DS1302 RTC Test

From Public Wiki
Jump to navigation Jump to search

Synopsis

Tests the attachment of a DS1302 RTC module

Notes

Code

 1 #include<DS1302.h>
 2 #include <stdio.h>
 3 
 4   const int kCePin  = 5;  // Chip Enable
 5   const int kIoPin   = 6;  // Input/Output
 6   const int kSclkPin = 7;  // Serial Clock
 7   DS1302 rtc(kCePin, kIoPin, kSclkPin);
 8 
 9   void setup() {
10   Serial.begin(9600);
11   delay(1000);
12   rtc.writeProtect(true);
13 
14 }
15 
16 void loop() {
17   byte hr;
18   Time tm = rtc.time();
19   hr=t.hr;
20   while(hr>12) hr -= 12;
21   Serial.print("(");
22   Serial.print(hr);
23   Serial.print(":");
24   Serial.print(t.min);
25   Serial.print(":");
26   Serial.print(t.sec);
27   Serial.println(")");
28   delay(1000);
29 }