![](/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:
RTC8563.cpp@2:f75062350241, 2015-04-16 (annotated)
- Committer:
- bulmecisco
- Date:
- Thu Apr 16 10:25:33 2015 +0000
- Revision:
- 2:f75062350241
rtc functions in class RTC8563 transferred
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bulmecisco | 2:f75062350241 | 1 | // |
bulmecisco | 2:f75062350241 | 2 | // @ Project : RTC Date Time Clock |
bulmecisco | 2:f75062350241 | 3 | // @ File Name : RTC8563.cpp |
bulmecisco | 2:f75062350241 | 4 | // @ Date : 06.04.2015 |
bulmecisco | 2:f75062350241 | 5 | // @ Author : Franz Pucher |
bulmecisco | 2:f75062350241 | 6 | // @ Copyright : pe@bulme.at |
bulmecisco | 2:f75062350241 | 7 | // |
bulmecisco | 2:f75062350241 | 8 | |
bulmecisco | 2:f75062350241 | 9 | #include "mbed.h" |
bulmecisco | 2:f75062350241 | 10 | #include "const.h" |
bulmecisco | 2:f75062350241 | 11 | |
bulmecisco | 2:f75062350241 | 12 | #include "RTC8563.h" |
bulmecisco | 2:f75062350241 | 13 | |
bulmecisco | 2:f75062350241 | 14 | RTC8563::RTC8563() : i2c(p28, p27) // delete void and add call to base constructor |
bulmecisco | 2:f75062350241 | 15 | { |
bulmecisco | 2:f75062350241 | 16 | // Initialise I2C |
bulmecisco | 2:f75062350241 | 17 | i2c.frequency(40000); |
bulmecisco | 2:f75062350241 | 18 | char init1[2] = {0x6, 0x00}; |
bulmecisco | 2:f75062350241 | 19 | char init2[2] = {0x7, 0xff}; |
bulmecisco | 2:f75062350241 | 20 | i2c.write(0x40, init1, 2); |
bulmecisco | 2:f75062350241 | 21 | i2c.write(0x40, init2, 2); |
bulmecisco | 2:f75062350241 | 22 | } |
bulmecisco | 2:f75062350241 | 23 | |
bulmecisco | 2:f75062350241 | 24 | RTC8563::RTC8563(PinName sda, PinName scl) : i2c(sda, scl) |
bulmecisco | 2:f75062350241 | 25 | { |
bulmecisco | 2:f75062350241 | 26 | // Initialise I2C |
bulmecisco | 2:f75062350241 | 27 | i2c.frequency(40000); |
bulmecisco | 2:f75062350241 | 28 | char init1[2] = {0x6, 0x00}; |
bulmecisco | 2:f75062350241 | 29 | char init2[2] = {0x7, 0xff}; |
bulmecisco | 2:f75062350241 | 30 | i2c.write(0x40, init1, 2); |
bulmecisco | 2:f75062350241 | 31 | i2c.write(0x40, init2, 2); |
bulmecisco | 2:f75062350241 | 32 | } |
bulmecisco | 2:f75062350241 | 33 | |
bulmecisco | 2:f75062350241 | 34 | char RTC8563::rtc_read(char address) |
bulmecisco | 2:f75062350241 | 35 | { |
bulmecisco | 2:f75062350241 | 36 | char value; |
bulmecisco | 2:f75062350241 | 37 | i2c.start(); |
bulmecisco | 2:f75062350241 | 38 | i2c.write(RTC8563_ADR); |
bulmecisco | 2:f75062350241 | 39 | i2c.write(address); |
bulmecisco | 2:f75062350241 | 40 | i2c.start(); |
bulmecisco | 2:f75062350241 | 41 | i2c.write(RTC8563_ADR | _READ); |
bulmecisco | 2:f75062350241 | 42 | value = i2c.read(0); |
bulmecisco | 2:f75062350241 | 43 | i2c.stop(); |
bulmecisco | 2:f75062350241 | 44 | |
bulmecisco | 2:f75062350241 | 45 | return value; |
bulmecisco | 2:f75062350241 | 46 | } |
bulmecisco | 2:f75062350241 | 47 | |
bulmecisco | 2:f75062350241 | 48 | void RTC8563::rtc_write(char address, char value) |
bulmecisco | 2:f75062350241 | 49 | { |
bulmecisco | 2:f75062350241 | 50 | i2c.start(); |
bulmecisco | 2:f75062350241 | 51 | i2c.write(RTC8563_ADR); |
bulmecisco | 2:f75062350241 | 52 | i2c.write(address); |
bulmecisco | 2:f75062350241 | 53 | i2c.write(value); |
bulmecisco | 2:f75062350241 | 54 | i2c.stop(); |
bulmecisco | 2:f75062350241 | 55 | } |
bulmecisco | 2:f75062350241 | 56 | |
bulmecisco | 2:f75062350241 | 57 | void RTC8563::rtc_init() |
bulmecisco | 2:f75062350241 | 58 | { |
bulmecisco | 2:f75062350241 | 59 | } |
bulmecisco | 2:f75062350241 | 60 | |
bulmecisco | 2:f75062350241 | 61 | void RTC8563::rtc_alarm() |
bulmecisco | 2:f75062350241 | 62 | { |
bulmecisco | 2:f75062350241 | 63 | } |