# ds1337_driver **Repository Path**: ischen-x/ds1337_driver ## Basic Information - **Project Name**: ds1337_driver - **Description**: ds1337 rtc驱动程序 - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2024-07-29 - **Last Updated**: 2024-08-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: DS1337, RTC ## README # DS1337_driver [gitee地址](https://gitee.com/ischen-x/ds1337_driver) 使用记得点小心心哦 #### 介绍 DS1337 RTC 时钟芯片驱动 #### 使用说明 1. 驱动写提供了IIC接口函数指针(如下),用户只需要调用ds1337_set_read_write_function()函数即可设置IIC接口函数。 ```c /** * @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); ``` 2. 使用int ds1337_set_time(struct tm *time_struct)函数设置时间。 函数需要传入C库tm结构体来设置时间。 ```c #inclulde 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); ``` 3. 使用int ds1337_get_time(struct tm *time_struct);获取时间。 ```c struct tm test_read_time = {0}; at_rtc_get_time(&test_read_time); ``` 4. 打印时间 ```c 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); ``` 5. 效果如图: ![](demo.png "demo演示") 可以正常设置时间,读取时间,进位正确。