This sketch set time and date using compiler macros, and then send through serial port every five seconds

Dependencies:   Hotboards_rtcc mbed

Committer:
Hotboards
Date:
Tue Feb 09 23:31:57 2016 +0000
Revision:
0:18a586e130b8
Child:
1:6270f452fd66
First release: Hotboards_rtcc_compiler_timedate

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Hotboards 0:18a586e130b8 1 /*
Hotboards 0:18a586e130b8 2 Hotboards_rtcc Library - setting time and date with compiler macros
Hotboards 0:18a586e130b8 3 Demonstrates the use a MCP7941x clock calendar.
Hotboards 0:18a586e130b8 4 The Hotboards_rtcc library works with this microchip real time clock
Hotboards 0:18a586e130b8 5 (http://www.hotboards.org).
Hotboards 0:18a586e130b8 6
Hotboards 0:18a586e130b8 7 This sketch set time and date using compiler macros, and then send through
Hotboards 0:18a586e130b8 8 serial port every five seconds
Hotboards 0:18a586e130b8 9 The circuit:
Hotboards 0:18a586e130b8 10 * VDD --> 3.3v
Hotboards 0:18a586e130b8 11 * GND --> GND
Hotboards 0:18a586e130b8 12 * SDA --> SDA
Hotboards 0:18a586e130b8 13 * SCL --> SCL
Hotboards 0:18a586e130b8 14 */
Hotboards 0:18a586e130b8 15 #include "mbed.h"
Hotboards 0:18a586e130b8 16 #include "Hotboards_rtcc.h"
Hotboards 0:18a586e130b8 17
Hotboards 0:18a586e130b8 18 /* days of the week */
Hotboards 0:18a586e130b8 19 const char *week[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
Hotboards 0:18a586e130b8 20 /* months of the year */
Hotboards 0:18a586e130b8 21 const char *months[] = {"JAN","FEB","MAR","APR","MAY","JUN", "JUL", "AUG","SEPT","OCT","NOV","DEC"};
Hotboards 0:18a586e130b8 22
Hotboards 0:18a586e130b8 23 /*serial port init*/
Hotboards 0:18a586e130b8 24 Serial pc(USBTX,USBRX);
Hotboards 0:18a586e130b8 25 /*i2c instance delaration for use with the rtcc library*/
Hotboards 0:18a586e130b8 26 I2C device(PB_9, PB_8);
Hotboards 0:18a586e130b8 27 /*lets declare and rtcc instance */
Hotboards 0:18a586e130b8 28 Hotboards_rtcc rtcc(device);
Hotboards 0:18a586e130b8 29 #include "mbed.h"
Hotboards 0:18a586e130b8 30
Hotboards 0:18a586e130b8 31
Hotboards 0:18a586e130b8 32 int main()
Hotboards 0:18a586e130b8 33 {
Hotboards 0:18a586e130b8 34 /*i2c bus clock set to 100khz*/
Hotboards 0:18a586e130b8 35 device.frequency(100000);
Hotboards 0:18a586e130b8 36 /* init the rtcc, just enable the clock if not already enable */
Hotboards 0:18a586e130b8 37 rtcc.begin();
Hotboards 0:18a586e130b8 38 /* set the time when is compiled*/
Hotboards 0:18a586e130b8 39 DateTime time( __DATE__, __TIME__);
Hotboards 0:18a586e130b8 40 rtcc.adjust(time);
Hotboards 0:18a586e130b8 41
Hotboards 0:18a586e130b8 42 while(1)
Hotboards 0:18a586e130b8 43 {
Hotboards 0:18a586e130b8 44 /* get the actual time and date */
Hotboards 0:18a586e130b8 45 time = rtcc.now( );
Hotboards 0:18a586e130b8 46 /* display trough serial port */
Hotboards 0:18a586e130b8 47 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());
Hotboards 0:18a586e130b8 48 /* wait only five second */
Hotboards 0:18a586e130b8 49 wait( 5 );
Hotboards 0:18a586e130b8 50 }
Hotboards 0:18a586e130b8 51 }