//******************************************************************************* // // Simple program to decode commands of RC5 infrared remote controls // // // ATTENTION! All timer-values just fit, if the controller runs with 20 MHz!!! // When you use another frequency, the values have to be adapted! // //******************************************************************************* int1 get_RC5(void); typedef struct { int8 data[2]; int8 state; } rc5_struct; rc5_struct rc5; int1 get_RC5(void) { int16 tmp,t; int i; int1 inp; set_timer1(0); while(IR_STATUS==1); t=get_timer1(); if ((t<400) || (t>800)) return 0; // no RC5 code, abort decoding for (i=0;i<13;i++) { inp=IR_STATUS; set_timer1(0); while (IR_STATUS==inp) { t=get_timer1(); if (t>800) return 0; // no RC5 code, abort decoding } tmp<<=1; if (inp==0) tmp++; set_timer1(0); while (get_timer1()<776); // a simple delay would work here as well } tmp=tmp | 0x3000; tmp=tmp & 0x37ff; // cut off togglebit rc5.data[0]=tmp & 0xff; // device address tmp>>=8; rc5.data[1]=tmp & 0xff; // command code rc5.state = 1; disable_interrupts(INT_EXT); return 1; }