Errol Burrow
/
HelloWorldSerial
Simple Serial Hello World with RTC clock sync to PC capability
Revision 0:ac9d7acfd1f5, committed 2010-04-06
- Comitter:
- eburrow
- Date:
- Tue Apr 06 20:08:35 2010 +0000
- Commit message:
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r ac9d7acfd1f5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 06 20:08:35 2010 +0000 @@ -0,0 +1,64 @@ +#include "mbed.h" + +DigitalOut myled(LED1); + +Serial pc(USBTX,USBRX); + + +bool clock_set = 0; +time_t read_time = 0; +time_t seconds; + +int main() { + + pc.baud(9600); + + while (1) { + + // have we set our clock yet? + if (clock_set == 0) { + // try to request the time + pc.printf("epoch\n\r"); + // wait a bit + wait(0.1); + // try to read a long int + if (pc.readable()) { + scanf("%d",&read_time); + if (read_time > 0) { + // set the time + pc.printf("time value read: %u\r\n",read_time); + set_time(read_time); + wait(0.2); + clock_set = 1; + } else { + // delay longer and try again + wait(4); + } + } else{ + wait (0.1); + } + } else { + // display time + //seconds = time(NULL); + //struct tm *t = localtime(&seconds); + //pc.printf("%04d-%02d-%02d %02d:%02d:%02d UTC\r\n",(t->tm_year+1900),(t->tm_mon+1),t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); + // delay 5 seconds + //wait(1); + ;; + } + + myled = !myled; + //wait(0.2); + //pc.printf("Hello World\r\n"); + + seconds = time(NULL); + struct tm *t = localtime(&seconds); + pc.printf("%04d-%02d-%02d %02d:%02d:%02d UTC\r\n",(t->tm_year+1900),(t->tm_mon+1),t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); + wait(1); + + + } + +} + +
diff -r 000000000000 -r ac9d7acfd1f5 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Apr 06 20:08:35 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0