102 lines
2.6 KiB
C
102 lines
2.6 KiB
C
#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_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;//接收设定时间
|
||
extern UnTimeOutput inittime;// 默认设置 2025年,8月2日 周六,16:37:00
|
||
|
||
|
||
// 假设 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)
|
||
|
||
|
||
|
||
unsigned char BcdToDec(unsigned char bcd);
|
||
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 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 |