时钟芯片rx8025t芯片读取,小时超出24小时,请问是什么原因?

作者站长头像
站长
· 阅读数 17

时钟芯片rx8025t芯片读取,小时超出24小时,请问是什么原因?

这是i2c返回的结果小时是第三个字节,0x36,转成bcd然后10进制是36,直接超出24小时了

#include <stdio.h>

unsigned char bcd_decimal(unsigned char bcd)
{
    return bcd - (bcd >> 4) * 6;
}

int main(void)
{
    unsigned char buf[7] = {0x18, 0x27, 0x36, 0x00, 0x08, 0x12, 0x23};
    printf("date -s %04d-%02d-%02d %02d:%02d:%02d\n",
           2000 + bcd_decimal(buf[6]),
           bcd_decimal(buf[5]),
           bcd_decimal(buf[4]),

           bcd_decimal(buf[2] & 0x3f),
           bcd_decimal(buf[1]),
           bcd_decimal(buf[0]));
    return 0;
}

输出结果是

➜ gcc hello.c && ./a.out
date -s 2023-12-08 36:27:18

参数解析:时钟芯片rx8025t芯片读取,小时超出24小时,请问是什么原因?

具体规格书:规格书

请问是什么原因导致的?

回复
1个回答
avatar
test
2024-06-24

自问自答吧,看的规格书不对找到了正确的规格书

寄存器有一位是表示12小时格式还是24小时格式的,不通的时间格式读取不一样

answer image

有需要可以私信我要修改后的代码

回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容