极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11209|回复: 3

arduino-ds1302 时间显示问题

[复制链接]
发表于 2016-8-8 09:48:43 | 显示全部楼层 |阅读模式
麻烦求助一下,网上下载的样例,但是读取的时候会有乱码,试了好几个例子都是这样,请教一下大家这是为什么?谢谢!



  1. #include <DS1302.h>

  2. // Init the DS1302
  3. DS1302 rtc(2, 3, 7);

  4. void setup()
  5. {
  6.   // Set the clock to run-mode, and disable the write protection
  7.   rtc.halt(false);
  8.   rtc.writeProtect(false);
  9.   
  10.   // Setup Serial connection
  11.   Serial.begin(9600);

  12.   // The following lines can be commented out to use the values already stored in the DS1302
  13. // rtc.setDOW(FRIDAY);        // Set Day-of-Week to FRIDAY
  14.   rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  15.   rtc.setDate(6, 8, 2013);   // Set the date to August 6th, 2010
  16. }

  17. void loop()
  18. {
  19.   // Send Day-of-Week
  20.   Serial.print(rtc.getDOWStr());
  21.   Serial.print(" ");
  22.   
  23.   // Send date
  24.   Serial.print(rtc.getDateStr());
  25.   Serial.print(" -- ");

  26.   // Send time
  27.   Serial.println(rtc.getTimeStr());
  28.   
  29.   // Wait one second before repeating :)
  30.   delay (1000);
  31. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2016-8-8 18:18:47 | 显示全部楼层
本帖最后由 275891381 于 2016-8-8 18:20 编辑

库文件有问题,发下我给你看看
uint8_t DS1302::seconds()
{
  return _register_bcd_to_dec(SEC_REG, 6);
}


uint8_t DS1302::minutes()
{
  return _register_bcd_to_dec(MIN_REG);
}

改成下面试试
uint8_t DS1302::seconds()
{
  return _register_bcd_to_dec(SEC_REG, 6);
}


uint8_t DS1302::minutes()
{
  return _register_bcd_to_dec(MIN_REG,6);
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-8-9 00:02:43 | 显示全部楼层
275891381 发表于 2016-8-8 18:18
库文件有问题,发下我给你看看
uint8_t DS1302::seconds()
{

你好库文件是修改哪个呀。。。。。?
回复 支持 反对

使用道具 举报

发表于 2016-8-9 07:53:02 | 显示全部楼层
本帖最后由 275891381 于 2016-8-9 08:04 编辑
wyl_stloy 发表于 2016-8-9 00:02
你好库文件是修改哪个呀。。。。。?


这么空说,谁知道修改哪个
这个肯定可以用

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-4 13:41 , Processed in 0.041152 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表