#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit IR=P3^2;
uchar disp[4];
void chushi();
void display();
void extr0();
bit right();
void main()
{uint n;
chushi();
P1=0xff;
while(1)
{display();
}
}
void chushi()
{TMOD=0X01;
IE=0X81;
IT0=1;
}
void display()
{uchar code shuma[17]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
uchar code *sm=shuma;
uchar i,n;
P2=0x03;
for(i=0;i<4;i++)
{P0=*(sm+disp[i]);
P2=(++P2)&0x03;
n=200;
while(--n);
}
}
void extr0() interrupt 0 using 1
{uint n;
uint lowt,higt;
EA=0;
TH0=0;
TL0=0;
TR0=1;
while(IR==0);
TR0=0;
lowt=TH0*256+TL0;
TH0=0;
TL0=0;
TR0=1;
while(IR==1);
TR0=0;
higt=TH0*256+TL0;
if((lowt<8800)&&(lowt>7800)&&(higt<4700)&&(higt>3600))
if(right())
{ P1=0x00;
n=20000;
while(--n);
}
EA=1;
}
bit right()
{uchar i,j;
uchar tem[4];
uint lowt,higt;
for(i=0;i<4;i++)
{for(j=0;j<8;j++)
{tem[i]>>=1;
TH0=0;
TL0=0;
TR0=1;
while(IR==0);
TR0=0;
lowt=TH0*256+TL0;
TH0=0;
TL0=0;
TR0=1;
while(IR==1);
TR0=0;
higt=TH0*256+TL0;
if((lowt>370)&&(lowt<640))
{if((higt<620)&&(higt>420))
tem[i]=tem[i]&0x7f;
else
if((higt>1300)&&(higt<1800))
tem[i]|=0x80;
else return (0);
}
else return (0);
}
}
disp[0]=tem[2]/100; //数码管显示数据的百位 十位 和个位
disp[1]=(tem[2]%100)/10;
disp[2]=tem[2]%10;
return (1);
} |