Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Hotboards_rtcc mbed
main.cpp
00001 /* 00002 Hotboards_rtcc Library - alarm 00003 Demonstrates the use a MCP7941x clock calendar. The Hotboards_rtcc 00004 library works with this microchip real time clock 00005 (http://www.hotboards.org). 00006 00007 This sketch shows how to repeat an alarm every minute 00008 00009 The circuit: 00010 * VDD --> 3.3v 00011 * GND --> GND 00012 * SDA --> SDA 00013 * SCL --> SCL 00014 00015 */ 00016 #include "mbed.h" 00017 #include "Hotboards_rtcc.h" 00018 00019 /* days of the week */ 00020 const char *week[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 00021 /* months of the year */ 00022 const char *months[] = {"JAN","FEB","MAR","APR","MAY","JUN", "JUL", "AUG","SEPT","OCT","NOV","DEC"}; 00023 00024 /*serial port init*/ 00025 Serial pc(USBTX,USBRX); 00026 /*i2c instance delaration for use with the rtcc library*/ 00027 I2C device(PB_9, PB_8); 00028 /*lets declare and rtcc instance */ 00029 Hotboards_rtcc rtcc(device); 00030 00031 int main() 00032 { 00033 /*i2c bus clock set to 100khz*/ 00034 device.frequency(100000); 00035 /* init the rtcc, just enable the clock if not already enable */ 00036 rtcc.begin(); 00037 /* set the time when is compiled*/ 00038 DateTime time( __DATE__, __TIME__); 00039 rtcc.adjust(time); 00040 00041 /* Set an alarm after one minute */ 00042 DateTime alarm = time + TimeSpan( 0, 0, 1, 0 ); 00043 rtcc.setAlarm( alarm ); 00044 /* enable the alarm */ 00045 rtcc.turnOnAlarm( ); 00046 00047 printf("The alarm will be active in one minute \n"); 00048 00049 while(1) 00050 { 00051 /* is the alarm active?? */ 00052 if( rtcc.getAlarmStatus( ) == 1 ) 00053 { 00054 /* clear the alarm */ 00055 rtcc.clearAlarm( ); 00056 /* display the time */ 00057 DateTime time = rtcc.now( ); 00058 printf( "Alarm active at: Time- %d:%d:%d Date- %s/ %d/ %s/ %d\n",time.hour( ),time.minute( ),time.second( ),week[time.dayOfTheWeek( )],time.day( ),months[time.month( )],time.year()); 00059 /* Set an alarm one minute after the current time, again */ 00060 alarm = time + TimeSpan( 0, 0, 1, 0 ); 00061 rtcc.setAlarm( alarm ); 00062 } 00063 } 00064 } 00065
Generated on Tue Jul 12 2022 20:48:51 by
1.7.2