#include<reg52.h>
#define uchar unsigned char
#define Imax 14000
#define Imin 800
uchar x;
uchar y;
uchar z;
uchar ir
time;
uchar flag;
uchar i;
uchar n;
uchar numbit;
uchar irreceok;
uchar ircode[4];
uchar temp;
uchar irprosok;
uchar k;
uchar w;
uchar display[8];
uchar code dulasmg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code welasmg[]={0x08,0x18,0x28,0x38,0x48,0x58,0x68,0x78};
void delay(z){
for(x=z;x>0;x--)
for(y=110 ;y>0;y--); }
sbit dula=P2^6;
sbit wela=P2^7;
uchar irdata[33];
void t0_init(){
ET0=1;
EA=1;
TMOD=0x02;
TH0=0x00;
TL0=0x00;
TR0=1;}
void ex_init(){
EX0=1;
EA=1;
IT0=1;}
void time0() interrupt 1{
irtime++;
}
void ex() interrupt 0{
if(flag){
TR0=0;
if(irtime>51)
{
numbit=0;
}
irdata[numbit]=irtime;
irtime=0;
numbit++;
if(numbit==33)
{numbit=0;
irreceok=1;}
}
else {
flag=1;
irtime=0;
}
}
void irpros(){
k=1;
for(n=0;n<4;n++){
for(i=0;i<8;i++)
{ temp=temp>>1;
if(irdata[k]>6)
{temp=temp|0x80;}
k++;
}
ircode[n]=temp;
}
irprosok=1;
}
void irwork(){
display[0]=ircode[0]/16;
display[1]=ircode[0]%16;
display[2]=ircode[1]/16;
display[3]=ircode[1]%16;
display[4]=ircode[2]/16;
display[5]=ircode[2]%16;
display[6]=ircode[3]/16;
display[7]=ircode[3]%16;
}
void disp(){
for(w=0;w<8;w++){
P0=dulasmg[display[w]];
dula=1;
dula=0;
P0=welasmg[w];
wela=1;
wela=0;
delay(100);
}
}
void main(void){
ex_init();
t0_init();
while(1){
if(irreceok)
{
irpros();
irreceok=0;
if(irprosok)
{irwork();
irprosok=0;
disp();
}
}
}
}
一周热门 更多>