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 with compiler macros 00003 Demonstrates the use a MCP7941x clock calendar. 00004 The Hotboards_rtcc library works with this microchip real time clock 00005 (http://www.hotboards.org). 00006 00007 This sketch set time and date using compiler macros, and then send through 00008 serial port every five seconds 00009 The circuit: 00010 * VDD --> 3.3v 00011 * GND --> GND 00012 * SDA --> SDA 00013 * SCL --> SCL 00014 */ 00015 #include "mbed.h" 00016 #include "Hotboards_rtcc.h" 00017 00018 /* days of the week */ 00019 const char *week[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 00020 /* months of the year */ 00021 const char *months[] = {"JAN","FEB","MAR","APR","MAY","JUN", "JUL", "AUG","SEPT","OCT","NOV","DEC"}; 00022 00023 /*serial port init*/ 00024 Serial pc(USBTX,USBRX); 00025 /*i2c instance delaration for use with the rtcc library*/ 00026 I2C device(PB_9, PB_8); 00027 /*lets declare and rtcc instance */ 00028 Hotboards_rtcc rtcc(device); 00029 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 while(1) 00042 { 00043 /* get the actual time and date */ 00044 time = rtcc.now( ); 00045 /* display trough serial port */ 00046 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()); 00047 /* wait only five second */ 00048 wait( 5 ); 00049 } 00050 }
Generated on Tue Jul 26 2022 09:31:15 by
