5 years ago.

RTC date and time adjustment during compile time


Is there a way to automatically adjust DS1307 RTC date and time during compilation time. I mean can mbed compiler adjust it according to windows date-time?

As far as i know, it is possible to do it on Arduino platform.. Is it possible for mbed?


1 Answer

5 years ago.

This prints the time and date on a pc terminal set at point of compiling.

Print system Time and Date

pc.printf("%s %s\n",__TIME__,__DATE__);

You could extract the values to set the RTC.

However you will need to test if the RTC has been set otherwise every reset will set the same time until you compile again.

Accepted Answer

Have a look here, may help to extract the data to the RTC:


pc.printf("SystemCoreClock %d %s %s\n",SystemCoreClock,TIME,DATE);

Gives the compile time,date.

posted by Paul Staron 08 Oct 2015

Anybody have a compiler macro that converts the TIME,DATE format into a unix time? I know it is sloppy but it could be used to set the ds1302 chip to whatever the time was when the code was last compiled.

posted by Joseph Ellsworth 28 Mar 2016