#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
uint num=0,shu=432;
uchar bai,shi,ge;
sbit du=P2^6;
sbit we=P2^7;
void display();
uchar table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
void delayms(uchar x)
{
uchar i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar a,uchar b,uchar c,uchar bai,uchar shi,uchar ge)
{
du=0;
P0=table[a];
du=1;
du=0;
we=0;
P0=0xfe;
we=1;
we=0;
delayms(5);
du=1;
P0=table[b];
du=0;
we=1;
P0=0xfd;
delayms(5);
du=1;
P0=table[c];
du=0;
P0=0xff;
we=1;
P0=0xfb;
delayms(5);
du=1;
P0=table[bai];
du=0;
we=1;
P0=0xf7;
delayms(5);
du=1;
P0=table[shi];
du=0;
P0=0xff;
we=1;
P0=0xef;
delayms(5);
du=1;
P0=table[ge];
du=0;
P0=0xff;
we=1;
P0=0xdf;
delayms(10);
}
void timer()
{
TMOD=0x10;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
//TH0=(65536-50000)/256;
//TL0=(65536-50000)%256;
EA=1;
//ET0=1;
ET1=1;
//TR0=1;
TR1=1;
}
void main()
{
timer();
while(1)
{
if(num==20)
{
num=0;
shu--;
bai=shu/100;
shi=shu/10%10;
ge=shu%10;
if(shu==398)
{
TR1=0;
}
display(7,6,5,bai,shi,ge);
}
}
}
void timer1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num++;
}
|