#include<reg52.h>
#include"display.h"
#include"key.h"
unsigned char hour,miniute,second,keyval;
extern unsigned char temp[8];
extern unsigned char code duanma[10];//={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};// 显示段码值0~9
extern unsigned char code weima[];//={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//分别对应相应的数码管点亮,即位码
bit flag;
void main()
{
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
// TH0=(65536-2000)/256;
// TL0=(65536-2000)%256;
while(1)
{
keyval=keyscan();
switch(keyval)
{
case 1: hour++;break;
case 2: miniute++;break;
case 3: second++;break;
default:break;
}
if(flag==1)
{
temp[0]=duanma[hour/10];
temp[1]=duanma[hour%10];
temp[2]=0x40;
temp[3]=duanma[miniute/10];
temp[4]=duanma[miniute%10];
temp[5]=0x40;
temp[6]=duanma[second/10];
temp[7]=duanma[second%10];
flag=0;
}
}
}
void timer0()interrupt 1
{
static unsigned int i,k;
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
display(0,8);
i++;
k++;
if(k==10)
{
flag=1;
k=0;
}
if(i==500)
{
second++;
i=0;
if(second==60)
{
miniute++;
second=0;
}
if(miniute==60)
{
hour++;
if(hour==60)
hour=0;
}
} |