极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 32759|回复: 10

Arduino + DS1302时钟模块遇到问题

[复制链接]
发表于 2013-11-5 21:51:25 | 显示全部楼层 |阅读模式
本帖最后由 mybag1 于 2013-11-5 21:58 编辑

我使用arduino与DS1302时钟模块练习时,按照下面的代码,将VCC接5V,GND接地,CLK接4,DAT接3,RST接2。结果运行后,全显示为xxxxxxxxx 00.00.2000 -- 00:00:40是什么原因?

  1. // DS1302_Serial_Easy (C)2010 Henning Karlsen
  2. // web: http://www.henningkarlsen.com/electronics
  3. //
  4. // A quick demo of how to use my DS1302-library to
  5. // quickly send time and date information over a serial link
  6. //
  7. // I assume you know how to connect the DS1302.
  8. // DS1302:  CE pin    -> Arduino Digital 2
  9. //          I/O pin   -> Arduino Digital 3
  10. //          SCLK pin  -> Arduino Digital 4

  11. #include <DS1302.h>

  12. // Init the DS1302
  13. DS1302 rtc(2, 3, 4);

  14. void setup()
  15. {
  16.   // Set the clock to run-mode, and disable the write protection
  17.   rtc.halt(false);
  18.   rtc.writeProtect(false);
  19.   
  20.   // Setup Serial connection
  21.   Serial.begin(9600);

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

  27. void loop()
  28. {
  29.   // Send Day-of-Week
  30.   Serial.print(rtc.getDOWStr());
  31.   Serial.print(" ");
  32.   
  33.   // Send date
  34.   Serial.print(rtc.getDateStr());
  35.   Serial.print(" -- ");

  36.   // Send time
  37.   Serial.println(rtc.getTimeStr());
  38.   
  39.   // Wait one second before repeating :)
  40.   delay (1000);
  41. }
复制代码


执行情况:


本帖子中包含更多资源

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

x
回复

使用道具 举报

 楼主| 发表于 2013-11-6 20:29:12 | 显示全部楼层
没人能帮忙回答一下吗?弘毅老师能否帮帮忙?
回复 支持 反对

使用道具 举报

发表于 2013-11-7 11:24:21 | 显示全部楼层
setup部分这样写试试:

  1. void setup()
  2. {
  3.   // Set the clock to run-mode, and disable the write protection
  4.   rtc.halt(true);
  5.   rtc.writeProtect(false);

  6.   // Setup Serial connection
  7.   Serial.begin(9600);

  8.   // The following lines can be commented out to use the values already stored in the DS1302
  9. // rtc.setDOW(FRIDAY);        // Set Day-of-Week to FRIDAY
  10.   rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  11.   rtc.setDate(6, 8, 2013);   // Set the date to August 6th, 2010
  12.   rtc.halt(false);
  13.   rtc.writeProtect(true);
  14. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2013-11-7 15:11:48 | 显示全部楼层
看了一下你的库代码,可能是模块数据读取出错了,建议直接读取各个时间变量,而不是使用它的字符输出函数
另外,下次求助记得也贴一下你的库~~
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-11-7 20:58:21 | 显示全部楼层
shenhaiyu 发表于 2013-11-7 11:24
setup部分这样写试试:

void setup()

灰常感谢,搞定!
回复 支持 反对

使用道具 举报

发表于 2013-11-7 21:46:50 | 显示全部楼层
mybag1 发表于 2013-11-7 20:58
灰常感谢,搞定!

有空的话建议你看看我转来的几篇帖子,都看懂了就完全明白DS130X系列的工作原理了,遇到问题也能自己解决了:


http://www.geek-workshop.com/thread-2225-1-1.html
http://www.geek-workshop.com/thread-2224-1-1.html
http://www.geek-workshop.com/thread-2227-1-1.html
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-11-7 22:04:31 | 显示全部楼层
好的,谢谢
回复 支持 反对

使用道具 举报

发表于 2013-12-9 21:55:51 | 显示全部楼层
好久没搞这个了,一直想在数码管上输出,还是LCD简单。
回复 支持 反对

使用道具 举报

发表于 2014-1-14 14:35:39 | 显示全部楼层
shenhaiyu 发表于 2013-11-7 11:24
setup部分这样写试试:

void setup()

我这样试了还是不行怎么办?
回复 支持 反对

使用道具 举报

发表于 2014-1-14 22:07:17 | 显示全部楼层
zengwh 发表于 2014-1-14 14:35
我这样试了还是不行怎么办?

那就是晶振停震了
回复 支持 反对

使用道具 举报

发表于 2016-4-15 10:45:40 | 显示全部楼层
问题解决吗?有同一问题,你是怎么解决的?
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-18 12:37 , Processed in 0.043881 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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