.

Dependencies:   mbed

Fork of rtc_func by HIMBED_3AHELI

Files at this revision

API Documentation at this revision

Comitter:
Deixi
Date:
Wed Apr 22 19:31:07 2015 +0000
Parent:
3:f75062350241
Commit message:
..; ;

Changed in this revision

Date.cpp Show annotated file Show diff for this revision Revisions of this file
Date.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Date.cpp	Wed Apr 22 19:31:07 2015 +0000
@@ -0,0 +1,54 @@
+#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) + (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::GetSecond()
+{
+    uint8_t second = rtc_read(SECONDS);
+    return bcdToUint(second & 0x3F);
+}
+
+uint8_t Date::GetMinute()
+{
+    uint8_t minute = rtc_read(MINUTES);
+    return bcdToUint(minute & 0x3F);
+}
+
+uint8_t Date::GetHour()
+{
+    uint8_t hour = rtc_read(HOURS);
+    return bcdToUint(hour & 0x2F);
+}
+
+uint8_t Date::GetDay()
+{
+    uint8_t day = rtc_read(DAYS);
+    return bcdToUint(day & 0x2F);
+}
+
+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 & 0x4F);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Date.h	Wed Apr 22 19:31:07 2015 +0000
@@ -0,0 +1,24 @@
+#include "mbed.h"
+#include "const.h"
+#include "RTC8563.h"
+#include "string"
+ 
+#ifndef DATE_H
+#define DATE_H
+class Date : public RTC8563 // Date abgeleitet von RTC8563
+{
+private:
+    uint8_t bcdToUint(uint8_t const nybbles);   // private Methode
+    string toString(uint8_t value);
+ 
+public:
+    Date()  // Standard Konstruktor
+    {}   
+    uint8_t GetDay();   // Methode
+    uint8_t GetMonth();
+    uint8_t GetYear();
+    uint8_t GetMinute();
+    uint8_t GetHour();
+    uint8_t GetSecond();
+};
+#endif
\ No newline at end of file
--- a/main.cpp	Thu Apr 16 10:25:33 2015 +0000
+++ b/main.cpp	Wed Apr 22 19:31:07 2015 +0000
@@ -5,50 +5,28 @@
 description:
     Real Time Clock (RTC8563) 
     on HIMBED M0 - LPC11U24 
-    prints formatted time and date values to serial port
-    programed by Franz Wolf (wf@bulme.at) 
+    class Date inherited from class RTC8563
+    Example methode GetDay implemented 
+ToDo: 
+    implement year, month;
 ***********************************/
 #include "mbed.h"
 #include "const.h"
 #include "RTC8563.h"
 #include "string"
+#include "Date.h"
  
 Serial pc(USBTX, USBRX);
-//I2C i2c(p28, p27);
  
-uint8_t year, month, day, week;
-uint8_t hour, minute, sec;
-char week_chr[7][4] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
+uint8_t year, month, day;
  
 int main()
 {
-    RTC8563 rtc;  // instanziieren des Objektes rtc
- 
-    pc.printf("Setting up RTC\n");
-    //rtc.rtc_init();
+    Date rtc;  // instanziieren des Objektes rtc
  
     while(1) {
-        //printTime();           
-        year = rtc.rtc_read(YEARS);   // Aufruf der Methode rtc_read der Instanz (Objekt) rtc
-        month = rtc.rtc_read(MONTHS);
-        day = rtc.rtc_read(DAYS);
-        week = rtc.rtc_read(WEEKDAYS);
-        hour = rtc.rtc_read(HOURS);
-        minute = rtc.rtc_read(MINUTES);
-        sec = rtc.rtc_read(SECONDS);
- 
-        //Datum Ausgabe
-        pc.printf("20%x%x/%x%x/%x%x %s\n",
-                  ((year >> 4) & 0x03) , (year & 0x0F) ,
-                  ((month >> 4) & 0x01), (month & 0x0F) ,
-                  ((day >> 4) & 0x03), (day & 0x0F) ,
-                  week_chr[week & 0x07]);
- 
-        //Zeit Ausgabe
-        pc.printf("%x%x:%x%x:%x%x\n",
-                  ((hour >> 4) & 0x03), (hour & 0x0F),
-                  (minute >> 4), (minute & 0x0F) ,
-                  (sec >> 4), (sec & 0x0F) );
+        pc.printf("%x.%x.20%x\n", rtc.GetDay(), rtc.GetMonth(), rtc.GetYear());
+        pc.printf("%x:%x:%x\n", rtc.GetHour(), rtc.GetMinute(), rtc.GetSecond());
         wait(1);
     }
 }
\ No newline at end of file