Tarea Procesadores IRDA
Dependencies: Pulse1 TextLCD mbed
main.cpp
- Committer:
- Equipo3JohnAndresx2
- Date:
- 2015-05-01
- Revision:
- 0:31b68270edc9
File content as of revision 0:31b68270edc9:
// Equipo #3 Tarea Procesadores IRDA UnalMed #include "mbed.h" #include <Pulse1.h> #include "TextLCD.h" //control remoto videobeam aula PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo Serial pc(USBTX, USBRX); TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 DigitalOut led2(LED1); DigitalOut led(LED2); // variables int headerL =0; //tiempo de cabecera pulso abajo int headerH =0; const int head_H = 3817; //+10% medida con osciloscopio en microsegundos const int head_L = 3123;//-10% medida con osciloscopio int i=0; const int T_alto=1730;//ponga su tiempo de la prueba const int T_bajo=467;//ponga su tiempo de la prueba const int num_bits = 48;//ponga su numero de bits int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos int dato; // tiempo de cada dato que se lee int bin[num_bits]; int p; int tuno; // Tiempo de uno int a1; // Acumulacion de unos para el promedio int C1=0x0F; int C4=0x0C; // quito cursor bajo int main(){ lcd.cls(); lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD while(1){ ini1: fflush( stdin ); headerL=0; headerH=0; led2=1; led=0; headerL = irda.read_low_us(); //funcion para leer un pulso de caida o bajo en header pc.printf("Header bajo dura %d us\n", headerL); lcd.cls(); lcd.locate(0,0); lcd.printf("HeaderLow=%d us", headerL); wait(0.1); headerH= irda.read_high_us(); pc.printf("Header alto dura %d us\n", headerH); lcd.locate(0,1); lcd.printf("HeaderHigh=%d us", headerH); wait(0.3); led=1; if (headerL > head_L && headerL < head_H) goto seguir;//verificar que este en la tolerancia +-1,8% else goto ini1; seguir: //leo los datos de la trama y se meten a un arreglo ///wait_us(4470);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO lcd.writeCommand(C4);//escribimos un comando segun el manual del modulo LCD para quitar cursor bajo wait_us(400); led2=0; for(i=0;i<(num_bits);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control num[i]=dato; } wait(0.5);//espero un poquito luego de leer todo el arreglo y ponerlo en pantalla for(i=0;i<(num_bits);++i){ pc.printf(",%d",num[i]); } wait(0.1); //espero e imprimo en binario pc.printf("\n\n"); tuno=0; a1=0; int tcero=0; // Tiempo de ceros int a0=0; // Acumulacion de ceros para el promedio for(i=0;i<(num_bits);++i){ if(num[i] > ((T_alto+T_bajo)/2)) { tuno = num[i]+tuno; bin[i]=1; pc.printf("%d",bin[i]); a1 = a1+1; } if(num[i] < ((T_alto+T_bajo)/2)) { tcero = num[i]+tcero; bin[i]=0; pc.printf("%d",bin[i]); a0 = a0+1; } } pc.printf("\n\n"); int TONE = tuno/a1; int TZERO = tcero/a0; pc.printf(" tide unos1 =%d",tuno); pc.printf(", can1 =%d",a1); pc.printf(" tide unoso =%d",tcero); pc.printf(", can0 =%d",a0); pc.printf("\n\n"); wait (0.3); pc.printf("TONE =%d",TONE); pc.printf("TZERO =%d",TZERO); lcd.locate(0,0); lcd.printf("N_bits = %d",i); wait(1); lcd.locate(0,0); lcd.printf("TONE =%d",TONE); lcd.locate(0,1); lcd.printf("TZERO =%d",TZERO); wait(1); pc.printf("\n\n"); lcd.cls(); lcd.printf("Hex="); for (i=0;i< num_bits;i =i+4){ long int x = bin[i]*8+bin[i+1]*4+bin[i+2]*2+bin[i+3]; pc.printf("%x",x); lcd.printf("%x",x); } } }