Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of irda1 by
main.cpp
00001 #include "mbed.h" 00002 #include <Pulse1.h> 00003 int dec; 00004 PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo 00005 Serial pc(USBTX, USBRX); 00006 DigitalOut led(LED1); 00007 DigitalOut led2(LED2); 00008 DigitalOut led3(LED3); 00009 00010 int header =0; //tiempo de cabecera pulso abajo 00011 const int head_H = 8470*1.2;; //+20% medida con osciloscopio en microsegundos 00012 const int head_L =8470*0.8;//-20% medida con osciloscopio 00013 int i=0; 00014 const int T_alto=1530;//ponga su tiempo de la prueba 00015 const int T_bajo=500;//ponga su tiempo de la prueba 00016 const int num_bits = 33;//ponga su numero de bits 00017 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos 00018 int dat[num_bits]; 00019 int comp[num_bits]; 00020 int v[num_bits]; 00021 int r[num_bits]; 00022 int dato; // tiempo de cada dato que se lee 00023 int j,x,k; 00024 00025 int main(){ 00026 00027 led2=1; 00028 led=1; 00029 led3=1; 00030 while(1) 00031 { 00032 dat[0]=dat[2]=dat[3]=dat[5]=dat[7]=dat[9]=dat[12]=dat[14]=1,dat[16]=0,dat[17]=1,dat[19]=0,dat[26]=dat[28]=dat[29]=1,dat[30]=0,dat[31]=1; 00033 dat[1]=0,dat[4]=dat[6]=dat[8]=dat[10]=dat[11]=dat[13]=dat[15]=dat[18]=dat[20]=dat[21]=0,dat[22]=1,dat[23]=0,dat[24]=1,dat[25]=0,dat[27]=1; 00034 v[0]=1; 00035 v[1]=0; 00036 v[2]=1; 00037 v[3]=1; 00038 v[4]=0; 00039 v[5]=1; 00040 v[6]=0; 00041 v[7]=1; 00042 v[8]=0; 00043 v[9]=1; 00044 v[10]=0; 00045 v[11]=0; 00046 v[12]=1; 00047 v[13]=0; 00048 v[14]=1; 00049 v[15]=0; 00050 v[16]=1; 00051 v[17]=0; 00052 v[18]=0; 00053 v[19]=1; 00054 v[20]=1; 00055 v[ 21]=0; 00056 v[22]=0; 00057 v[23]=0; 00058 v[24]=0; 00059 v[25]=1; 00060 v[26]=1; 00061 v[27]=0; 00062 v[28]=0; 00063 v[29]=1; 00064 v[30]=1; 00065 v[31]=1; 00066 r[0]=1; 00067 r[1]=0; 00068 r[2]=1; 00069 r[3]=1; 00070 r[4]=0; 00071 r[5]=1; 00072 r[6]=0; 00073 r[7]=1; 00074 r[8]=0; 00075 r[9]=1; 00076 r[10]=0; 00077 r[11]=0; 00078 r[12]=1; 00079 r[13]=0; 00080 r[14]=1; 00081 r[15]=0; 00082 r[16]=1; 00083 r[17]=1; 00084 r[18]=0; 00085 r[19]=0; 00086 r[20]=0; 00087 r[21]=0; 00088 r[22]=1; 00089 r[23]=0; 00090 r[24]=0; 00091 r[25]=0; 00092 r[26]=1; 00093 r[27]=1; 00094 r[28]=1; 00095 r[29]=1; 00096 r[30]=0; 00097 r[31]=1; 00098 ini1: header=0; 00099 header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo 00100 if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20% 00101 else goto ini1; 00102 00103 seguir: 00104 //leo los datos de la trama y se meten a un arreglo 00105 wait_us(2100); 00106 //led2=0; 00107 for(i=0;i<(num_bits-1);++i) 00108 { // POR OSCILOSCOPIO se determina que llegan (num_bits),datos 00109 dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control 00110 num[i]=dato; 00111 wait_us(250); 00112 }// 00113 wait(0.5); //espero un poquito antes de leer todo el arreglo y ponerlo en pantalla 00114 pc.printf(",%d",header); 00115 for(i=0;i<(num_bits-1);++i) 00116 {// 00117 pc.printf(",%d",num[i]); 00118 }// 00119 wait(0.1); //espero e imprimo en binario 00120 pc.printf("\n\n"); 00121 for(i=0;i<(num_bits-1);++i) 00122 { // 00123 if(num[i] > ((T_alto+T_bajo)/2)) 00124 { 00125 pc.printf("1"); 00126 comp[i]=1; 00127 } 00128 else 00129 { 00130 pc.printf("0"); 00131 comp[i]=0; 00132 } 00133 if(comp[i]==dat[i]) 00134 { 00135 ++j; 00136 } 00137 if(j==32) led=!led; 00138 if(j!=32) led=1; 00139 00140 if (v[i]==comp[i]) 00141 { 00142 ++x; 00143 } 00144 if(x==32) led2=!led2; 00145 if(x!=32) led2=1; 00146 00147 if (r[i]==comp[i]) 00148 { 00149 ++k; 00150 } 00151 if(k==32) led3=!led3; 00152 if(k!=32) led3=1; 00153 00154 }// 00155 j=x=k=0; 00156 00157 00158 }////while 00159 }
Generated on Sun Jul 24 2022 06:41:08 by
1.7.2
