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 - setting time and date 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 set and arbitrary time and date, and then send through 00008 serial port every five seconds 00009 00010 The circuit: 00011 * VDD --> 3.3v 00012 * GND --> GND 00013 * SDA --> SDA 00014 * SCL --> SCL 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 (15:30:00) and date 1/MAR/2001 */ 00038 rtcc.adjust( DateTime( 2001, 2, 1, 15, 30, 0 ) ); 00039 00040 while(1) 00041 { 00042 /* get the actual time and date */ 00043 DateTime time = rtcc.now( ); 00044 /* print to serial port */ 00045 printf( "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()); 00046 /* repeat again every 5 seconds*/ 00047 wait( 5 ); 00048 } 00049 }
Generated on Tue Jul 19 2022 12:13:29 by
1.7.2
Hotboards RTCC