Josef Kager / Mbed 2 deprecated rtc_class2

Dependencies:   mbed

Fork of rtc_class by Josef Kager

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Date.cpp Source File

Date.cpp

00001 #include "mbed.h"
00002 #include "const.h"
00003 #include "Date.h"
00004     
00005     
00006 uint8_t bcdToUint(uint8_t const nybbles)
00007 {
00008     uint8_t result;
00009     result = (nybbles >>4)*10 + (nybbles & 0x0F);
00010     return result;
00011 } 
00012 
00013 uint8_t Date::GetDay()
00014 {
00015     uint8_t day = rtc_read(DAYS);
00016     return bcdToUint(day & 0x3F);
00017 }
00018 uint8_t Date::GetMonth()
00019 {
00020     uint8_t month = rtc_read(MONTHS);
00021     return bcdToUint(month & 0x07F);
00022 }
00023 uint8_t Date::GetYear()
00024 {
00025     uint8_t year = rtc_read(YEARS);
00026     return bcdToUint(year & 0x3F);
00027 }
00028 uint8_t Date::GetWeek()
00029 {
00030     uint8_t week = rtc_read(WEEKDAYS);
00031     return bcdToUint(week & 0x07);       
00032 }