#include <AT89X52.H>
#define uchar unsigned char
sbit check=P2^2;
sbit beep=P2^1;
uchar irdata[2],irtype,ircount;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
bit endflag;
void init()
{
irdata[0]=0;
irdata[1]=0;
irtype=0;
ircount=0;
endflag=0;
check=1;
P3=0xfe;
}
void delay_50ms(unsigned int t)
{
unsigned int j;
for(;t>0;t--)
for(j=6245;j>0;j--)
{;}
}
void tim0() interrupt 1 using 0
{
bit in=~check;
TH0=(65536-1688)/256;
TL0=(65536-1688)%256;
irdata[irtype]=irdata[irtype]|in;
ircount++;
if(ircount==3)
{
irtype=1;
}
else if(ircount==12)
{
irtype=2;
}
else if(irtype==2)
{
endflag=1;
ircount=0;
irtype=0;
TR0=0;
return;
}
else
{
irdata[irtype]=irdata[irtype]<<1;
}
}
void delay()
{
uchar a,b;
for(a=20;a!=0;a--)
for(b=248;b!=0;b--);
}
void display()
{
uchar i;
switch(irdata[1])
{
case 0x20:i=0;break;
case 0x10:i=1;break;
case 0x08:i=2;break;
case 0x04:i=3;break;
case 0x02:i=4;break;
case 0x01:i=5;break;
case 0xa0:i=6;break;
case 0x90:i=7;break;
case 0x88:i=8;break;
case 0x82:i=9;break;
}
P0=table[i];
delay();
}
void main()
{
TMOD=0x81;
IE=0x82;
P0=table[0];
check=1;
while(1)
{
init();
TH0=(65536-844)/256;
TL0=(65536-844)%256;
while(check);
TR0=1;
while(!endflag);
display();
beep=0;
delay_50ms(1);
beep=1;
}
}