#define IR_Signal P3_2
unsigned char cmd=0,val=0;
void delay() //delay of 1.664msec //delay of 1.658msec
{
TMOD=1;
TL0=0x02;
TH0=0xFA;
TR0=1;
while(TF0 == 0);
TR0=0;
TF0=0;
}
void delay3() //delay of 2.75 bits = 2.75*1.664msec = 4.57 ms
{
TMOD=1;
TL0=0x86;
TH0=0xEF;
TR0=1;
while(TF0 == 0);
TR0=0;
TF0=0;
}
void InitTimer0(void) //Init Timer 0 for 5 ms multiplexing
{
EA=0;
TMOD = 0x01;
TH0 = 0xEE;
TL0 = 0x00;
TR0 = 1;
ET0 = 1;
EA = 1; //Enable Global interrupt
}
/*===================================*/
int main()
{
InitTimer0();
while(1)
{
if(IR_signal == 0) // IR signal received on micro-controller pin, collect remaining 11 bits in interval of 1.664 ms
{
delay3(); //wait for 2.75 bits = 4.57 ms
cmd=0;
val=0;
for(i=0; i<12; i++) //collect 11 bits and segregate last 6 command bits
{
val=(val<<1) | input;
delay();
}
cmd = val & 0x3F; //command received from Remote control
}
}
return 0;
}
void timer_0ISR () interrupt 1
{
Multiplexing_Logic(); //activating 1 column at a time and sending data to shift registor
}