{
initialize(); while(1) { }
//*****************定时器初始化************************** void initialize(void) {
TMOD = 0x01; TH0 = 0X3C; TL0 = 0XB0; ET0 = 1; EA = 1;
TR0 = 1; }
//*****************定时器T0中断服务程序**************** void Timer0(void) interrupt 1 {
TL0 = 0XB0; TH0 = 0X3C; t++;
if(t==20) // (50ms*20=1s)
P1=0X7F; //初始化时关掉蜂鸣器 alarm_flag=alarm_en=0;
//50ms
keyscan();
alarm_judge(); switch(moshi) {
case 0:show(); show4();break; //显示正常走时
case 1:show1();show3();break; //显示设置时间 case 2:show2();show3();break; //显示闹钟时间
//定时时间到达且闹钟打开
}
if(alarm_flag==1 && alarm_en==1) { beep(); }
}
19
{ t=0; sec++; } { sec=0; min++; } { min=0; hour++;} { hour=0;}
if(sec==60) // 秒为60,则清零,分加1 if(min==60) // 分为60,则清零,时加1 if(hour==24) // 时为24,则清零
if(sec1==60)
if(sec2==60) }
//******************正常时间显示程序******************* void show(void) {
uchar i=0;
temp[0]=sec;
temp[1]=sec/10; temp[2]=10;
{ sec2=0; min2++; } { min2=0; hour2++;} { hour2=0;} if(min2==60) if(hour2==24)
{ sec1=0; min1++; } { min1=0; hour1++;} { hour1=0;} if(min1==60) if(hour1==24)
temp[3]=min; temp[4]=min/10;
for(i=0;i<8;i++)
temp[5]=10; temp[6]=hour; temp[7]=hour/10;
20
{ }
//******************调时模式显示程序******************* void show1(void) {
uchar i=0;
temp1[1]=sec1/10; temp1[2]=10; temp1[0]=sec1;
P2=wei[i]; P0=duan[temp[i]]; delay(100);
}
temp1[3]=min1; temp1[4]=min1/10;
for(i=0;i<8;i++) { }
//******************闹钟设定模式显示程序******************* void show2(void) {
uchar i=0;
temp2[0]=sec2;
temp2[1]=sec2/10; temp2[2]=11; P2=wei[i];
P0=duan[temp1[i]]; delay(100); temp1[5]=11; temp1[6]=hour1; temp1[7]=hour1/10;
}
temp2[3]=min2;
21
temp2[4]=min2/10;
for(i=0;i<8;i++) { }
//******************调整位标记显示程序******************* void show3(void) {
uchar movv=0; switch(mov) }
//*********************闹钟开闭显示程序******************* void show4(void) {
if(alarm_en==1) {
P2=wei[2]+wei[5]; }
P0=duan[12]; delay(100); } {
case 0:movv=0;
case 1:movv=3; case 2:movv=6;
break; break; break;
P2=wei[i];
P0=duan[temp2[i]]; delay(100); temp2[5]=10; temp2[6]=hour2; temp2[7]=hour2/10;
}
}
P2=wei[movv];
P0=duan[12]; delay(100);
22

