#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f,0x77,0x7c};
void display(uchar shi,uchar ge);
void delayms(uint xms);
uchar shi,ge,num,aa;
void main()
{
aa=0;
TMOD=0X01;
TH0=(65535-45872)/256;// 1001100 76
TL0=(65535-45872)%256; //208
EA=1;
ET0=1;
TR0=1;
while(1)
{
display(shi,ge);
}
}
void display(uchar shi,uchar ge)
{
dula=1;
P0=tab[shi];
dula=0;
P0=0xff;//255
wela=1;
P0=0xfe;
wela=0;
delayms(5);
dula=1;
P0=tab[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;//253
wela=0;
delayms(5);
}
void T() interrupt 1
{
TH0=(65535-45872)/256;
TL0=(65535-45872)%256;
num++;
if(num==20)
{
num=0;
aa++;
if(aa==60)
aa=0;
shi=aa/10;
ge=aa%10;
}
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
|