![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
RX8025 sample
Dependencies: AQM0802 RX8025 mbed
See https://developer.mbed.org/users/yasuyuki/notebook/RX8025/
main.cpp@0:fd7275804dc9, 2014-11-08 (annotated)
- Committer:
- yasuyuki
- Date:
- Sat Nov 08 12:21:25 2014 +0000
- Revision:
- 0:fd7275804dc9
release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yasuyuki | 0:fd7275804dc9 | 1 | //********************** |
yasuyuki | 0:fd7275804dc9 | 2 | // Real Time Clock |
yasuyuki | 0:fd7275804dc9 | 3 | // RX8025 sample for mbed |
yasuyuki | 0:fd7275804dc9 | 4 | // |
yasuyuki | 0:fd7275804dc9 | 5 | // Be careful, no parameter check. |
yasuyuki | 0:fd7275804dc9 | 6 | // |
yasuyuki | 0:fd7275804dc9 | 7 | // (C)Copyright 2014 All rights reserved by Y.Onodera |
yasuyuki | 0:fd7275804dc9 | 8 | // http://einstlab.web.fc2.com |
yasuyuki | 0:fd7275804dc9 | 9 | //********************** |
yasuyuki | 0:fd7275804dc9 | 10 | #include "mbed.h" |
yasuyuki | 0:fd7275804dc9 | 11 | #include "AQM0802.h" |
yasuyuki | 0:fd7275804dc9 | 12 | #include "RX8025.h" |
yasuyuki | 0:fd7275804dc9 | 13 | |
yasuyuki | 0:fd7275804dc9 | 14 | #if defined(TARGET_LPC1768) |
yasuyuki | 0:fd7275804dc9 | 15 | I2C i2c(p28,p27); |
yasuyuki | 0:fd7275804dc9 | 16 | #endif |
yasuyuki | 0:fd7275804dc9 | 17 | // for TG-LPC11U35-501 |
yasuyuki | 0:fd7275804dc9 | 18 | #if defined(TARGET_LPC11U35_501) |
yasuyuki | 0:fd7275804dc9 | 19 | I2C i2c(P0_5,P0_4); |
yasuyuki | 0:fd7275804dc9 | 20 | #endif |
yasuyuki | 0:fd7275804dc9 | 21 | // for Nucleo |
yasuyuki | 0:fd7275804dc9 | 22 | #if defined(TARGET_NUCLEO_F401RE) |
yasuyuki | 0:fd7275804dc9 | 23 | I2C i2c(D14,D15); |
yasuyuki | 0:fd7275804dc9 | 24 | #endif |
yasuyuki | 0:fd7275804dc9 | 25 | |
yasuyuki | 0:fd7275804dc9 | 26 | AQM0802 lcd(i2c); |
yasuyuki | 0:fd7275804dc9 | 27 | RX8025 rx8025(i2c); |
yasuyuki | 0:fd7275804dc9 | 28 | |
yasuyuki | 0:fd7275804dc9 | 29 | // 0=Sun...6=Sat |
yasuyuki | 0:fd7275804dc9 | 30 | int zeller(int y, int m, int d){ |
yasuyuki | 0:fd7275804dc9 | 31 | |
yasuyuki | 0:fd7275804dc9 | 32 | int i; |
yasuyuki | 0:fd7275804dc9 | 33 | if(m<3){ |
yasuyuki | 0:fd7275804dc9 | 34 | --y; |
yasuyuki | 0:fd7275804dc9 | 35 | m+=12; |
yasuyuki | 0:fd7275804dc9 | 36 | } |
yasuyuki | 0:fd7275804dc9 | 37 | i = (y + y/4 - y/100 + y/400 + (13*m + 8)/5 + d) % 7; |
yasuyuki | 0:fd7275804dc9 | 38 | return i; |
yasuyuki | 0:fd7275804dc9 | 39 | } |
yasuyuki | 0:fd7275804dc9 | 40 | |
yasuyuki | 0:fd7275804dc9 | 41 | |
yasuyuki | 0:fd7275804dc9 | 42 | int main() { |
yasuyuki | 0:fd7275804dc9 | 43 | |
yasuyuki | 0:fd7275804dc9 | 44 | char msg[10]; |
yasuyuki | 0:fd7275804dc9 | 45 | Times t; |
yasuyuki | 0:fd7275804dc9 | 46 | Control c; |
yasuyuki | 0:fd7275804dc9 | 47 | Alarmw aw; |
yasuyuki | 0:fd7275804dc9 | 48 | Alarmd ad; |
yasuyuki | 0:fd7275804dc9 | 49 | |
yasuyuki | 0:fd7275804dc9 | 50 | // set Control |
yasuyuki | 0:fd7275804dc9 | 51 | c.control1=0x20; // 24hours format |
yasuyuki | 0:fd7275804dc9 | 52 | c.control2=0x00; |
yasuyuki | 0:fd7275804dc9 | 53 | c.offset=0x00; // to adjust offset |
yasuyuki | 0:fd7275804dc9 | 54 | rx8025.setCONTROL(c); |
yasuyuki | 0:fd7275804dc9 | 55 | |
yasuyuki | 0:fd7275804dc9 | 56 | // set Alarm with week, as 08:00 at sat. |
yasuyuki | 0:fd7275804dc9 | 57 | // to enable WAFG=1 in contol2 |
yasuyuki | 0:fd7275804dc9 | 58 | // you will see WALE=1 in control1 and INTB pin=L, when it happens |
yasuyuki | 0:fd7275804dc9 | 59 | // you should clear WALE |
yasuyuki | 0:fd7275804dc9 | 60 | aw.minute=0x00; |
yasuyuki | 0:fd7275804dc9 | 61 | aw.hour=0x08; |
yasuyuki | 0:fd7275804dc9 | 62 | aw.weekday=0x06; |
yasuyuki | 0:fd7275804dc9 | 63 | rx8025.setALARMw(aw); |
yasuyuki | 0:fd7275804dc9 | 64 | |
yasuyuki | 0:fd7275804dc9 | 65 | // set Alarm, as 09:00 |
yasuyuki | 0:fd7275804dc9 | 66 | // to enable DAFG=1 in contol2 |
yasuyuki | 0:fd7275804dc9 | 67 | // you will see DALE=1 in control1 and INTA pin=L, when it happens |
yasuyuki | 0:fd7275804dc9 | 68 | // you should clear DALE |
yasuyuki | 0:fd7275804dc9 | 69 | ad.minute=0x00; |
yasuyuki | 0:fd7275804dc9 | 70 | ad.hour=0x09; |
yasuyuki | 0:fd7275804dc9 | 71 | rx8025.setALARMd(ad); |
yasuyuki | 0:fd7275804dc9 | 72 | |
yasuyuki | 0:fd7275804dc9 | 73 | // set Time as 2014-01-01 00:00:00 |
yasuyuki | 0:fd7275804dc9 | 74 | t.seconds=0x00; |
yasuyuki | 0:fd7275804dc9 | 75 | t.minutes=0x00; |
yasuyuki | 0:fd7275804dc9 | 76 | t.hours=0x00; |
yasuyuki | 0:fd7275804dc9 | 77 | t.weekdays=zeller(2014,1,1); |
yasuyuki | 0:fd7275804dc9 | 78 | t.days=0x01; |
yasuyuki | 0:fd7275804dc9 | 79 | t.months=0x01; |
yasuyuki | 0:fd7275804dc9 | 80 | t.years=0x14; |
yasuyuki | 0:fd7275804dc9 | 81 | rx8025.setTIME(t); |
yasuyuki | 0:fd7275804dc9 | 82 | |
yasuyuki | 0:fd7275804dc9 | 83 | while(1) { |
yasuyuki | 0:fd7275804dc9 | 84 | |
yasuyuki | 0:fd7275804dc9 | 85 | // Get Time |
yasuyuki | 0:fd7275804dc9 | 86 | t=rx8025.getTIME(); |
yasuyuki | 0:fd7275804dc9 | 87 | |
yasuyuki | 0:fd7275804dc9 | 88 | sprintf(msg,"%02X-%02X-%02X", t.years, t.months, t.days); |
yasuyuki | 0:fd7275804dc9 | 89 | lcd.locate(0,0); |
yasuyuki | 0:fd7275804dc9 | 90 | lcd.print(msg); |
yasuyuki | 0:fd7275804dc9 | 91 | sprintf(msg,"%02X:%02X:%02X", t.hours, t.minutes, t.seconds); |
yasuyuki | 0:fd7275804dc9 | 92 | lcd.locate(0,1); |
yasuyuki | 0:fd7275804dc9 | 93 | lcd.print(msg); |
yasuyuki | 0:fd7275804dc9 | 94 | wait(1); |
yasuyuki | 0:fd7275804dc9 | 95 | } |
yasuyuki | 0:fd7275804dc9 | 96 | |
yasuyuki | 0:fd7275804dc9 | 97 | } |
yasuyuki | 0:fd7275804dc9 | 98 | |
yasuyuki | 0:fd7275804dc9 | 99 |