#include
#define uchar unsigned char
#define uint unsigned int
void init();//hanshushengming
void delay(uint );//hanshushengming
void display_fen(uint aa,uint bb,uint cc);//hanshushengming
void display_miao(uint cc,uint dd);//hanshushengming
void keyscan();//hanshushengming
void display();//hanshushengming
sbit duan=P2^6;
sbit wei=P2^7;
sbit key1=P3^4;
uint t0,t1,num1,num2;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void main()
{
init();
while(1)
{
display();
display_fen(num1/100,num1/10%10,num1%10);
display_miao(num2/10,num2%10);
if(key1==0)
{
delay(10);
if(key1==0)
{
TR0=0;
TR1=0;
while(!key1)
{
display_fen(num1/100,num1/10%10,num1%10);
display_miao(num2/10,num2%10);
display();
}
TR0=1;
TR1=1;
}
}
}
}
void init()
{
TMOD=0x11;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
}
void time_0() interrupt 1 //定时分钟
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
t0++;
if(t0==1200)
{
t0=0;
num1++;
if(num1==1000)
num1=0;
}
}
void time_1() interrupt 3//定时秒
{
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
t1++;
if(t1==20)
{
t1=0;
num2++;
if(num2==60)
{
num2=0;
}
}
}
void display_fen(uint aa,uint bb,uint cc)
{
duan=1;
P0=table[aa];
duan=0;
P0=0xff;
wei=1;
P0=0xfe;//1 liang
wei=0;
delay(1);
duan=1;
P0=table[bb];
duan=0;
P0=0xff;
wei=1;
P0=0xfd;//2 liang
wei=0;
delay(1);
duan=1;
P0=table[cc];
duan=0;
P0=0xff;
wei=1;
P0=0xfb;
wei=0;
delay(1);//3 liang
}
void display_miao(uint dd,uint ee)
{
duan=1;
P0=table[dd];
duan=0;
P0=0xff;
wei=1;
P0=0xef;//5 liang
wei=0;
delay(1);
duan=1;
P0=table[ee];
duan=0;
P0=0xff;
wei=1;
P0=0xdf;//6 liang
wei=0;
delay(1);
}
void delay(uint m)
{
uint i,j;
for(i=m;i>0;i--)
for(j=110;j>0;j--);
}
void display()
{
duan=1;
P0=0x40;//让数码管亮一
duan=0;
P0=0xff;
wei=1;
P0=0xf7;//让第四个数码管亮
wei=0;
}