|
建议用“连续读取”的模式,这样比单个数据读取省时间。
- #ifndef _DS1302_H_
- #define _DS1302_H_
- #include "const.h"
- #include "chiptypedef.h"
- /**********************************************
- 仅实现多字节读取模式,单字节和RAM的没有实现
- 仅实现24小时制模式,12小时制没实现
- ***********************************************/
- //更改为合适的位
- #define RST_PIN P3_2
- #define SCLK_PIN P3_3
- #define IO_PIN P3_4
- typedef struct tagBCDDATETIME //注意:字节顺序必须和burst的传输顺序一致
- {
- BYTE nSecond;
- BYTE nMinute;
- BYTE nHour;
- BYTE nDay;
- BYTE nMonth;
- BYTE nDayOfWeek;
- BYTE nYear;
- BYTE WriteProtect; // Before ANY write operation to the clock or RAM, bit 7 must be 0
- }BCDDATETIME;
- void InitDS1302();
- void SetDateTime(const BCDDATETIME* pBCDDateTime);
- void GetDateTime(BCDDATETIME* pBCDDateTime);
- ///////////////////////////////////////
- //
- typedef enum tagCOMMANDBYTE
- {
- SECOND_WRITE = 0x80,
- SECOND_READ,
- MINUTE_WRITE,
- MINUTE_READ,
- HOUR_WRITE,
- HOUR_READ,
- DATE_WRITE,
- DATE_READ,
- MONTH_WRITE,
- MONTH_READ,
- DAY_WRITE,
- DAY_READ,
- YEAR_WRITE,
- YEAR_READ,
- CONTROL = 0x8e, //控制寄存器
- TRICKLE_CHARGE = 0x90, //涓流充电设置
- CLOCK_BURST_WRITE = 0xbe, //burst模式传输字节
- CLOCK_BURST_READ = 0xbf,
- RAM_BURST_WRITE = 0xfe, //burst模式读写ram
- RAM_BURST_READ = 0xff,
- }COMMANDBYTE;
- static void WriteSingleCmdByte(COMMANDBYTE cmd, BYTE Data);
- static BYTE ReadSingleCmdByte(COMMANDBYTE cmd);
- static void WriteOneByte(BYTE byte);
- static BYTE ReadOneByte();
- #endif
复制代码 |
|