Simple RTC class based on DS1307. Emphasis on simple. Allows you to run at 100k or 400k Hz (for newer DS1307 capable devices). MapTime() allows you to set the time() service to the same as the RTC. Uses struct tm throughout so you can use traditional time functions for manipulation.

Dependents:   AdaFruit_RGBLCD

Revision:
1:8952befe5d36
Parent:
0:98b84d9c8c96
Child:
2:3dc63e48cb5d
--- a/RTclock.cpp	Sat Aug 09 09:18:38 2014 +0000
+++ b/RTclock.cpp	Sat Aug 09 09:27:40 2014 +0000
@@ -49,7 +49,8 @@
     out_sTM.tm_wday = aBuffer[3]; 
     out_sTM.tm_mday = BcdToDecimal(aBuffer[4]);
     out_sTM.tm_mon  = BcdToDecimal(aBuffer[5]);
-    out_sTM.tm_year = BcdToDecimal(aBuffer[6]) + 2000;   //  plus hundred (RTC returns years since 2000) but std c is from 1900
+    out_sTM.tm_year = (BcdToDecimal(aBuffer[6]) + 2000) - 1900;   //  Returns from 2000, need form 1900 for time function
+    out_sTM.tm_isdst = 0;
     
     return true;
 }
@@ -59,16 +60,6 @@
     return m_aWeekDays[in_nWeekDay];
 }
 
-bool RTclock::read(int in_nAddress, char * out_pBuffer, int in_nLength)
-{
-    char aBuffer[2] = { (char)in_nAddress, 0 };
-    
-    if (0 != RTclock_parent::write(0xd0, aBuffer, 1)) return false;
-    if (0 != RTclock_parent::read(0xd0, out_pBuffer, in_nLength)) return false;
-    
-    return true;
-}
-
 bool RTclock::MapTime()
 {
     tm sTM;
@@ -81,6 +72,16 @@
     return true;
 }
 
+bool RTclock::read(int in_nAddress, char * out_pBuffer, int in_nLength)
+{
+    char aBuffer[2] = { (char)in_nAddress, 0 };
+    
+    if (0 != RTclock_parent::write(0xd0, aBuffer, 1)) return false;
+    if (0 != RTclock_parent::read(0xd0, out_pBuffer, in_nLength)) return false;
+    
+    return true;
+}
+
 bool RTclock::SetTime(const tm  & in_sTM)
 {
     char aBuffer[7];