Si además quieres enviarnos un Artículo para el Blog y redes sociales, pulsa el siguiente botón:
Buenas jóvenes.
Tiempo hace que no paso por estos lares.
A ver, al grano, estoy intentando coger el código RC5 de infrarrojos con el siguiente programa:
/*-------------------------------------------------------------------*/
#define P1     	 13    //LED 1
#define P2     	 16    //LED 2
#define IR     	 17    //signal from IR receiver SFH506
#define halfbit 	889  //time [µs] of 1/2 bit
/*-------------------------------------------------------------------*/
void setup(void)
{
   pinMode(P1,OUTPUT);
   pinMode(P2,OUTPUT);
   pinMode(IR,INPUT);
   digitalWrite(P1,LOW); //LED1 off
   digitalWrite(P2,LOW); //LED2 off
}
/*-------------------------------------------------------------------*/
uint RC5_data()  //this subfunction waits for a RC5 signal and decodes it.
{
   uint D0,D1,i;
	D0 = 0;
	D1 = 65535;
   if (digitalRead(IR))               //skip if 0
   {
      while (digitalRead(IR));        //wait for "1 to 0" edge (falling edge)
      delayMicroseconds(halfbit/2);	//wait 444.5us
      for(i=0;i<13;i++)       		  //read the following 13 bits
      {
         D1=D1*2+(digitalRead(IR));   //and read data
			delayMicroseconds(halfbit);  //wait for a half bit-time
			D0=D0*2+(digitalRead(IR));   //and read inverted data
         delayMicroseconds(halfbit);  //wait for a half bit-time
      }
      if ((D0^D1)==65535)
      {
			return (D1 & 0x7FF);
		}
      else return (0);
   }
   else return (0);
}
/*-------------------------------------------------------------------*//
void loop(void)
{
	int datos;
	while(1)
	{
      datos = 0;
      datos = RC5_data();                    //read RC5 
      if (datos==1)
      {
			digitalWrite(P1,HIGH); //if "1" is pressed switch on LED1
			delay(2000);
		}
      if (datos==2)
      {
			digitalWrite(P2,HIGH); //if "2" is pressed switch on LED2
			delay(2000);
		}
         digitalWrite(P1,LOW);
         digitalWrite(P2,LOW);
	}
}
PROBLEMA: no consigo ver si lo hace bien. He probado con un LCD 2x16 y cogia valores muy cercanos pero en ninguno de los casos conseguia coger bien el código. Pero el LCD creo que ha pasado a mejor vida y a falta de un monitor de USB, me las veo mal para verlo.
He pensado en mirarlo por el ICD2 pero implica tocar todo el código y pasarlo a CCS para verlo.
¿Alguna alma candida que lo mire a ver si me he pasado algo?
Es lo que me estaba temiendo, que no contase bien los microsegundos.
D1: 57464 D0: 06023 D1^D0:63487
D1: 57464 D0: 06023 D1^D0:63487
D1: 58488 D0: 07047 D1^D0:65535
D1: 58488 D0: 07047 D1^D0:65535
D1: 57464 D0: 06023 D1^D0:63487
D1: 57464 D0: 06023 D1^D0:63487
D1: 58488 D0: 07047 D1^D0:65535
D1: 58424 D0: 07047 D1^D0:65471
D1: 57464 D0: 06023 D1^D0:63487
D1: 57464 D0: 06023 D1^D0:63487
D1: 58488 D0: 07047 D1^D0:65535
D1: 58488 D0: 07047 D1^D0:65535
D1: 57464 D0: 06023 D1^D0:63487
D1: 57464 D0: 06023 D1^D0:63487
D1: 58424 D0: 07047 D1^D0:65471
D1: 58488 D0: 07047 D1^D0:65535 
El caso es que aproximo el código pero no lo consigo. Dime por donde tienes la libreria a ver si esta noche cojo ya el código RC5 que me hace falta para el concurso.
Gracias
PD: Acabo de pasar a 9.05 y la comunicacion CDC se ha ido al traste.
Acabo de incorporar un temporizador (T1CON = 0xB0) de 889'1us:
/*-------------------------------------------------------------------*/
void RC5_delay_us()
{
	TMR1H = 0xFA;
	TMR1L = 0XCA;
	PIR1bits.TMR1IF=0;
	T1CONbits.TMR1ON=1;
	while(!(PIR1bits.TMR1IF));
	PIR1bits.TMR1IF=0;
	T1CONbits.TMR1ON=0;
}
/*-------------------------------------------------------------------*/
Problema: ahora leo el CDC asi -->
D1: 5746406023D1: 6143908191D1: 574640602363487D1: 614390819161440D1: 584880704765535D1: 614390819161440D1


