real time clock...Marcel Reath

Dependencies:   RTC8563 mbed

Fork of rtc_func by HIMBED_3AHELI

Revision:
4:f3adf7e6dd40
diff -r f75062350241 -r f3adf7e6dd40 Date.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Date.cpp	Wed Apr 22 18:10:10 2015 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+#include "Date.h"
+ 
+// http://developer.mbed.org/teams/HIMBED_3AHELI/code/rtc_func/wiki/Homepage
+uint8_t Date::bcdToUint(uint8_t const nybbles)
+{
+    uint8_t result;
+    result = (nybbles>>4)*10 + (nybbles & 0x0F);
+    return result;
+}
+ 
+string Date::toString(uint8_t value)
+{
+    //return std::to_string(value); // ab C++ version 11
+    char buffer[2];
+    sprintf (buffer, "%d", value);  // ToString()
+    return buffer;
+}    
+ 
+uint8_t Date::GetDay()
+{
+    uint8_t day = rtc_read(DAYS);
+    return bcdToUint(day & 0x3F);
+}
+
+uint8_t Date::GetMonth()
+{
+    uint8_t month = rtc_read(MONTHS);
+    return bcdToUint(month & 0x1F);
+}
+uint8_t Date::GetYear()
+{
+    uint8_t year = rtc_read(YEARS);
+    return bcdToUint(year & 0xFF);
+}
\ No newline at end of file