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.
Dependents: Hotboards_rtcc_manual_timedate Hotboards_rtcc_timeSpan Hotboards_rtcc_alarm Hotboards_rtcc_compiler_timedate ... more
Hotboards_rtcc.h@1:0790bcaf8b8f, 2016-02-09 (annotated)
- Committer:
- Hotboards
- Date:
- Tue Feb 09 19:28:24 2016 +0000
- Revision:
- 1:0790bcaf8b8f
- Parent:
- 0:3a2ad459941a
corrected a trouble with the device adress:; ; #define RTC_ADDR (uint8_t)(0xDE >> 1); #define EEPROM_ADDR (uint8_t)(0xAE >> 1); ; ;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Hotboards | 0:3a2ad459941a | 1 | /* |
| Hotboards | 0:3a2ad459941a | 2 | Hotboards_rtcc.cpp - Library to read, write and control the real time clock MCP7941x included in rtc board. |
| Hotboards | 0:3a2ad459941a | 3 | http://hotboards.org |
| Hotboards | 0:3a2ad459941a | 4 | adapted and Taken from https://github.com/adafruit/RTClib |
| Hotboards | 0:3a2ad459941a | 5 | Released into the public domain. |
| Hotboards | 0:3a2ad459941a | 6 | */ |
| Hotboards | 0:3a2ad459941a | 7 | |
| Hotboards | 0:3a2ad459941a | 8 | #ifndef Hotboards_rtcc_h |
| Hotboards | 0:3a2ad459941a | 9 | #define Hotboards_rtcc_h |
| Hotboards | 0:3a2ad459941a | 10 | |
| Hotboards | 0:3a2ad459941a | 11 | #include "mbed.h" |
| Hotboards | 0:3a2ad459941a | 12 | |
| Hotboards | 0:3a2ad459941a | 13 | class TimeSpan; |
| Hotboards | 0:3a2ad459941a | 14 | |
| Hotboards | 0:3a2ad459941a | 15 | class DateTime |
| Hotboards | 0:3a2ad459941a | 16 | { |
| Hotboards | 0:3a2ad459941a | 17 | public: |
| Hotboards | 0:3a2ad459941a | 18 | DateTime( uint32_t t = 0 ); |
| Hotboards | 0:3a2ad459941a | 19 | DateTime( uint16_t year, uint8_t month, uint8_t day, |
| Hotboards | 0:3a2ad459941a | 20 | uint8_t hour = 0, uint8_t min = 0, uint8_t sec = 0, uint8_t dweek = 0 ); |
| Hotboards | 0:3a2ad459941a | 21 | DateTime( const DateTime& copy ); |
| Hotboards | 0:3a2ad459941a | 22 | DateTime( const char* date, const char* time ); |
| Hotboards | 0:3a2ad459941a | 23 | uint16_t year() const { return 2000 + yOff; } |
| Hotboards | 0:3a2ad459941a | 24 | uint8_t month() const { return m; } |
| Hotboards | 0:3a2ad459941a | 25 | uint8_t day() const { return d; } |
| Hotboards | 0:3a2ad459941a | 26 | uint8_t hour() const { return hh; } |
| Hotboards | 0:3a2ad459941a | 27 | uint8_t minute() const { return mm; } |
| Hotboards | 0:3a2ad459941a | 28 | uint8_t second() const { return ss; } |
| Hotboards | 0:3a2ad459941a | 29 | uint8_t dweek( void ) const { return ss; } |
| Hotboards | 0:3a2ad459941a | 30 | uint8_t dayOfTheWeek( void ) const; |
| Hotboards | 0:3a2ad459941a | 31 | // 32-bit times as seconds since 1/1/2000 |
| Hotboards | 0:3a2ad459941a | 32 | uint32_t secondstime( void ) const; |
| Hotboards | 0:3a2ad459941a | 33 | // 32-bit times as seconds since 1/1/1970 |
| Hotboards | 0:3a2ad459941a | 34 | uint32_t unixtime( void ) const; |
| Hotboards | 0:3a2ad459941a | 35 | DateTime operator+(const TimeSpan& span); |
| Hotboards | 0:3a2ad459941a | 36 | DateTime operator-(const TimeSpan& span); |
| Hotboards | 0:3a2ad459941a | 37 | TimeSpan operator-(const DateTime& right); |
| Hotboards | 0:3a2ad459941a | 38 | |
| Hotboards | 0:3a2ad459941a | 39 | |
| Hotboards | 0:3a2ad459941a | 40 | protected: |
| Hotboards | 0:3a2ad459941a | 41 | uint8_t yOff, m, d, dw, hh, mm, ss; |
| Hotboards | 0:3a2ad459941a | 42 | }; |
| Hotboards | 0:3a2ad459941a | 43 | |
| Hotboards | 0:3a2ad459941a | 44 | // Timespan which can represent changes in time with seconds accuracy. |
| Hotboards | 0:3a2ad459941a | 45 | class TimeSpan |
| Hotboards | 0:3a2ad459941a | 46 | { |
| Hotboards | 0:3a2ad459941a | 47 | public: |
| Hotboards | 0:3a2ad459941a | 48 | TimeSpan (int32_t seconds = 0); |
| Hotboards | 0:3a2ad459941a | 49 | TimeSpan (int16_t days, int8_t hours, int8_t minutes, int8_t seconds); |
| Hotboards | 0:3a2ad459941a | 50 | TimeSpan (const TimeSpan& copy); |
| Hotboards | 0:3a2ad459941a | 51 | int16_t days() const { return _seconds / 86400L; } |
| Hotboards | 0:3a2ad459941a | 52 | int8_t hours() const { return _seconds / 3600 % 24; } |
| Hotboards | 0:3a2ad459941a | 53 | int8_t minutes() const { return _seconds / 60 % 60; } |
| Hotboards | 0:3a2ad459941a | 54 | int8_t seconds() const { return _seconds % 60; } |
| Hotboards | 0:3a2ad459941a | 55 | int32_t totalseconds() const { return _seconds; } |
| Hotboards | 0:3a2ad459941a | 56 | |
| Hotboards | 0:3a2ad459941a | 57 | TimeSpan operator+(const TimeSpan& right); |
| Hotboards | 0:3a2ad459941a | 58 | TimeSpan operator-(const TimeSpan& right); |
| Hotboards | 0:3a2ad459941a | 59 | |
| Hotboards | 0:3a2ad459941a | 60 | protected: |
| Hotboards | 0:3a2ad459941a | 61 | int32_t _seconds; |
| Hotboards | 0:3a2ad459941a | 62 | }; |
| Hotboards | 0:3a2ad459941a | 63 | |
| Hotboards | 0:3a2ad459941a | 64 | class Hotboards_rtcc |
| Hotboards | 0:3a2ad459941a | 65 | { |
| Hotboards | 0:3a2ad459941a | 66 | public: |
| Hotboards | 0:3a2ad459941a | 67 | Hotboards_rtcc( I2C &i2c ); |
| Hotboards | 0:3a2ad459941a | 68 | void begin( void ); |
| Hotboards | 0:3a2ad459941a | 69 | void adjust( const DateTime &dt ); |
| Hotboards | 0:3a2ad459941a | 70 | DateTime now( void ); |
| Hotboards | 0:3a2ad459941a | 71 | uint8_t isrunning( void ); |
| Hotboards | 0:3a2ad459941a | 72 | void setVBAT( uint8_t OnOff ); |
| Hotboards | 0:3a2ad459941a | 73 | void setAlarm( const DateTime &dt, uint8_t alarm = 0 ); |
| Hotboards | 0:3a2ad459941a | 74 | uint8_t getAlarmStatus( uint8_t alarm = 0 ); |
| Hotboards | 0:3a2ad459941a | 75 | void clearAlarm( uint8_t alarm = 0 ); |
| Hotboards | 0:3a2ad459941a | 76 | void turnOnAlarm( uint8_t alarm = 0 ); |
| Hotboards | 0:3a2ad459941a | 77 | void turnOffAlarm( uint8_t alarm = 0 ); |
| Hotboards | 0:3a2ad459941a | 78 | |
| Hotboards | 0:3a2ad459941a | 79 | protected: |
| Hotboards | 0:3a2ad459941a | 80 | I2C _i2c; |
| Hotboards | 0:3a2ad459941a | 81 | uint8_t on_off; |
| Hotboards | 0:3a2ad459941a | 82 | |
| Hotboards | 0:3a2ad459941a | 83 | void stop( void ); |
| Hotboards | 0:3a2ad459941a | 84 | uint8_t readReg( uint8_t address ); |
| Hotboards | 0:3a2ad459941a | 85 | void writeReg( uint8_t address, uint8_t val ); |
| Hotboards | 0:3a2ad459941a | 86 | uint8_t bcd2bin( uint8_t val ); |
| Hotboards | 0:3a2ad459941a | 87 | uint8_t bin2bcd( uint8_t val ); |
| Hotboards | 0:3a2ad459941a | 88 | |
| Hotboards | 0:3a2ad459941a | 89 | }; |
| Hotboards | 0:3a2ad459941a | 90 | |
| Hotboards | 0:3a2ad459941a | 91 | |
| Hotboards | 0:3a2ad459941a | 92 | #endif |
| Hotboards | 0:3a2ad459941a | 93 |
Hotboards RTCC