Files
TempControl/RTC.h
2025-10-21 21:25:35 +08:00

101 lines
2.6 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 _RTC_H_
#define _RTC_H_
//#define _nop_() udelay(1);
#define somenop {_nop_();_nop_();_nop_();_nop_();_nop_();}
typedef enum {
STATE_INIT = 0, // 初始化状态(首次运行)
STATE_ON, // ON状态唤醒工作模式
STATE_OFF, // OFF状态准备休眠
STATE_OFF2, // OFF2状态休眠监控
STATE_ON2 // ON2状态工作模式
} SystemState;
typedef struct {
ubyte year; // 年建议存储后两位如2025→25
ubyte month; // 月1-12
ubyte day; // 日1-31
ubyte hour; // 小时0-23
ubyte week; // 周 0-6
ubyte minute; // 分钟0-59
ubyte second; // 秒 0-59
ubyte resver;
} DateTimeInfo; // 类型名使用大驼峰法(帕斯卡命名法)
typedef union _UnTimeOutput
{
DateTimeInfo bit_data; // 使用定义的结构体变量名
ubyte arr[sizeof(DateTimeInfo)]; // 通过结构体类型确定大小
} UnTimeOutput;
extern unsigned char bySta;
extern UnTimeOutput currenttime;
extern UnTimeOutput un_time_output1;//接收设定时间
// 假设 BM8563 的 I2C 地址
#define BM8563_ADDR 0xA2
// 假设 BM8563 寄存器地址
#define BM8563_CSR2 0x01
#define BM8563_SEC 0x02
#define BM8563_MIN 0x03
#define BM8563_HOUR 0x04
#define BM8563_DAY 0x05
#define BM8563_WEEK 0x06
#define BM8563_MONTH 0x07
#define BM8563_YEAR 0x08
#define BM8563_ALARM_MIN 0x09
#define BM8563_ALARM_HOUR 0x0A
#define BM8563_ALARM_DAY 0x0B
#define BM8563_ALARM_WEEK 0x0C
#define BM8563_CONTROL 0x0E // 定时器控制寄存器
#define BM8563_STATUS 0x01
#define BM8563_TIMER_VALUE 0x0F // 定时器计数寄存器
#define BM8563_AF_BIT 0x08 // AF标志位Bit3
ubyte leapYear(uword year);
void BM8563_InitTime();
void BM8563_Set4HourCountdown();
unsigned char BM8563_ReadReg(unsigned char reg);
void BM8563_WriteReg(unsigned char reg, unsigned char rdata);
void BM8563_Set4HourAlarm();
void bm8563GetTime(UnTimeOutput *pTime);
ubyte bm8563SetAlarm(UnTimeOutput *pTime);
void bm8563SetTime(UnTimeOutput *pTime);
bool bm8563CheckAlarmFlag(void);
void bm8563ClearAlarmFlag(void);
void iic_start(void);
void iic_stop(void);
void iic_ack(bit ackbit);
void iic_sendbyte(unsigned char byt);
void wrbyte_24c02(unsigned int add,unsigned char dat);
bit iic_waitack(void);
unsigned char i2c_recbyte(void);
unsigned char rdbyte_24c02(unsigned int add);
unsigned char wrEE_CRC_Bak(unsigned char add,unsigned char *eeData,unsigned char len,unsigned char addbak);
unsigned char rdEE_CRC_Bak(unsigned char add,unsigned char *eeData,unsigned char len,unsigned char addbak);
#endif