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

Files at this revision

API Documentation at this revision

Comitter:
vtraveller
Date:
Sat Jan 24 15:59:29 2015 +0000
Parent:
16:f7e4b4cbfb9e
Commit message:
Fixed bug where tm struct used a month range of 0-11 and the DS3231 uses a range 1-12.

Changed in this revision

RTclock.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/RTclock.cpp	Thu Oct 09 14:04:25 2014 +0000
+++ b/RTclock.cpp	Sat Jan 24 15:59:29 2015 +0000
@@ -32,6 +32,7 @@
     m_bTwelveHour = ((aBuffer[2] & 0x40) == 0x40);
     
     out_sTM.tm_sec = bcdToDecimal(aBuffer[0] & 0x7f);
+    
     out_sTM.tm_min = bcdToDecimal(aBuffer[1]);
     
     if (m_bTwelveHour)
@@ -47,10 +48,10 @@
     {
         out_sTM.tm_hour = bcdToDecimal(aBuffer[2] & 0x3f);
     }
-    
-    out_sTM.tm_wday = aBuffer[3] % 7;
-    out_sTM.tm_mday = bcdToDecimal(aBuffer[4]);
-    out_sTM.tm_mon  = bcdToDecimal(aBuffer[5]);
+
+    out_sTM.tm_wday = aBuffer[3] % 7;    
+    out_sTM.tm_mday = bcdToDecimal(aBuffer[4]);    
+    out_sTM.tm_mon  = bcdToDecimal(aBuffer[5]) - 1;    
     out_sTM.tm_year = (bcdToDecimal(aBuffer[6]) + 2000) - 1900;   //  Returns from 2000, need form 1900 for time function
     out_sTM.tm_isdst = 0;
     
@@ -104,7 +105,7 @@
             aBuffer[2] = (aBuffer[2] & 0xc4) | (decimalToBcd(nHour) & 0x3f);
             aBuffer[3] = in_sTM.tm_wday;
             aBuffer[4] = decimalToBcd(in_sTM.tm_mday);
-            aBuffer[5] = decimalToBcd(in_sTM.tm_mon);
+            aBuffer[5] = decimalToBcd(in_sTM.tm_mon + 1);
             aBuffer[6] = decimalToBcd(in_sTM.tm_year + 1900 - 2000);
         
             // Handle the 12hr clock bits
@@ -128,7 +129,7 @@
             aBuffer[2] = decimalToBcd(nHour) & (m_bTwelveHour ? 0x1f : 0x3f);
             aBuffer[3] = in_sTM.tm_wday;
             aBuffer[4] = decimalToBcd(in_sTM.tm_mday);
-            aBuffer[5] = decimalToBcd(in_sTM.tm_mon) & ~0x80 /* 2000+ */;
+            aBuffer[5] = decimalToBcd(in_sTM.tm_mon + 1) & ~0x80 /* 2000+ */;
             aBuffer[6] = decimalToBcd(in_sTM.tm_year + 1900 - 2000);
         
             // Handle the 12hr clock bits