Tarea con el módulo IRDA, que muestra el código hexadecimal de la tecla pulsada en un control remoto panasonic, también sus tiempos de modulación.

Dependencies:   DebouncedIn Pulse1 TextLCD mbed

Fork of irda_V_aula by Gustavo Ramirez

Files at this revision

API Documentation at this revision

Comitter:
Equipo2_2015_1
Date:
Wed Apr 29 14:47:03 2015 +0000
Parent:
3:82bebaf2a06a
Commit message:
Tarea_IRDA_Hexadecimal_Tiempos

Changed in this revision

DebouncedIn.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebouncedIn.lib	Wed Apr 29 14:47:03 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/cmorab/code/DebouncedIn/#dc1131de43e8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Apr 29 14:47:03 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
--- a/main.cpp	Thu May 08 00:38:39 2014 +0000
+++ b/main.cpp	Wed Apr 29 14:47:03 2015 +0000
@@ -1,49 +1,586 @@
+// Juan Esteban Botero Holguin
+// Juan Felipe Vanegas Vargas
+//Daniel Barrios
+
 #include "mbed.h"
 #include <Pulse1.h>
-//control remoto videobeam aula
-PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
-Serial pc(USBTX, USBRX);
+#include "TextLCD.h"
+#include "DebouncedIn.h"
+
+
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
+PulseInOut irda(PTD5);//sensor infrarrojo
+DebouncedIn button1(PTC12);  
 DigitalOut led(LED1);
 DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+
 int header =0; //tiempo de cabecera pulso abajo
-const int head_H = 9120; //+10% medida con osciloscopio en microsegundos
-const int head_L = 8939;//-10%  medida con osciloscopio
+const int head_H = 3530*1.2; //+20% medida con osciloscopio en microsegundos
+const int head_L = 3530*0.8;//-20%  medida con osciloscopio en microsegundos
+const int Tp=417;  //tiempo entre bits en microsegundos
 int i=0;
-const int T_alto=1630;//ponga su tiempo de la prueba
-const int T_bajo=533;//ponga su tiempo de la prueba
-const int num_bits = 64;//ponga su numero de bits
+const int T_alto=1330;//lo que dura un uno lógico en microsegudnos
+const int T_bajo=450;//lo que dura un cero lógico en microsegundos
+const int num_bits = 48;//numero de bits
 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
+
+int Tecla=0;
+const int power=499;//datos del control tecla power
+const int mute=359;//datos del control tecla mute
+const int ch1=361;//datos del control tecla aumentar canal
+const int ch0=427;//datos del control tecla disminuir canal
+const int vol1=209;//datos del control tecla aumentar volumen
+const int video=269;//datos del control tecla video
+const int N1=199;//datos del control tecla 1
+const int N2=265;//datos del control tecla 2
+const int N3=275;//datos del control tecla 3
+const int N4=341;//datos del control tecla 4
+const int N5=277;//datos del control tecla 5
+const int N6=343;//datos del control tecla 6
+const int N7=353;//datos del control tecla 7
+const int N8=419;//datos del control tecla 8
+const int N9=271;//datos del control tecla 9
+const int N0=337;//datos del control tecla 0
+const int rtune=503;//datos del control tecla rtune
+const int recall=421;//datos del control tecla recall
+
 int dato; // tiempo de cada dato que se lee
   
