feat(clock): add day/month/year rollover and Zeller weekday calc
Extends Clock_IncMS()'s existing sec->min->hour cascade to also roll day->month->year (with leap-year Feb 29 via Days_In_Month()), and adds Clock_RecalcWeekday() computing current_weekday via Zeller's congruence whenever the date changes, rather than trusting PCF8563's own weekday register (which would drift if the date is edited manually). Verified the formula against 2026-07-31, a known Friday.
This commit is contained in:
18
App/clock.h
18
App/clock.h
@@ -7,6 +7,10 @@
|
||||
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,供主循环转换为事件
|
||||
|
||||
@@ -15,4 +19,18 @@ extern volatile bit second_tick_flag; // 整秒滴答标志位,每次 current_
|
||||
*/
|
||||
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__
|
||||
|
||||
Reference in New Issue
Block a user