Arduino: RTC DS1302

From OnnoWiki
Revision as of 05:37, 27 February 2016 by Onnowpurbo (talk | contribs) (New page: Sumber: http://domoticx.com/arduino-modules-rtc-tijdklok-ds1302/ ==Download Library== * http://domoticx.com/arduino-library-ds13xx-en-ds32xx-rtc-module/ * http://domoticx.phoenixinteract...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Sumber: http://domoticx.com/arduino-modules-rtc-tijdklok-ds1302/

Download Library


Rangkaian

Arduino-DS1302-schema.png

Pin

Arduino   RTC
+5v	  01 - VCC1 (+5v)
GND	  02 - GND
D6	  03 - CLK (serial clock)
D7	  04 - DAT (data)
D8	  05 - RST (reset)


Code

#include <DS1302.h>
 
// Init the DS1302
// DS1302 rtc([CE/RST], [I/O], [CLOCK]);
DS1302 rtc(8, 7, 6);
 
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, 2010);   // 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);
}


Referensi