#ifndef __CLOCK_H__ #define __CLOCK_H__ #include "config.h" // 全局软时钟变量声明 extern u8 current_hour; extern u8 current_min; extern u8 current_sec; extern u8 current_day; // 日 (1~31) extern u8 current_month; // 月 (1~12) extern u8 current_year; // 年 (0~99,代表 2000~2099,不处理世纪) extern u8 current_weekday; // 星期 (0=周日, 1=周一, ..., 6=周六) extern volatile u8 clock_updated; extern volatile bit second_tick_flag; // 整秒滴答标志位,每次 current_sec 递增时置 1,供主循环转换为事件 /** * @brief 系统软时钟毫秒递增更新 (在 1ms 中断中调用) */ void Clock_IncMS(void); /** * @brief 返回指定年月的天数上限 (处理闰年 2 月) * @param year 年 (0~99,代表 2000~2099) * @param month 月 (1~12) */ u8 Days_In_Month(u8 year, u8 month); /** * @brief 根据年月日重新计算星期,并写回 current_weekday * @details 采用 Zeller 公式现算,不依赖 RTC 自身的星期寄存器, * 避免手动改日期后星期跟着错乱;日期发生变化(自然进位或手动调节)时都要调用一次。 */ void Clock_RecalcWeekday(void); #endif // __CLOCK_H__