RTC8564.cpp@0:ed1f619f1794, 2012-06-20 (annotated)
- Committer:
- misodengaku
- Date:
- Wed Jun 20 04:09:39 2012 +0000
- Revision:
- 0:ed1f619f1794
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
misodengaku | 0:ed1f619f1794 | 1 | #include "mbed.h" |
misodengaku | 0:ed1f619f1794 | 2 | #include "RTC8564.h" |
misodengaku | 0:ed1f619f1794 | 3 | |
misodengaku | 0:ed1f619f1794 | 4 | void RTC8564::write(char address, char value) |
misodengaku | 0:ed1f619f1794 | 5 | { |
misodengaku | 0:ed1f619f1794 | 6 | i2c.start(); |
misodengaku | 0:ed1f619f1794 | 7 | i2c.write(RTC8564NB_ADR); |
misodengaku | 0:ed1f619f1794 | 8 | i2c.write(address); |
misodengaku | 0:ed1f619f1794 | 9 | i2c.write(value); |
misodengaku | 0:ed1f619f1794 | 10 | i2c.stop(); |
misodengaku | 0:ed1f619f1794 | 11 | } |
misodengaku | 0:ed1f619f1794 | 12 | |
misodengaku | 0:ed1f619f1794 | 13 | char RTC8564::read(char address) |
misodengaku | 0:ed1f619f1794 | 14 | { |
misodengaku | 0:ed1f619f1794 | 15 | char value; |
misodengaku | 0:ed1f619f1794 | 16 | i2c.start(); |
misodengaku | 0:ed1f619f1794 | 17 | i2c.write(RTC8564NB_ADR); |
misodengaku | 0:ed1f619f1794 | 18 | i2c.write(address); |
misodengaku | 0:ed1f619f1794 | 19 | i2c.start(); |
misodengaku | 0:ed1f619f1794 | 20 | i2c.write(RTC8564NB_ADR | _READ); |
misodengaku | 0:ed1f619f1794 | 21 | value = i2c.read(0); |
misodengaku | 0:ed1f619f1794 | 22 | i2c.stop(); |
misodengaku | 0:ed1f619f1794 | 23 | |
misodengaku | 0:ed1f619f1794 | 24 | return value; |
misodengaku | 0:ed1f619f1794 | 25 | } |
misodengaku | 0:ed1f619f1794 | 26 | |
misodengaku | 0:ed1f619f1794 | 27 | void RTC8564::time_just() |
misodengaku | 0:ed1f619f1794 | 28 | { |
misodengaku | 0:ed1f619f1794 | 29 | char _min, _hour; |
misodengaku | 0:ed1f619f1794 | 30 | _min = read(MINUTES); |
misodengaku | 0:ed1f619f1794 | 31 | if (_min >= 0x30) { |
misodengaku | 0:ed1f619f1794 | 32 | _hour = read(HOURS); |
misodengaku | 0:ed1f619f1794 | 33 | if (_hour == 0x23) |
misodengaku | 0:ed1f619f1794 | 34 | _hour = 0x00; |
misodengaku | 0:ed1f619f1794 | 35 | else if ((_hour & 0x0F) == 0x09) |
misodengaku | 0:ed1f619f1794 | 36 | _hour = (_hour & 0xF0) + 0x10; |
misodengaku | 0:ed1f619f1794 | 37 | else |
misodengaku | 0:ed1f619f1794 | 38 | _hour = _hour + 0x01; |
misodengaku | 0:ed1f619f1794 | 39 | write(HOURS, _hour); |
misodengaku | 0:ed1f619f1794 | 40 | } |
misodengaku | 0:ed1f619f1794 | 41 | write(MINUTES, 0x00); |
misodengaku | 0:ed1f619f1794 | 42 | write(SECONDS, 0x00); |
misodengaku | 0:ed1f619f1794 | 43 | } |
misodengaku | 0:ed1f619f1794 | 44 | |
misodengaku | 0:ed1f619f1794 | 45 | |
misodengaku | 0:ed1f619f1794 | 46 | void RTC8564::setdaytime(char y[3], char m[3], char d[3], char h[3], char min[3], char s[3], char week_val[2]) |
misodengaku | 0:ed1f619f1794 | 47 | { |
misodengaku | 0:ed1f619f1794 | 48 | write(CONTROL1, 0x20); //stop |
misodengaku | 0:ed1f619f1794 | 49 | write(CONTROL2, 0x00); |
misodengaku | 0:ed1f619f1794 | 50 | write(YEARS, ((y[0]-0x30)<<4)+(y[1]-0x30)); |
misodengaku | 0:ed1f619f1794 | 51 | write(MONTHS, ((m[0]-0x30)<<4)+(m[1]-0x30)); |
misodengaku | 0:ed1f619f1794 | 52 | write(DAYS, ((d[0]-0x30)<<4)+(d[1]-0x30)); |
misodengaku | 0:ed1f619f1794 | 53 | write(HOURS, ((h[0]-0x30)<<4)+(h[1]-0x30)); |
misodengaku | 0:ed1f619f1794 | 54 | write(MINUTES, ((min[0]-0x30)<<4)+(min[1]-0x30)); |
misodengaku | 0:ed1f619f1794 | 55 | write(SECONDS, ((s[0]-0x30)<<4)+(s[1]-0x30)); |
misodengaku | 0:ed1f619f1794 | 56 | write(WEEKDAYS, week_val[0] - 0x30); //Sunday = "0", Monday = "1" ... |
misodengaku | 0:ed1f619f1794 | 57 | write(CLOCKOUT_FREQ, 0x00); // 0x83 = TE on & 1Hz |
misodengaku | 0:ed1f619f1794 | 58 | write(TIMER_CONTROL, 0x00); |
misodengaku | 0:ed1f619f1794 | 59 | write(CONTROL1, 0x00); //start |
misodengaku | 0:ed1f619f1794 | 60 | return; |
misodengaku | 0:ed1f619f1794 | 61 | } |