#include
#include
#include
unsigned char hour;
unsigned char minite;
unsigned char second;
unsigned char second20;
//unsigned char time;
//void delay( unsigned char time);
unsigned char display_buff[6];
unsigned char code display_code[32]=
{
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e ,0x79, 0x71,
0x3d, 0x76, 0x38, 0x54, 0x5c, 0x73, 0x3e, 0x6e,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
};
//延时子程序//
void delay(unsigned char time)
{
unsigned char i,j;
for(i=0;i<=time;i++)
{for(j=0;j<=140;j++)
{
}
}
}
//数码管显示程序//
void display (void)
{
unsigned char i;
P2=0xfe;
P0=0;
for(i=0;i<6;i++)
{
P0=display_buff;
delay(2);
P0=0;
P2=_col_(P2,1);
}
}
//定时 计数中断服务子程序//
//定时每隔50ms中断一次,据 秒 分 小时的进制关系
//设定条件判断用 second minite hour分别代表 秒 分 小时
void time0_ISR(void)interrupt 1 using 0
{
TH0=0x3C;
TL0=0x0B0;
second20++;
if (second20==20)
{
second20=0;
second++;
if(second==60)
{
second=0;
minite++;
if(minite==60)
{
minite=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
}
}
//系统初始化程序//
void init(void)
{
TMOD=0x01;
TH0=0x3C;
TL0=0x0B0;
TF0=0;
TR0=1;
hour=12;
minite=0;
second=0;
second20=0;
ET0=1;
EA=1;
}
//主程序//
void main(void)
{
init();
while(1)
{//display respectively
display_buff[5]=display_code[hour/10];
display_buff[4]=display_code[hour%10]/0x80;
display_buff[3]=display_code[minite/10];
display_buff[2]=display_code[minite%10]/0x80;
display_buff[1]=display_code[second/10];
display_buff[0]=display_code[second%10];
display();
}
}