標題: DS1307 RTC時鐘芯片實驗 [打印本頁]

作者: 愛生活學(xué)習(xí)    時間: 2018-10-11 11:58
標題: DS1307 RTC時鐘芯片實驗
實驗器件 :
Arduino 控制板 1 塊、USB 數(shù)據(jù)線 1 根、面包板 1 塊、面包板專用跳線 1 盒、鑷子 1 把、DS1307 RTC 模塊。

實驗電路:


想了解更多創(chuàng)客知識,歡迎加入QQ群:820685901,或關(guān)注創(chuàng)客集結(jié)號。

實驗原理 :
本程序需要用電腦來接收 arduino 傳回的數(shù)據(jù),需要點擊打開串口監(jiān)視器。

Arduino  代碼 :
  1. #include <WProgram.h>
  2. #include <Wire.h>
  3. #include <DS1307.h>
  4. int rtc[7];
  5. int ledPin = 13;
  6. void setup()
  7. {
  8. DDRC|=_BV(2) |_BV(3); // POWER:Vcc Gnd
  9. PORTC |=_BV(3); // VCC PINC3
  10. pinMode(ledPin, OUTPUT);
  11. Serial.begin(9600);
  12. RTC.stop();
  13. RTC.set(DS1307_SEC,1);
  14. RTC.set(DS1307_MIN,57);
  15. RTC.set(DS1307_HR,17);
  16. RTC.set(DS1307_DOW,2);
  17. RTC.set(DS1307_DATE,18);
  18. RTC.set(DS1307_MTH,1);
  19. RTC.set(DS1307_YR,10);
  20. RTC.start();
  21. }
  22. void loop()
  23. {
  24. RTC.get(rtc,true);
  25. for(int i=0; i<7; i++){
  26. Serial.print(rtc[i]);
  27. Serial.print(" ");
  28. }
  29. Serial.println();
  30. digitalWrite(ledPin, HIGH);
  31. delay(500);
  32. digitalWrite(ledPin, LOW);
  33. delay(500);
  34. }
復(fù)制代碼



作者: redtxd    時間: 2018-10-17 14:09
老師好,怎么通過按鈕來設(shè)置DS1307的時間呢?謝謝!




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1