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