Arduino + DS1302时钟模块遇到问题
本帖最后由 mybag1 于 2013-11-5 21:58 编辑我使用arduino与DS1302时钟模块练习时,按照下面的代码,将VCC接5V,GND接地,CLK接4,DAT接3,RST接2。结果运行后,全显示为xxxxxxxxx 00.00.2000 -- 00:00:40是什么原因?
// DS1302_Serial_Easy (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1302-library to
// quickly send time and date information over a serial link
//
// I assume you know how to connect the DS1302.
// DS1302:CE pin -> Arduino Digital 2
// I/O pin -> Arduino Digital 3
// SCLK pin-> Arduino Digital 4
#include <DS1302.h>
// Init the DS1302
DS1302 rtc(2, 3, 4);
void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
// Setup Serial connection
Serial.begin(9600);
// The following lines can be commented out to use the values already stored in the DS1302
// rtc.setDOW(FRIDAY); // Set Day-of-Week to FRIDAY
rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 8, 2013); // Set the date to August 6th, 2010
}
void loop()
{
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
// Wait one second before repeating :)
delay (1000);
}
执行情况:
没人能帮忙回答一下吗?弘毅老师能否帮帮忙? setup部分这样写试试:
void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(true);
rtc.writeProtect(false);
// Setup Serial connection
Serial.begin(9600);
// The following lines can be commented out to use the values already stored in the DS1302
// rtc.setDOW(FRIDAY); // Set Day-of-Week to FRIDAY
rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 8, 2013); // Set the date to August 6th, 2010
rtc.halt(false);
rtc.writeProtect(true);
} 看了一下你的库代码,可能是模块数据读取出错了,建议直接读取各个时间变量,而不是使用它的字符输出函数
另外,下次求助记得也贴一下你的库~~ shenhaiyu 发表于 2013-11-7 11:24 static/image/common/back.gif
setup部分这样写试试:
void setup()
灰常感谢,搞定! mybag1 发表于 2013-11-7 20:58 static/image/common/back.gif
灰常感谢,搞定!
有空的话建议你看看我转来的几篇帖子,都看懂了就完全明白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
好的,谢谢 好久没搞这个了,一直想在数码管上输出,还是LCD简单。 shenhaiyu 发表于 2013-11-7 11:24 static/image/common/back.gif
setup部分这样写试试:
void setup()
我这样试了还是不行怎么办? zengwh 发表于 2014-1-14 14:35 static/image/common/back.gif
我这样试了还是不行怎么办?
那就是晶振停震了 问题解决吗?有同一问题,你是怎么解决的?
页:
[1]