Tarea 2-Procesadores 2016-2. Aldair Navarro
Dependencies: Pulse1 TextLCD mbed
Fork of irda_Sony by
main.cpp@2:6a15ab0305c8, 2013-11-08 (annotated)
- Committer:
- tony63
- Date:
- Fri Nov 08 07:40:04 2013 +0000
- Revision:
- 2:6a15ab0305c8
- Parent:
- 0:74d57f8ae247
- Child:
- 3:82bebaf2a06a
version corregida y lee tiempos de todos los bits ademas muestra codigo de trama en binario y cabecera
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:74d57f8ae247 | 1 | #include "mbed.h" |
tony63 | 0:74d57f8ae247 | 2 | #include <Pulse1.h> |
tony63 | 0:74d57f8ae247 | 3 | |
tony63 | 2:6a15ab0305c8 | 4 | PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo |
tony63 | 0:74d57f8ae247 | 5 | Serial pc(USBTX, USBRX); |
tony63 | 0:74d57f8ae247 | 6 | DigitalOut led(LED1); |
tony63 | 2:6a15ab0305c8 | 7 | DigitalOut led2(LED2); |
tony63 | 2:6a15ab0305c8 | 8 | int header =0; //tiempo de cabecera pulso abajo |
tony63 | 2:6a15ab0305c8 | 9 | const int head_H = 9100; //+20% medida con osciloscopio en microsegundos |
tony63 | 2:6a15ab0305c8 | 10 | const int head_L = 8500;//-20% medida con osciloscopio |
tony63 | 2:6a15ab0305c8 | 11 | int i=0; |
tony63 | 2:6a15ab0305c8 | 12 | const int T_alto=1680;//ponga su tiempo de la prueba |
tony63 | 2:6a15ab0305c8 | 13 | const int T_bajo=526;//ponga su tiempo de la prueba |
tony63 | 2:6a15ab0305c8 | 14 | const int num_bits = 32;//ponga su numero de bits |
tony63 | 2:6a15ab0305c8 | 15 | int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos |
tony63 | 2:6a15ab0305c8 | 16 | int dato; // tiempo de cada dato que se lee |
tony63 | 0:74d57f8ae247 | 17 | |
tony63 | 0:74d57f8ae247 | 18 | int main(){ |
tony63 | 0:74d57f8ae247 | 19 | while(1){ |
tony63 | 2:6a15ab0305c8 | 20 | ini1: header=0; |
tony63 | 2:6a15ab0305c8 | 21 | led2=1; |
tony63 | 0:74d57f8ae247 | 22 | led=1; |
tony63 | 2:6a15ab0305c8 | 23 | header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo |
tony63 | 2:6a15ab0305c8 | 24 | if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20% |
tony63 | 2:6a15ab0305c8 | 25 | else goto ini1; |
tony63 | 0:74d57f8ae247 | 26 | |
tony63 | 2:6a15ab0305c8 | 27 | seguir: |
tony63 | 2:6a15ab0305c8 | 28 | //leo los datos de la trama y se meten a un arreglo |
tony63 | 2:6a15ab0305c8 | 29 | wait_us(5000); |
tony63 | 2:6a15ab0305c8 | 30 | led2=0; |
tony63 | 2:6a15ab0305c8 | 31 | for(i=0;i<(num_bits-1);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos |
tony63 | 2:6a15ab0305c8 | 32 | dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control |
tony63 | 2:6a15ab0305c8 | 33 | num[i]=dato; |
tony63 | 2:6a15ab0305c8 | 34 | wait_us(300); |
tony63 | 2:6a15ab0305c8 | 35 | } |
tony63 | 2:6a15ab0305c8 | 36 | wait(0.5); //espero un poquito antes de leer todo el arreglo y ponerlo en pantalla |
tony63 | 2:6a15ab0305c8 | 37 | pc.printf(",%d",header); |
tony63 | 2:6a15ab0305c8 | 38 | for(i=0;i<(num_bits-1);++i){ |
tony63 | 2:6a15ab0305c8 | 39 | pc.printf(",%d",num[i]); |
tony63 | 2:6a15ab0305c8 | 40 | } |
tony63 | 2:6a15ab0305c8 | 41 | wait(0.1); //espero e imprimo en binario |
tony63 | 2:6a15ab0305c8 | 42 | pc.printf("\n\n"); |
tony63 | 2:6a15ab0305c8 | 43 | for(i=0;i<(num_bits-1);++i){ |
tony63 | 2:6a15ab0305c8 | 44 | if(num[i] > ((T_alto+T_bajo)/2)) pc.printf("1"); |
tony63 | 2:6a15ab0305c8 | 45 | else pc.printf("0"); |
tony63 | 2:6a15ab0305c8 | 46 | } |
tony63 | 2:6a15ab0305c8 | 47 | } |
tony63 | 2:6a15ab0305c8 | 48 | } |