#include<reg51.h>
void interruptdelay(void); //function for interrupt
void delwaste(unsigned int); //it's to receive the bit from the protocol sent by your remote
void DELAY(void); //for 13.392ms delay to skip the reading of code upto command
#define y P2 //to display number in the command code of rc5 protocol
sbit first=P0^0;
sbit sec=P0^1;
sbit third=P0^2;
sbit mybit=P3^3; //tsoy738 signal connected at P3^3(interrupt pin)
void timer0(void) interrupt 2 //isr routine for external hardware interrupt
{
interruptdelay();
}
void main()
{
P3=0XFF; //make as input
P1=0X00; //make as output
P0=0X00; //motors connected
P2=0X00;
while(1)
{
IE=0X84; //low level triggered
TMOD=0X01; //timer 0 in mode 1
}
}
void interruptdelay(void)
{
unsigned int z=0,y=0,t=0;
DELAY(); //13.392ms skip
while(z<6) //here in rc5 protocol the command length is of 6 bits
{
if(mybit==0)
{
y=y<<1;
y|=0X01;
}
else
{
y=y<<1;
}
delwaste(1); //1.728ms delay
z+=1;
}
P1=y; //display the command code "i.e 6bits size"
}
void delwaste(unsigned int e) //for e=1 creates delay of 1.728msec
{
for(;e>0;e--)
{
TH0=0XF9;
TL0=0XD4;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
return;
}
void DELAY(void) //13.392ms
{
TH0=0XCE;
TL0=0X4C;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
return;
}