源程序:#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar Countor;
uint temp,fen,miao ;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
sbit wale=P2^5;
sbit duan=P2^6;
sbit wr=P2^7;
void delay(uint z)
{
uint i,y;
for(i=z;i>0;i--)
for(y=123;y>0;y--);
}
void display(uchar fen, uchar miao)
{
wr=0;
wale=0;
P3=0xfd;
wr=1;
wale=1;
wr=0;
duan=0;
P3=tab[fen];//分
wr=1;
duan=1;
delay(5);
wr=0;
wale=0;
P3=0xfe;
wr=1;
wale=1;
wr=0;
duan=0;
P3=tab[miao];//秒
wr=1;
duan=1;
delay(5);
}
void init()
{
EA=1;//开总中断
ET0=1;//定时器T0中断允许
TMOD=0x01; //使用定时器T0的模式2
TH0=(65536-46083)/256;
TL0=(65536-46083)%256;
TR0=1;
}
void Time0(void) interrupt 1 using 0
{
TH0=(65536-46083)/256;
TL0=(65536-46083)%256;
Countor++;
}
void main ()
{
init();
while(1)
{
if(Countor==20)
{
Countor=0;
temp++;
if(temp==100)
temp=0;
fen=temp/10;
miao=temp%10;
}
display(fen ,miao);
}
}