-int main(){
-while(1){
+int main()
+{
+      
+      led=1;  //leds apagados
+      led2=1;
+      led3=1;       
+while(1)
+    {
+        
+      
+       
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("PRESIONE BOTON");
+          
 ini1: fflush( stdin );
       header=0;
-      led2=1;
-      led=1;
       header = irda.read_low_us();    //funcion para leer un pulso de caida o bajo en header
       if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20%
       else goto ini1;
       
 seguir:
        //leo los datos de la trama y se meten a un arreglo
-      wait_us(4500);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO 
-      led2=0;
-      for(i=0;i<(num_bits-1);++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_us(300);   
+      wait_us(1700/2);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO 
+      //led2=0;
+      lcd.cls();
+      Tecla=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_us(Tp/2);   
+      }
+      wait(0.3); //espero un poco luego de leer todo el arreglo y ponerlo en pantalla 
+ 
+      for(i=0;i<(num_bits);++i)
+      {  
+        
+        if(num[i] > ((T_alto+T_bajo)/2))
+            {
+                    Tecla=Tecla+ (2^(i));  //creo el código de la tecla pulsada en forma decimal
+            }
+          
       }
-      wait(0.5); //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla 
-      pc.printf(",%d",header);
-      for(i=0;i<(num_bits-1);++i){  
-      pc.printf(",%d",num[i]);
+      
+      //IMPRIMO LOS PARÁMETROS DE CADA TECLA QUE SE PUEDE SELECCIONAR
+      
+            if(Tecla==power)
+      {
+            led3=1;
+            led2=1;
+            led=!led;
+            lcd.cls();
+            lcd.printf("TECLA POWER");
+            lcd.locate(0,1);
+            lcd.printf("HEX=1F3");
+             lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1331");
+            lcd.locate(0,1);
+            lcd.printf("HL:1716");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);    
+            //led3=1;  
+      }  
+      
+            if(Tecla==mute)
+      {
+            led3=1;
+            led2=1;
+            led=!led;
+            lcd.cls();
+            lcd.printf("TECLA MUTE");
+            lcd.locate(0,1);
+            lcd.printf("HEX=167");
+            lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1337");
+            lcd.locate(0,1);
+            lcd.printf("HL:1713");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);    
+            //led3=1;  
+      }  
+      
+            if(Tecla==ch1)
+      {
+            led3=1;
+            led2=1;
+            led=!led;
+            lcd.cls();
+            lcd.printf("TECLA CH+");
+            lcd.locate(0,1);
+            lcd.printf("HEX=169");
+             lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1333");
+            lcd.locate(0,1);
+            lcd.printf("HL:1714");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);    
+            //led3=1;  
+      }  
+      
+             if(Tecla==ch0)
+      {
+            led3=1;
+            led2=1;
+            led=!led;
+            lcd.cls();
+            lcd.printf("TECLA CH-");
+            lcd.locate(0,1);
+            lcd.printf("HEX=1AB");
+            lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1325");
+            lcd.locate(0,1);
+            lcd.printf("HL:1716");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);    
+            //led3=1;  
+      }  
+      
+      
+      
+                if(Tecla==vol1)
+      {
+            led3=1;
+            led2=1;
+            led=!led;
+            lcd.cls();
+            lcd.printf("TECLA VOL+");
+            lcd.locate(0,1);
+            lcd.printf("HEX=D1");
+             lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1338");
+            lcd.locate(0,1);
+            lcd.printf("HL:1701");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);    
+            //led3=1;  
+      }    
+      
+      
+      
+                 if(Tecla==video)
+      {
+            led3=1;
+            led2=1;
+            led=!led;
+            lcd.cls();
+            lcd.printf("TECLA VIDEO");
+            lcd.locate(0,1);
+            lcd.printf("HEX=10D");
+            lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1336");
+            lcd.locate(0,1);
+            lcd.printf("HL:1705");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);    
+            //led3=1;  
+      }    
+      
+              if(Tecla==N1)
+      {
+            led3=1;
+            led2=1;
+            led=!led;
+            lcd.cls();
+            lcd.printf("PRESIONO 1");
+            lcd.locate(0,1);
+            lcd.printf("HEX=C7");
+            lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1328");
+            lcd.locate(0,1);
+            lcd.printf("HL:1698");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);    
+            //led3=1;  
+      }        
+      
+      if(Tecla==N2)
+      {
+            led=1;
+            led3=1;
+            led2=!led2;
+            lcd.cls();
+          lcd.printf("PRESIONO 2");
+            lcd.locate(0,1);
+            lcd.printf("HEX=109");
+            lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1331");
+            lcd.locate(0,1);
+            lcd.printf("HL:1696");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);    
+            //led3=1;  
+      }      
+      
+      
+      if(Tecla==N3)
+      {
+            led=1;
+            led2=1;
+            led3=!led3;
+            lcd.cls();
+          lcd.printf("PRESIONO 3");
+            lcd.locate(0,1);
+            lcd.printf("HEX=113");
+            lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1325");
+            lcd.locate(0,1);
+            lcd.printf("HL:1713");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);   
+            //led3=1;  
       }
