#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uint temp,bai,shi,ge,a,aa;
sbit wela=P2^7;
sbit dula=P2^6;
sbit key1=P3^4;
void init();
void delay(uint xm)
{
uint i,j;
for(i=xm;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar aa,uchar bb,uchar cc);
void main ()
{
init();
while(1)
{
if(key1==0)
{
delay(5);
if(key1==0)
TR0=0;//按键时关闭计时器1
}
while(!key1)
{
delay(5);
while(!key1)
TR0=1;
}
display(bai,shi,ge);
}
}
void timer_0() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
temp++;
if(temp==999)
temp=0;
bai=temp/100;
shi=temp%100/10;
ge=temp%10;
}
void init()
{
temp=0;
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
EA=1;
ET0=1;
TR0=1;
}
void display(uchar aa,uchar bb,uchar cc)
{
P0=0xff;
dula=1;
P0=table[aa];
dula=0;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[bb];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[cc];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);//如果延时100的话就正常显示,其他位会闪烁
}
|