#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={0x3f, 0x06, 0x5b, 0x4f,
0x66, 0x6d, 0x7d, 0x07,
0x7f, 0x6f, 0x77, 0x7c,
0x39, 0x5e, 0x79, 0x71};
uchar num1,num2,shi,ge;
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display1(uchar m)
{
wela=1;
P0=0xfe;
wela=0;
dula=1;
P0=table[m];
dula=0;
delayms(5);
}
void display(uchar shi,uchar ge)
{
wela=1;
P0=0xfd;
wela=0;
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
delayms(5);
wela=1;
P0=0xfe;
wela=0;
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
delayms(5);
}
void main()
{
uchar temp, key;
TMOD=0x01;
EA=1;
ET0=1;
TH0=(65536-9174)/256;
TL0=(65536-9174)%256;
while(1)
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delayms(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delayms(10);
temp=P3;
switch(temp)
{
case 0xee: key=1;
break;
case 0xde: key=2;
break;
case 0xbe: key=3;
break;
case 0x7e: key=4;
break;
}
while(temp!=0xfe)
{
delayms(5);
TR0=1;
}
while(num1<1000&&TR0==1)
{
display1(key);
delayms(10);
display1(0);
display(shi,ge);
}
if(num1==1000)
{
num1=0;
TR0=0;
display1(0);
}
}
}
}
}
void T0_time() interrupt 1
{
uchar num1, num2;
TH0=(65536-9174)/256;
TL0=(65536-9174)%256;
num1++;
ge=num2%10;
shi=num2/10;
if(num1==100)
{
num1=0;
num2++;
if(num2==10)
{
num2=0;
num1=0;
}
}
}
|