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

Dependencies:   Hotboards_rtcc mbed

Committer:
Hotboards
Date:
Tue Feb 09 22:39:19 2016 +0000
Revision:
0:b3b7ee561bba
Child:
1:d385e20a630f
first release

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 0:b3b7ee561bba 6 This sketch set and arbitrary time and date, and then send through
Hotboards 0:b3b7ee561bba 7 serial port every five seconds
Hotboards 0:b3b7ee561bba 8 The circuit:
Hotboards 0:b3b7ee561bba 9 * VDD --> 3.3v
Hotboards 0:b3b7ee561bba 10 * GND --> GND
Hotboards 0:b3b7ee561bba 11 * SDA --> SDA
Hotboards 0:b3b7ee561bba 12 * SCL --> SCL
Hotboards 0:b3b7ee561bba 13 */
Hotboards 0:b3b7ee561bba 14 #include "mbed.h"
Hotboards 0:b3b7ee561bba 15 #include "Hotboards_rtcc.h"
Hotboards 0:b3b7ee561bba 16
Hotboards 0:b3b7ee561bba 17 /*Abrimos una instancia de puerto serial*/
Hotboards 0:b3b7ee561bba 18 Serial pc(USBTX,USBRX);
Hotboards 0:b3b7ee561bba 19 /*i2c instance delaration for use with the rtcc library*/
Hotboards 0:b3b7ee561bba 20 I2C device(PB_9, PB_8);
Hotboards 0:b3b7ee561bba 21 /* lets declare and rtcc instance */
Hotboards 0:b3b7ee561bba 22 Hotboards_rtcc rtcc(device);
Hotboards 0:b3b7ee561bba 23
Hotboards 0:b3b7ee561bba 24 int main()
Hotboards 0:b3b7ee561bba 25 {
Hotboards 0:b3b7ee561bba 26 /* i2c bus clock set to 100khz*/
Hotboards 0:b3b7ee561bba 27 device.frequency(100000);
Hotboards 0:b3b7ee561bba 28 /* init the rtcc, just enable the clock if not already enable */
Hotboards 0:b3b7ee561bba 29 rtcc.begin();
Hotboards 0:b3b7ee561bba 30 /* set the time (15:30:00) and date 1/MAR/2001 */
Hotboards 0:b3b7ee561bba 31 rtcc.adjust( DateTime( 2001, 2, 1, 15, 30, 0 ) );
Hotboards 0:b3b7ee561bba 32
Hotboards 0:b3b7ee561bba 33 while(1)
Hotboards 0:b3b7ee561bba 34 {
Hotboards 0:b3b7ee561bba 35 /* get the actual time and date */
Hotboards 0:b3b7ee561bba 36 DateTime time = rtcc.now( );
Hotboards 0:b3b7ee561bba 37 /* print to serial port */
Hotboards 0:b3b7ee561bba 38 printf( "Time- %d:%d:%d Date- %d/ %d/ %d\n",time.hour( ),time.minute( ),time.second( ),time.day( ),time.month( ),time.year( ));
Hotboards 0:b3b7ee561bba 39 /* repeat again every 5 seconds*/
Hotboards 0:b3b7ee561bba 40 wait( 5 );
Hotboards 0:b3b7ee561bba 41 }
Hotboards 0:b3b7ee561bba 42 }