RX8025 sample

Dependencies:   AQM0802 RX8025 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //**********************
00002 // Real Time Clock
00003 // RX8025 sample for mbed
00004 //
00005 // Be careful, no parameter check.
00006 //
00007 // (C)Copyright 2014 All rights reserved by Y.Onodera
00008 // http://einstlab.web.fc2.com
00009 //**********************
00010 #include "mbed.h"
00011 #include "AQM0802.h"
00012 #include "RX8025.h"
00013 
00014 #if defined(TARGET_LPC1768)
00015 I2C i2c(p28,p27);
00016 #endif
00017 // for TG-LPC11U35-501
00018 #if defined(TARGET_LPC11U35_501)
00019 I2C i2c(P0_5,P0_4);
00020 #endif
00021 // for Nucleo
00022 #if defined(TARGET_NUCLEO_F401RE)
00023 I2C i2c(D14,D15);
00024 #endif
00025 
00026 AQM0802 lcd(i2c);
00027 RX8025 rx8025(i2c);
00028 
00029 // 0=Sun...6=Sat
00030 int zeller(int y, int m, int d){
00031     
00032     int i;
00033     if(m<3){
00034         --y;
00035         m+=12;
00036     }
00037     i = (y + y/4 - y/100 + y/400 + (13*m + 8)/5 + d) % 7;
00038     return i;    
00039 }
00040 
00041 
00042 int main() {
00043     
00044     char msg[10];
00045     Times t;
00046     Control c;
00047     Alarmw aw;
00048     Alarmd ad;
00049 
00050     // set Control
00051     c.control1=0x20;    // 24hours format
00052     c.control2=0x00;
00053     c.offset=0x00;      // to adjust offset
00054     rx8025.setCONTROL(c);
00055 
00056     // set Alarm with week, as 08:00 at sat.
00057     // to enable WAFG=1 in contol2
00058     // you will see WALE=1 in control1 and INTB pin=L, when it happens
00059     // you should clear WALE
00060     aw.minute=0x00;
00061     aw.hour=0x08;
00062     aw.weekday=0x06;
00063     rx8025.setALARMw(aw);
00064 
00065     // set Alarm, as 09:00
00066     // to enable DAFG=1 in contol2
00067     // you will see DALE=1 in control1 and INTA pin=L, when it happens
00068     // you should clear DALE
00069     ad.minute=0x00;
00070     ad.hour=0x09;
00071     rx8025.setALARMd(ad);
00072 
00073     // set Time as 2014-01-01 00:00:00
00074     t.seconds=0x00;
00075     t.minutes=0x00;
00076     t.hours=0x00;
00077     t.weekdays=zeller(2014,1,1);
00078     t.days=0x01;
00079     t.months=0x01;
00080     t.years=0x14;
00081     rx8025.setTIME(t);
00082       
00083     while(1) {
00084 
00085         // Get Time
00086         t=rx8025.getTIME();
00087 
00088         sprintf(msg,"%02X-%02X-%02X", t.years, t.months, t.days);
00089         lcd.locate(0,0);
00090         lcd.print(msg);
00091         sprintf(msg,"%02X:%02X:%02X", t.hours, t.minutes, t.seconds);
00092         lcd.locate(0,1);
00093         lcd.print(msg);
00094         wait(1);
00095     }
00096 
00097 }
00098 
00099