Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of rtc_class by
Date.cpp@2:ce174a86d215, 2015-04-23 (annotated)
- Committer:
- KagerJ
- Date:
- Thu Apr 23 09:42:34 2015 +0000
- Revision:
- 2:ce174a86d215
- Child:
- 3:75f5352b387d
added GetWeek() GetDays() GetMonths() GetYears()
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 | 2:ce174a86d215 | 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 | } |
