Functions and formatted printing of time and date for RTC8563
Dependencies: mbed
I2C RTC on HIMBED
Definition der benannten Konstanten für die Register des PCF8563 (Tabelle 4)
Praeprozessor-Direktiven #define werden durch benannte Konstante ersetzt
const.h
/*********************************** name: const.h Version: 0.1 author: PE HTL BULME email: pe@bulme.at description: Named constants definitions for registers PCF8563 RTC on HIMBED M0 - LPC11U24 ***********************************/ #ifndef CONST_H #define CONST_H // Address of RTC const int RTC8563_ADR = 0xA2; // Control and status const int CONTROL1 = 0x00; const int CONTROL2 = 0x01; // Time and date const int SECONDS = 0x02; const int MINUTES = 0x03; const int HOURS = 0x04; const int DAYS = 0x05; const int WEEKDAYS = 0x06; const int MONTHS = 0x07; const int YEARS = 0x08; // Alarm const int MINUTE_ALARM = 0x09; const int HOUR_ALARM = 0x0A; const int DAY_ALARM = 0x0B; const int WEEKDAY_ALARM = 0x0C; // Clock and timer const int CLOCKOUT_FREQ = 0x0D; const int TIMER_CINTROL = 0x0E; const int _READ = 0x01; #endif
Register organisation
Terminal program
Mit einem Terminal Programm (z.B. HTERM) können die Werte von der seriellen Schnittstelle (COM-Port) angezeigt werden:
main.cpp@2:f75062350241, 2015-04-16 (annotated)
- Committer:
- bulmecisco
- Date:
- Thu Apr 16 10:25:33 2015 +0000
- Revision:
- 2:f75062350241
- Parent:
- 1:554eb6675279
rtc functions in class RTC8563 transferred
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bulmecisco | 0:32ae5fd83722 | 1 | /*********************************** |
bulmecisco | 0:32ae5fd83722 | 2 | name: main.cpp Version: 0.1 |
bulmecisco | 0:32ae5fd83722 | 3 | author: PE HTL BULME |
bulmecisco | 0:32ae5fd83722 | 4 | email: pe@bulme.at |
bulmecisco | 0:32ae5fd83722 | 5 | description: |
bulmecisco | 0:32ae5fd83722 | 6 | Real Time Clock (RTC8563) |
bulmecisco | 0:32ae5fd83722 | 7 | on HIMBED M0 - LPC11U24 |
bulmecisco | 0:32ae5fd83722 | 8 | prints formatted time and date values to serial port |
bulmecisco | 0:32ae5fd83722 | 9 | programed by Franz Wolf (wf@bulme.at) |
bulmecisco | 0:32ae5fd83722 | 10 | ***********************************/ |
bulmecisco | 0:32ae5fd83722 | 11 | #include "mbed.h" |
bulmecisco | 2:f75062350241 | 12 | #include "const.h" |
bulmecisco | 2:f75062350241 | 13 | #include "RTC8563.h" |
bulmecisco | 2:f75062350241 | 14 | #include "string" |
bulmecisco | 2:f75062350241 | 15 | |
bulmecisco | 0:32ae5fd83722 | 16 | Serial pc(USBTX, USBRX); |
bulmecisco | 2:f75062350241 | 17 | //I2C i2c(p28, p27); |
bulmecisco | 2:f75062350241 | 18 | |
bulmecisco | 2:f75062350241 | 19 | uint8_t year, month, day, week; |
bulmecisco | 2:f75062350241 | 20 | uint8_t hour, minute, sec; |
bulmecisco | 0:32ae5fd83722 | 21 | char week_chr[7][4] = {"MON","TUE","WED","THU","FRI","SAT","SUN"}; |
bulmecisco | 2:f75062350241 | 22 | |
bulmecisco | 0:32ae5fd83722 | 23 | int main() |
bulmecisco | 0:32ae5fd83722 | 24 | { |
bulmecisco | 2:f75062350241 | 25 | RTC8563 rtc; // instanziieren des Objektes rtc |
bulmecisco | 2:f75062350241 | 26 | |
bulmecisco | 2:f75062350241 | 27 | pc.printf("Setting up RTC\n"); |
bulmecisco | 2:f75062350241 | 28 | //rtc.rtc_init(); |
bulmecisco | 2:f75062350241 | 29 | |
bulmecisco | 0:32ae5fd83722 | 30 | while(1) { |
bulmecisco | 2:f75062350241 | 31 | //printTime(); |
bulmecisco | 2:f75062350241 | 32 | year = rtc.rtc_read(YEARS); // Aufruf der Methode rtc_read der Instanz (Objekt) rtc |
bulmecisco | 2:f75062350241 | 33 | month = rtc.rtc_read(MONTHS); |
bulmecisco | 2:f75062350241 | 34 | day = rtc.rtc_read(DAYS); |
bulmecisco | 2:f75062350241 | 35 | week = rtc.rtc_read(WEEKDAYS); |
bulmecisco | 2:f75062350241 | 36 | hour = rtc.rtc_read(HOURS); |
bulmecisco | 2:f75062350241 | 37 | minute = rtc.rtc_read(MINUTES); |
bulmecisco | 2:f75062350241 | 38 | sec = rtc.rtc_read(SECONDS); |
bulmecisco | 2:f75062350241 | 39 | |
bulmecisco | 2:f75062350241 | 40 | //Datum Ausgabe |
bulmecisco | 2:f75062350241 | 41 | pc.printf("20%x%x/%x%x/%x%x %s\n", |
bulmecisco | 2:f75062350241 | 42 | ((year >> 4) & 0x03) , (year & 0x0F) , |
bulmecisco | 2:f75062350241 | 43 | ((month >> 4) & 0x01), (month & 0x0F) , |
bulmecisco | 2:f75062350241 | 44 | ((day >> 4) & 0x03), (day & 0x0F) , |
bulmecisco | 2:f75062350241 | 45 | week_chr[week & 0x07]); |
bulmecisco | 2:f75062350241 | 46 | |
bulmecisco | 2:f75062350241 | 47 | //Zeit Ausgabe |
bulmecisco | 2:f75062350241 | 48 | pc.printf("%x%x:%x%x:%x%x\n", |
bulmecisco | 2:f75062350241 | 49 | ((hour >> 4) & 0x03), (hour & 0x0F), |
bulmecisco | 2:f75062350241 | 50 | (minute >> 4), (minute & 0x0F) , |
bulmecisco | 2:f75062350241 | 51 | (sec >> 4), (sec & 0x0F) ); |
bulmecisco | 0:32ae5fd83722 | 52 | wait(1); |
bulmecisco | 0:32ae5fd83722 | 53 | } |
bulmecisco | 2:f75062350241 | 54 | } |