eecs-bsp-test-code-2/inc/DS1302.h

75 lines
4.3 KiB
C
Raw Permalink Normal View History

2022-08-23 16:16:38 +08:00
/**********************************DS1302 V1.1 说明 ************************************************************************
DS1302模块用于控制STC-B学习板DS1302芯片操作
DS1302提供RTCNVMRTC和NVM是依靠纽扣电池BAT维持工作的
RTC提供
NVM提供31 Bytes非易失存储器功能(03030DS1302Init()DS1302是否掉电使)
DS1302模块共提供1个驱动函数4
2022-08-22 14:51:00 +08:00
2022-08-23 16:16:38 +08:00
(1) void DS1302Init(struct_DS1302_RTC time)DS1302驱动函数使DS1302
struct_DS1302_RTC time
DS1302掉电RTC数据失效time定义的时间初始化RTC
2022-08-22 14:51:00 +08:00
2022-08-23 16:16:38 +08:00
(2) struct_DS1302_RTC RTC_Read(void)DS1302内部实时时钟RTC内容
struct_DS1302struct_DS1302定义
2022-08-22 14:51:00 +08:00
2022-08-23 16:16:38 +08:00
(3) void RTC_Write(struct_DS1302_RTC time) DS1302内部实时时钟RTC内容
struct_DS1302 timestruct_DS1302定义
2022-08-22 14:51:00 +08:00
2022-08-23 16:16:38 +08:00
(4) unsigned char NVM_Read(unsigned char NVM_addr): NVM一个指定地址内容
NVM_addr03031
NVM中对应单元的存储数值1Byte
enumDS1302_error
2022-08-22 14:51:00 +08:00
2022-08-23 16:16:38 +08:00
(5) unsigned char NVM_Write(unsigned char NVM_addr, unsigned char NVM_data)NVM一个指定地址写入新值
NVM_addr0303130DS1302Init()DS1302是否掉电使)
NVM_dataNVM单元的新值1Byte
enumDS1302_OK
enumDS1302_error
2022-08-22 14:51:00 +08:00
2022-08-23 16:16:38 +08:00
struct_DS1302_RTC定义DS1302Z数据手册
2022-08-22 14:51:00 +08:00
typedef struct
2022-08-23 16:16:38 +08:00
{ unsigned char second; //秒BCD码以下均为BCD码
unsigned char minute; //分
unsigned char hour; //时
unsigned char day; //日
unsigned char month; //月
unsigned char week; //星期
unsigned char year; //年
2022-08-22 14:51:00 +08:00
} struct_DS1302_RTC;
2022-08-23 16:16:38 +08:00
DS1302内部非易失性存储器补充说明
DS1302提供的非易失性存储器为低功耗RAM结构
M24C01区别31寿
DS1302内部NVM每一个字节均需要花费一定操作时间uS
使
2022-08-22 14:51:00 +08:00
2022-08-23 16:16:38 +08:00
18008400450 2021852021815
2022-08-22 14:51:00 +08:00
*/
#ifndef _DS1302_H_
#define _DS1302_H_
typedef struct
2022-08-23 16:16:38 +08:00
{ unsigned char second; //秒BCD码以下均为BCD码
unsigned char minute; //分
unsigned char hour; //时
unsigned char day; //日
unsigned char month; //月
unsigned char week; //星期
unsigned char year; //年
2022-08-22 14:51:00 +08:00
} struct_DS1302_RTC;
2022-08-23 16:16:38 +08:00
extern void DS1302Init(struct_DS1302_RTC time); //DS1302初始化
extern struct_DS1302_RTC RTC_Read(void); //读RTC读RTC时钟内容
extern void RTC_Write(struct_DS1302_RTC time); //写RTC校对RTC时钟
extern unsigned char NVM_Read(unsigned char NVM_addr); //读NVM读DS1302中的非易失存储单元内容
extern unsigned char NVM_Write(unsigned char NVM_addr, unsigned char NVM_data); //写NVM写DS1302中的非易失存储单元
2022-08-22 14:51:00 +08:00
enum DS1302name {enumDS1302_OK,enumDS1302_error};
#endif