![](/media/cache/group/HIMBED0.jpg.50x50_q85.jpg)
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:
Diff: main.cpp
- Revision:
- 1:554eb6675279
- Parent:
- 0:32ae5fd83722
- Child:
- 2:f75062350241
diff -r 32ae5fd83722 -r 554eb6675279 main.cpp --- a/main.cpp Sun Apr 05 09:55:01 2015 +0000 +++ b/main.cpp Wed Apr 15 07:15:25 2015 +0000 @@ -34,6 +34,11 @@ Serial pc(USBTX, USBRX); I2C i2c(p28, p27); +InterruptIn alarm(P1_28); + +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); + // Function prototyping void printTime(); void rtc_init(); @@ -117,10 +122,38 @@ i2c.stop(); } +void rtc_alarm() +{ + pc.printf("Setting up RTC\n"); + // Formatierung + // 2015/01/24 + // 17:02:00 MON + + // week_val = 0x05; // SAT + rtc_write(CONTROL1, 0x20); //stop + rtc_write(CONTROL2, 0x02); // alarm AF alarm flag bit + rtc_write(DAY_ALARM, (0x80) ); + rtc_write(HOUR_ALARM, (0x97)); + rtc_write(MINUTE_ALARM, (0x02)); + rtc_write(WEEKDAY_ALARM, (0x80)); + rtc_write(CONTROL1, 0x00); //start +} +//************************************ +void push1() // Interruptfunktion alarm +{ + pc.printf("********\n" ); + pc.printf("ALARM\n" ); + pc.printf("********\n" ); + myled1= 1; +} + + // main program int main() { rtc_init(); + alarm.fall(&push1); + rtc_alarm(); while(1) { printTime(); wait(1);