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

Dependencies:   Hotboards_rtcc mbed

main.cpp

Committer:
Hotboards
Date:
2016-02-09
Revision:
0:b3b7ee561bba
Child:
1:d385e20a630f

File content as of revision 0:b3b7ee561bba:

/*
  Hotboards_rtcc Library - setting time and date
 Demonstrates the use a MCP7941x clock calendar.  The Hotboards_rtcc
 library works with this microchip real time clock
 (http://www.hotboards.org).
 This sketch set and arbitrary time and date, and then send through
 serial port every five seconds
  The circuit:
 *  VDD  -->  3.3v
 *  GND  -->  GND
 *  SDA  -->  SDA
 *  SCL  -->  SCL
*/
#include "mbed.h"
#include "Hotboards_rtcc.h"

/*Abrimos una instancia de puerto serial*/
Serial pc(USBTX,USBRX);
/*i2c instance delaration for use with the rtcc library*/
I2C device(PB_9, PB_8);
/* lets declare and rtcc instance */
Hotboards_rtcc rtcc(device);

int main() 
{
  /* i2c bus clock set to 100khz*/
  device.frequency(100000);
  /* init the rtcc, just enable the clock if not already enable */
  rtcc.begin();
  /* set the time (15:30:00) and date 1/MAR/2001 */
  rtcc.adjust( DateTime( 2001, 2, 1, 15, 30, 0 ) );
 
 while(1)
 {
     /* get the actual time and date */
    DateTime time = rtcc.now( );
    /* print to serial port */
    printf( "Time- %d:%d:%d  Date-  %d/ %d/ %d\n",time.hour( ),time.minute( ),time.second( ),time.day( ),time.month( ),time.year( ));
    /* repeat again every 5 seconds*/
    wait( 5 );
 }
}