|
楼主 |
发表于 2024-8-8 09:59:03
|
显示全部楼层
这里是中断1
void T1_ISR_PC(void) interrupt 3 {
static u16 hours, minutes, seconds;
static u16 ms_count = 0;
EA = 0;
TH1 = T1MS >> 8;
TL1 = T1MS;
ms_count++;
if (ms_count >= 1000) { // 每1000ms更新一次
ms_count = 0;
if (!initialized) {
ReadCountdownTime(&hours, &minutes, &seconds);
initialized = 1;
}
if (seconds >0) {
seconds--;
} else {
if (minutes > 0) {
minutes--;
seconds = 59;
} else {
if (hours > 0) {
hours--;
minutes = 59;
seconds = 59;
} else {
// 倒计时结束,更新显示并发送开机命令
page_change(66);
UpdateCountdownTime(0, 0, 0);
//SendPowerOnCommand();
TR1 = 0;
TR0 = 1;
initialized = 0; // 重新初始化
EA = 1;
return;
}
}
}
// 更新显示
UpdateCountdownTime(hours, minutes, seconds);
}
EA = 1;
}
下面是时间更新函数
void ReadCountdownTime( u16 *hours,u16 *minutes,u16 *seconds)
{
u8 buf[2];
Write_Dgusii_Vp_byChar(0x2036,zero,2);
Read_Dgusii_Vp(0x1094,buf,2);//读取小时
*hours = (buf[0] << 8 | buf[1]);
Read_Dgusii_Vp(0x1096,buf,2);//读取分钟
*minutes = (buf[0] << 8 | buf[1]);
Read_Dgusii_Vp(0x2036,buf,2);//读取秒
*seconds = (buf[0] << 8 | buf[1]);
}
void UpdateCountdownTime(u16 hours,u16 minutes,u16 seconds)
{
u8 buffer[2] ;
buffer[0] = hours>>8;
buffer[1] = hours&0xFF;
Write_Dgusii_Vp_byChar(0x1094,buffer,2);//更新小时
buffer[0] = minutes>>8;
buffer[1] = minutes&0xFF;
Write_Dgusii_Vp_byChar(0x1096,buffer,2);//更新分钟
buffer[0] = seconds>>8;
buffer[1] = seconds&0xFF;
Write_Dgusii_Vp_byChar(0x2036,buffer,2);//更新秒
}
|
|