本帖最后由 Randy 于 2012-4-25 15:19 编辑
我的DS1307的问题超级奇怪,有7、8个这种模块都是出现这样的问题,起初以为是芯片的问题,换了芯片,还是一样的答案!不知道您们谁有过这样的结果,怎么解决,谢谢知道!
结果看图:
以下是代码部分!
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> // written by mattt on the Arduino forum and modified by D. Sjunnesson
void setup()
{
Serial.begin(9600);
RTC.stop();
RTC.set(DS1307_SEC,1); //set the seconds
RTC.set(DS1307_MIN,23); //set the minutes
RTC.set(DS1307_HR,12); //set the hours
RTC.set(DS1307_DOW,4); //set the day of the week
RTC.set(DS1307_DATE,5); //set the date
RTC.set(DS1307_MTH,3); //set the month
RTC.set(DS1307_YR,9); //set the year
RTC.start();
}
void loop()
{
Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
Serial.print(":");
Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
Serial.print(":");
Serial.print(RTC.get(DS1307_SEC,false));//read seconds
Serial.print(" "); // some space for a more happy life
Serial.print(RTC.get(DS1307_DATE,false));//read date
Serial.print("/");
Serial.print(RTC.get(DS1307_MTH,false));//read month
Serial.print("/");
Serial.print(RTC.get(DS1307_YR,false)); //read year
Serial.println();
delay(1000);
}
问题已经解决:
经过一段时间的总结,发现了问题所在,先告诉大家是怎么解决的。我试了25个板子,都可以进行工作了。
我总结一下解决方法的可能性!
第一: 确保您DS1307模块上的4.7K电阻是否接入电路当中。
第二: 查看一下您的掉电给电的纽扣电池是否插入电池座里。(这个原因不是很明确,但是在我没插电池时,有些模块测试不行,一旦确保电路接入4.7K电阻和电池时,完全可以工作了)!
第三: 查看一下电路连接是否正确,电路连接很简单,4根线。(VCC、GND、SCL、SDA)
第四: 如果发现在IDE编译程序时,不能成功,那就是可能是自己的操作不当或者不会操作(比如是不会把express 放入libraries 所导致编译的错误,方法请参照本论坛的相关帖子,谢谢)!
只要确保以上的步骤是正确的,那应该会没什么困难的进行工作,如果还有一个问题,那就是PCB板本身存在的问题咯。
如果大家还有什么问题,可以回帖一起学习哦!分享快乐! |