嵌入式跨平台DS1339驱动程序

嵌入式跨平台DS1339驱动程序

DS1339_driver

gitee地址
使用记得点小心心哦

介绍

DS1339 RTC 时钟芯片驱动

使用说明
  1. 驱动写提供了IIC接口函数指针(如下),用户只需要调用ds1339_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 (*ds1339_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 (*ds1339_i2c_mem_read)(uint8_t reg_addr, uint8_t *data, uint8_t length);

  1. 使用int ds1339_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);
  1. 使用int ds1339_get_time(struct tm *time_struct);获取时间。
struct tm test_read_time = {0};
at_rtc_get_time(&test_read_time);
  1. 打印时间
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);
  1. 效果如图:
    在这里插入图片描述

可以正常设置时间,读取时间,进位正确。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值