#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar irtime;
sbit beep=P3^6;
sbit ir_pin=P3^2;
uchar irreciveok;
uchar irdata[33];
uchar bitnum;
uchar ircode[4];
uchar irprook;
uchar dis[8];
uint a[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
uint b[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
uchar startflag;
void delay_50(uint t)
{uchar j;
for(;t>0;t--)
for(j=19;j>0;j--);
}
void timers(void)
{TMOD=0X02;
TH0=0X00;
TL0=0X00;
ET0=1;
EA=1;
TR0=1;
}
void intin(void)
{IT0=1;
EX0=1;
EA=1;
}
void timers0() interrupt 1
{
irtime++;//255
}
void int0() interrupt 0
{
if(startflag)
{
if(irtime>35) //
{ bitnum=0;
irreciveok=1;
}
irdata[bitnum]=irtime;
bitnum++;
if(bitnum==33)
{ bitnum=0;
}
}
else
{startflag=1;
irtime=0;
}
}
void irport(void)
{
uchar k,value,i,j;
k=1;
for(j=0;j<4;j++)
{
for(i=0;i<8;j++)
{
value=value>>1;
if((irdata[k]>6)&&ir_pin==1)
{ value=value|0x80;
}
k++;
}
ircode[j]=value;
}
irprook=1;
}
void irwork(void)
{
dis[0]=ircode[0]/16;
dis[1]=ircode[0]%16;
dis[2]=ircode[1]/16;
dis[3]=ircode[1]%16;
dis[4]=ircode[2]/16;
dis[5]=ircode[2]%16;
dis[6]=ircode[3]/16;
dis[7]=ircode[3]%16;
}
void display(void)
{ uchar i;
for(i=0;i<8;i++)
{P0=a[dis];
P2=b;
delay_50(20);
}
}
void main()
{timers();
intin();
while(1)
{
if(irreciveok)
{ irport();
irreciveok=0;
beep=0;
}
if(irprook)
{irwork();
beep=0;
irprook=0;
}
else
{
beep=1;
}
display();
}
}