Files
stc32g128k/Drivers/pcf8563.h
edisondeng 6022f0a409 feat(ui): extend set_clock_app to edit day/month/year, not just time
time_edit_field now cycles through 5 fields (hour/min/day/month/year)
via long-press CONFIRM. Up/down adjusts whichever field is focused,
with day clamped to Days_In_Month() when month/year changes, and
Clock_RecalcWeekday() called after every date edit so the weekday
label stays in sync. UI_UpdateSetTimeDigit() now also refreshes the
weekday abbreviation when editing day/month/year, since the computed
weekday can change independently of which digit was actually touched.
Save writes the full date+weekday via PCF8563_WriteDateTime(). Also
removes PCF8563_ReadTime()/WriteTime(), now unused since every caller
was updated to the DateTime variants directly.
2026-07-31 19:53:56 +08:00

67 lines
2.4 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __PCF8563_H__
#define __PCF8563_H__
#include "../App/config.h"
/* ====== PCF8563 器件地址与寄存器定义 ====== */
#define PCF8563_ADDR_READ 0xA3 // PCF8563 读地址 (0xA2 | 0x01)
#define PCF8563_ADDR_WRITE 0xA2 // PCF8563 写地址 (0xA2)
#define REG_CTRL_STATUS1 0x00 // 控制/状态寄存器 1
#define REG_CTRL_STATUS2 0x01 // 控制/状态寄存器 2
#define REG_VL_SECONDS 0x02 // 秒寄存器 (bit7 为 VL 保证标志)
#define REG_MINUTES 0x03 // 分钟寄存器
#define REG_HOURS 0x04 // 小时寄存器
#define REG_DAYS 0x05 // 日寄存器
#define REG_WEEKDAYS 0x06 // 星期寄存器
#define REG_MONTHS 0x07 // 月份寄存器 (bit7 为 C 世纪位)
#define REG_YEARS 0x08 // 年份寄存器
/**
* @brief 初始化 PCF8563 RTC 芯片
* @details 初始化 I2C 管脚高电平,并检测芯片启动状态
* @return bit 1: 芯片响应正常, 0: 通讯异常
*/
bit PCF8563_Init(void);
/**
* @brief 从 PCF8563 芯片连续读取时间与日期 (时/分/秒/日/月/年)
* @param hour 小时指针 (0~23)
* @param min 分钟指针 (0~59)
* @param sec 秒钟指针 (0~59)
* @param day 日指针 (1~31)
* @param month 月指针 (1~12)
* @param year 年指针 (0~99代表 2000~2099不处理世纪位)
* @return bit 1: 读取成功, 0: 通讯失败
*/
bit PCF8563_ReadDateTime(u8 *hour, u8 *min, u8 *sec, u8 *day, u8 *month, u8 *year);
/**
* @brief 将指定的时间与日期一次性连续写入 PCF8563 芯片
* @param hour 小时 (0~23)
* @param min 分钟 (0~59)
* @param sec 秒钟 (0~59)
* @param day 日 (1~31)
* @param month 月 (1~12)
* @param year 年 (0~99代表 2000~2099)
* @param weekday 星期 (0~6需与软件侧约定的星期数值一致芯片本身不做校验)
* @return bit 1: 写入成功, 0: 通讯失败
*/
bit PCF8563_WriteDateTime(u8 hour, u8 min, u8 sec, u8 day, u8 month, u8 year, u8 weekday);
/**
* @brief I2C 总线器件扫描诊断函数
* @details 逐个发送 I2C 写地址,检测总线上是否有响应的器件,并在串口打印发现的设备地址
*/
void PCF8563_ScanDiagnostic(void);
/**
* @brief 尝试直接用最底层时序试读 RTC 控制寄存器并输出 ACK 调试日志
*/
bit PCF8563_TryReadDiagnostic(void);
// 动态引脚对调标志 (由 pcf8563.c 维护0: 默认, 1: 互换)
extern volatile u8 i2c_swapped;
#endif // __PCF8563_H__