DS1337_driver
gitee地址
使用记得点小心心哦
介绍
DS1337 RTC 时钟芯片驱动
使用说明
- 驱动写提供了IIC接口函数指针(如下),用户只需要调用ds1337_set_read_write_function()函数即可设置IIC接口函数。
/**
* @description: I2C write interface
* @param reg_addr: Register address
* @param data: write data
* @param length: write length
* @return 0: successful
*/
static int (*ds1337_i2c_mem_write)(uint8_t reg_addr, uint8_t *data, uint8_t length);
/**
* @description: I2C read interface
* @param reg_addr: Register address
* @param data: read data
* @param length: read length
* @return 0: successful
*/
static int (*ds1337_i2c_mem_read)(uint8_t reg_addr, uint8_t *data, uint8_t length);
- 使用int ds1337_set_time(struct tm *time_struct)函数设置时间。
函数需要传入C库tm结构体来设置时间。
#inclulde <time.h>
struct tm test_time = {
.tm_sec = 55,
.tm_min = 59,
.tm_hour = 23,
.tm_mday = 31,
.tm_mon = 12 - 1,
.tm_wday = 0,
.tm_year = 2099 - 1900
};
at_rtc_set_time(&test_time);
- 使用int ds1337_get_time(struct tm *time_struct);获取时间。
struct tm test_read_time = {0};
at_rtc_get_time(&test_read_time);
- 打印时间
time_t time_sec;
time_sec = mktime(&test_read_time);
printf("%s\r\n", ctime(&time_sec));
//或者
char buff[50] = {0};
strftime(buff, 80, "%Y-%m-%d %H:%M:%S", &test_read_time);
printf("%s\r\n", buff);
- 效果如图:
可以正常设置时间,读取时间,进位正确。