This sketch set and arbitrary time and date, and then send through serial port every five seconds

Dependencies:   Hotboards_rtcc mbed

Committer:
Hotboards
Date:
Wed Feb 10 01:38:52 2016 +0000
Revision:
2:374bbb14bb6a
Parent:
1:d385e20a630f
added string array for days of the week  & months of the year ;

Who changed what in which revision?

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