Functions from rtc_func are programmed in a class
Fork of rtc_class by
Date.cpp@0:1df9d38ebe29, 2015-04-22 (annotated)
- Committer:
- Cartillius
- Date:
- Wed Apr 22 19:46:49 2015 +0000
- Revision:
- 0:1df9d38ebe29
Functions from rtc_func are programmed in a class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Cartillius | 0:1df9d38ebe29 | 1 | #include "mbed.h" |
Cartillius | 0:1df9d38ebe29 | 2 | #include "const.h" |
Cartillius | 0:1df9d38ebe29 | 3 | #include "Date.h" |
Cartillius | 0:1df9d38ebe29 | 4 | |
Cartillius | 0:1df9d38ebe29 | 5 | uint8_t Date::bcdToUint(uint8_t const nybbles) |
Cartillius | 0:1df9d38ebe29 | 6 | { |
Cartillius | 0:1df9d38ebe29 | 7 | uint8_t result; |
Cartillius | 0:1df9d38ebe29 | 8 | result = (nybbles>>4)*10 + (nybbles & 0x0F); |
Cartillius | 0:1df9d38ebe29 | 9 | return result; |
Cartillius | 0:1df9d38ebe29 | 10 | } |
Cartillius | 0:1df9d38ebe29 | 11 | uint8_t Date::GetDay() |
Cartillius | 0:1df9d38ebe29 | 12 | { |
Cartillius | 0:1df9d38ebe29 | 13 | uint8_t day = rtc_read(DAYS); |
Cartillius | 0:1df9d38ebe29 | 14 | return bcdToUint(day & 0x3F); |
Cartillius | 0:1df9d38ebe29 | 15 | } |
Cartillius | 0:1df9d38ebe29 | 16 | uint8_t Date::GetMonth() |
Cartillius | 0:1df9d38ebe29 | 17 | { |
Cartillius | 0:1df9d38ebe29 | 18 | uint8_t month = rtc_read(MONTHS); |
Cartillius | 0:1df9d38ebe29 | 19 | return bcdToUint(month & 0x1F); |
Cartillius | 0:1df9d38ebe29 | 20 | } |
Cartillius | 0:1df9d38ebe29 | 21 | uint8_t Date::GetYear() |
Cartillius | 0:1df9d38ebe29 | 22 | { |
Cartillius | 0:1df9d38ebe29 | 23 | uint8_t year = rtc_read(YEARS); |
Cartillius | 0:1df9d38ebe29 | 24 | return bcdToUint(year & 0x3F); |
Cartillius | 0:1df9d38ebe29 | 25 | } |
Cartillius | 0:1df9d38ebe29 | 26 | uint8_t Date::GetSecond() |
Cartillius | 0:1df9d38ebe29 | 27 | { |
Cartillius | 0:1df9d38ebe29 | 28 | uint8_t second = rtc_read(SECONDS); |
Cartillius | 0:1df9d38ebe29 | 29 | return bcdToUint(second & 0x7F); |
Cartillius | 0:1df9d38ebe29 | 30 | } |
Cartillius | 0:1df9d38ebe29 | 31 | uint8_t Date::GetMinute() |
Cartillius | 0:1df9d38ebe29 | 32 | { |
Cartillius | 0:1df9d38ebe29 | 33 | uint8_t minute = rtc_read(MINUTES); |
Cartillius | 0:1df9d38ebe29 | 34 | return bcdToUint(minute & 0x7F); |
Cartillius | 0:1df9d38ebe29 | 35 | } |
Cartillius | 0:1df9d38ebe29 | 36 | uint8_t Date::GetHour() |
Cartillius | 0:1df9d38ebe29 | 37 | { |
Cartillius | 0:1df9d38ebe29 | 38 | uint8_t hour = rtc_read(HOURS); |
Cartillius | 0:1df9d38ebe29 | 39 | return bcdToUint(hour & 0x3F); |
Cartillius | 0:1df9d38ebe29 | 40 | } |
Cartillius | 0:1df9d38ebe29 | 41 | uint8_t Date::GetWeek() |
Cartillius | 0:1df9d38ebe29 | 42 | { |
Cartillius | 0:1df9d38ebe29 | 43 | uint8_t week = rtc_read(WEEKDAYS); |
Cartillius | 0:1df9d38ebe29 | 44 | return bcdToUint(week & 0x07); |
Cartillius | 0:1df9d38ebe29 | 45 | } |