#include<reg51.h>
void interruptdelay(void);
void middelay(unsigned int); //arbitrary delay
void delwaste(unsigned int); //delay to skip the reading of code upto command
#define y P1 //to display number in the command code of rc5 protocol leds are connected
sbit mybit=P3^3; //tsop1738 signal connected at P3^3(interrupt pin)
void timer0(void) interrupt 2 //isr routine for external hardware interrupt
{
interruptdelay();
}
void main()
{
unsigned char z=0;
P3=0XFF; //make as input
P1=0X00; //make as output
IE=0X84; //low level triggered
TMOD=0X01; //timer 0 in mode 1
}
void interruptdelay(void)
{
unsigned int z;
delwaste(16); //13.824ms skip
while(z!=6) //here in rc5 protocl the command length is of 6 bits
{
if(mybit==0)
y=y<<1;
else
y|=0X01;
delwaste(2);
z+=1;
}
P1=y; //display final value in command code
middelay(100); //keep the display for a little long time
}
void delwaste(unsigned int e) //for e=1 creates delay of 860microsec=1.728ms/2 i.e(half of a bit)
{
for(;e>0;e--)
{
TH0=0XFC;
TL0=0XE4;
TR0=1;
if(TF0!=1);
TR0=0;
TF0=0;
}
}
void middelay(unsigned int g) //arbitrary delay
{
unsigned int h;
for(;g>0;g--)
{
for(h=0;h<10000;h++);
}
}