-      wait(0.1);  //espero e imprimo en binario 
-      pc.printf("\n\n");
-      for(i=0;i<(num_bits-1);++i){  
-      if(num[i] > ((T_alto+T_bajo)/2)) pc.printf("1");
-      else pc.printf("0");
+      if(Tecla==N4)
+      {
+            led=0;
+            led2=0;
+            led3=1;
+            lcd.cls();
+          lcd.printf("PRESIONO 4");
+            lcd.locate(0,1);
+            lcd.printf("HEX=155");
+            lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1338");
+            lcd.locate(0,1);
+            lcd.printf("HL:1704");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);   
+             led=1;  
+            led2=1;
+
+      }
+      
+            if(Tecla==N5)
+      {
+            led=1;
+            led2=0;
+            led3=0;
+            lcd.cls();
+          lcd.printf("PRESIONO 5");
+            lcd.locate(0,1);
+            lcd.printf("HEX=115");
+            lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1338");
+            lcd.locate(0,1);
+            lcd.printf("HL:1694");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);   
+            led2=1;    
+            led3=1;  
+      }
+      if(Tecla==N6)
+      {     led=0;
+            led2=1;
+            led3=0;
+            lcd.cls();
+           lcd.printf("PRESIONO 6");
+            lcd.locate(0,1);
+            lcd.printf("HEX=157");
+             lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1324");
+            lcd.locate(0,1);
+            lcd.printf("HL:1692");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);   
+           led=1;
+            led3=1;
+      }
+      if(Tecla==N7)
+      {     led=0;
+            led2=0;
+            led3=0;
+            lcd.cls();
+          lcd.printf("PRESIONO 7");
+            lcd.locate(0,1);
+            lcd.printf("HEX=161");
+            lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1336");
+            lcd.locate(0,1);
+            lcd.printf("HL:1701");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);   
+            led=1;
+            led2=1;
+            led3=1;
       }
+       
+             if(Tecla==N8)
+      {     led=0;
+            led2=0;
+            led3=0;
+            lcd.cls();
+          lcd.printf("PRESIONO 8");
+            lcd.locate(0,1);
+            lcd.printf("HEX=1A3");
+             lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1324");
+            lcd.locate(0,1);
+            lcd.printf("HL:1710");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);   
+            led=1;
+            led2=1;
+            led3=1;
       }
-      }
\ No newline at end of file
+      
+      
+      
+            if(Tecla==N9)
+      {     led=0;
+            led2=0;
+            led3=0;
+            lcd.cls();
+          lcd.printf("PRESIONO 9");
+            lcd.locate(0,1);
+            lcd.printf("HEX=10F");
+             lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1328");
+            lcd.locate(0,1);
+            lcd.printf("HL:1702");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);   
+            led=1;
+            led2=1;
+            led3=1;
+      }
+      
+      
+      
+            if(Tecla==N0)
+      {     led=0;
+            led2=0;
+            led3=0;
+            lcd.cls();
+          lcd.printf("PRESIONO 0");
+            lcd.locate(0,1);
+            lcd.printf("HEX=151");
+            lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1324");
+            lcd.locate(0,1);
+            lcd.printf("HL:1695");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);   
+            led=1;
+            led2=1;
+            led3=1;
+      }
+      
+      
+      
+            if(Tecla==rtune)
+      {     led=0;
+            led2=0;
+            led3=0;
+            lcd.cls();
+          lcd.printf("TECLA RTUNE");
+            lcd.locate(0,1);
+            lcd.printf("HEX=1F7");
+             lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1336");
+            lcd.locate(0,1);
+            lcd.printf("HL:1712");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);   
+            led=1;
+            led2=1;
+            led3=1;
+      }
+      
+      
+      
+            if(Tecla==recall)
+      {     led=0;
+            led2=0;
+            led3=0;
+            lcd.cls();
+          lcd.printf("TECLA RECALL");
+            lcd.locate(0,1);
+            lcd.printf("HEX=1A5");
+            lcd.locate(8,1);
+            lcd.printf("Nb:48");
+            wait(4);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",header);
+            lcd.locate(8,0);
+            lcd.printf("1L:1332");
+            lcd.locate(0,1);
+            lcd.printf("HL:1683");
+            lcd.locate(8,1);
+            lcd.printf("0L:%d",num[5]);
+            Tecla=0; 
+            wait(4);   
+            led=1;
+            led2=1;
+            led3=1;
+      }
+       
+       
+    }
+}
\ No newline at end of file