#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar code t[]={
0xed,0x48,0xf4,
0xb5,0xb5,0x99,
0x3d,0x7d,0x7d,0x85,
0xfd,0xbd
};
void dely(uint);
void disp(uchar,uchar,uchar,uchar,uchar,uchar);
uchar num,num1,num2,num3,shi1,shi2,fen1,fen2,miao1,miao2;
void main()
{
TMOD=0x11;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;ET0=1;TR0=1;
while(1)
{
disp(shi1,shi2,fen1,fen2,miao1,miao2);
}
}
void dely(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void disp(uchar shi1,uchar shi2,uchar fen1,uchar fen2,uchar miao1,uchar miao2)
{
dula=1;
P0=t[shi1];
dula=0;
P0=0xff;
wela=1;
P0=0x1f;
wela=0;
dely(5);
dula=1;
P0=t[shi2];
dula=0;
P0=0xff;
wela=1;
P0=0x2f;
wela=0;
dely(5);
dula=1;
P0=t[fen1];
dula=0;
P0=0xff;
wela=1;
P0=0x37;
wela=0;
dely(5);
dula=1;
P0=t[fen2];
dula=0;
P0=0xff;
wela=1;
P0=0x3b;
wela=0;
dely(5);
dula=1;
P0=t[miao1];
dula=0;
P0=0xff;
wela=1;
P0=0x3d;
wela=0;
dely(5);
dula=1;
P0=t[miao2];
dula=0;
P0=0xff;
wela=1;
P0=0x3e;
wela=0;
dely(5);
}
void ZD() interrupt 1
{
TH0=(65536-45872)/256;
TL0= (65536-45872)%256;
num++;
if(num==20)
{
num=0;
num1++;
miao2=num1%10;miao1=num1/10;
if(num1==60){
num1=0;
num2++;
}
fen1=num2/10;
fen2=num2%10;
if(num2==60){
num2=0;
num3++;
}
shi1=num3/10;
shi2=num3%10;
if(num3==60)
num3=0;
}
}
用一个中断来写的。