rtc class

Dependencies:   RTC8563 mbed

Fork of rtc_class by HIMBED_3AHELI

Committer:
bulmecisco
Date:
Thu Apr 23 09:02:20 2015 +0000
Revision:
5:fc8c66a7c87a
Parent:
4:a4d39c018c65
Child:
6:ebe2350041f1
Update to version 0.2 (private to protected)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bulmecisco 5:fc8c66a7c87a 1 /***********************************
bulmecisco 5:fc8c66a7c87a 2 name: date.cpp Version: 0.2
bulmecisco 5:fc8c66a7c87a 3 author: PE HTL BULME
bulmecisco 5:fc8c66a7c87a 4 email: pe@bulme.at
bulmecisco 5:fc8c66a7c87a 5 description:
bulmecisco 5:fc8c66a7c87a 6 Real Time Clock (RTC8563) on HIMBED M0 - LPC11U24
bulmecisco 5:fc8c66a7c87a 7 class Date inherited from class RTC8563
bulmecisco 5:fc8c66a7c87a 8 Example methode GetDay implemented
bulmecisco 5:fc8c66a7c87a 9 ToDo:
bulmecisco 5:fc8c66a7c87a 10 implement GetYear, GetMonth;
bulmecisco 5:fc8c66a7c87a 11 Constructor to initialize Date on RTC
bulmecisco 5:fc8c66a7c87a 12 Alarm methode
bulmecisco 5:fc8c66a7c87a 13 ***********************************/
bulmecisco 5:fc8c66a7c87a 14
bulmecisco 3:c6081814064d 15 #include "mbed.h"
bulmecisco 3:c6081814064d 16 #include "Date.h"
bulmecisco 3:c6081814064d 17
bulmecisco 5:fc8c66a7c87a 18 // https://developer.mbed.org/teams/HIMBED_3AHELI/code/rtc_func/wiki/Klasse-Date-von-RTC8563-ableiten
bulmecisco 3:c6081814064d 19 uint8_t Date::bcdToUint(uint8_t const nybbles)
bulmecisco 3:c6081814064d 20 {
bulmecisco 3:c6081814064d 21 uint8_t result;
bulmecisco 3:c6081814064d 22 result = (nybbles>>4)*10 + (nybbles & 0x0F);
bulmecisco 3:c6081814064d 23 return result;
bulmecisco 3:c6081814064d 24 }
bulmecisco 3:c6081814064d 25
bulmecisco 4:a4d39c018c65 26 string Date::toString(uint8_t value)
bulmecisco 4:a4d39c018c65 27 {
bulmecisco 4:a4d39c018c65 28 //return std::to_string(value); // ab C++ version 11
bulmecisco 4:a4d39c018c65 29 char buffer[2];
bulmecisco 4:a4d39c018c65 30 sprintf (buffer, "%d", value); // ToString()
bulmecisco 4:a4d39c018c65 31 return buffer;
bulmecisco 4:a4d39c018c65 32 }
bulmecisco 4:a4d39c018c65 33
bulmecisco 3:c6081814064d 34 uint8_t Date::GetDay()
bulmecisco 3:c6081814064d 35 {
bulmecisco 3:c6081814064d 36 uint8_t day = rtc_read(DAYS);
bulmecisco 3:c6081814064d 37 return bcdToUint(day & 0x3F);
bulmecisco 3:c6081814064d 38 }