Josef Kager
/
rtc_class2
added GetDay() GetYear() GetWeek()
Fork of rtc_class by
Date.cpp@3:75f5352b387d, 2015-04-30 (annotated)
- Committer:
- KagerJ
- Date:
- Thu Apr 30 10:53:00 2015 +0000
- Revision:
- 3:75f5352b387d
- Parent:
- 2:ce174a86d215
added GetDay() GetYear() GetWeek()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KagerJ | 2:ce174a86d215 | 1 | #include "mbed.h" |
KagerJ | 2:ce174a86d215 | 2 | #include "const.h" |
KagerJ | 2:ce174a86d215 | 3 | #include "Date.h" |
KagerJ | 2:ce174a86d215 | 4 | |
KagerJ | 2:ce174a86d215 | 5 | |
KagerJ | 2:ce174a86d215 | 6 | uint8_t bcdToUint(uint8_t const nybbles) |
KagerJ | 2:ce174a86d215 | 7 | { |
KagerJ | 2:ce174a86d215 | 8 | uint8_t result; |
KagerJ | 2:ce174a86d215 | 9 | result = (nybbles >>4)*10 + (nybbles & 0x0F); |
KagerJ | 2:ce174a86d215 | 10 | return result; |
KagerJ | 2:ce174a86d215 | 11 | } |
KagerJ | 2:ce174a86d215 | 12 | |
KagerJ | 2:ce174a86d215 | 13 | uint8_t Date::GetDay() |
KagerJ | 2:ce174a86d215 | 14 | { |
KagerJ | 2:ce174a86d215 | 15 | uint8_t day = rtc_read(DAYS); |
KagerJ | 2:ce174a86d215 | 16 | return bcdToUint(day & 0x3F); |
KagerJ | 2:ce174a86d215 | 17 | } |
KagerJ | 2:ce174a86d215 | 18 | uint8_t Date::GetMonth() |
KagerJ | 2:ce174a86d215 | 19 | { |
KagerJ | 2:ce174a86d215 | 20 | uint8_t month = rtc_read(MONTHS); |
KagerJ | 2:ce174a86d215 | 21 | return bcdToUint(month & 0x07F); |
KagerJ | 2:ce174a86d215 | 22 | } |
KagerJ | 2:ce174a86d215 | 23 | uint8_t Date::GetYear() |
KagerJ | 2:ce174a86d215 | 24 | { |
KagerJ | 2:ce174a86d215 | 25 | uint8_t year = rtc_read(YEARS); |
KagerJ | 2:ce174a86d215 | 26 | return bcdToUint(year & 0x3F); |
KagerJ | 2:ce174a86d215 | 27 | } |
KagerJ | 3:75f5352b387d | 28 | uint8_t Date::GetWeek() |
KagerJ | 2:ce174a86d215 | 29 | { |
KagerJ | 2:ce174a86d215 | 30 | uint8_t week = rtc_read(WEEKDAYS); |
KagerJ | 2:ce174a86d215 | 31 | return bcdToUint(week & 0x07); |
KagerJ | 2:ce174a86d215 | 32 | } |