thunchanok phutthaphaiboon
/
ReadRTC_example
version 1
Revision 0:29a6f70f93c3, committed 2017-12-11
- Comitter:
- moove1334
- Date:
- Mon Dec 11 13:09:16 2017 +0000
- Commit message:
- version1
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 29a6f70f93c3 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Dec 11 13:09:16 2017 +0000 @@ -0,0 +1,55 @@ +#include "mbed.h" +#include "string.h" +#include "SDFileSystem.h" + +void ReadRTC(); //DONE +void SetTime(); //DONE + +//---TIME---// +int sec = 0; +int min = 0; +int hour = 0; +int date = 0; +int month = 0; +int year = 0; + +int main() +{ + //SetTime(); + while(true) { + ReadRTC(); + printf("%d %d %d %d %d %d \n",year , month, date, hour, min, sec); + } +} + +void ReadRTC() +{ + printf(">>> ReadRTC()\n"); + struct tm * timeinfo; + char str_sec[5]; + char str_min[5]; + char str_hour[5]; + char str_date[5]; + char str_month[5]; + char str_year[5]; + time_t rawtime; + time (&rawtime); + timeinfo = localtime(&rawtime); + strftime(str_year,5,"%Y",timeinfo); + strftime(str_month,5,"%m",timeinfo); + strftime(str_date,5,"%d",timeinfo); + strftime(str_hour,5,"%H",timeinfo); + strftime(str_min,5,"%M",timeinfo); + strftime(str_sec,5,"%S",timeinfo); + sec = atoi(str_sec); + min = atoi(str_min); + hour = atoi(str_hour); + date = atoi(str_date); + month = atoi(str_month); + year = atoi(str_year); +} + +void SetTime() +{ + set_time(1513036800); +} \ No newline at end of file
diff -r 000000000000 -r 29a6f70f93c3 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Dec 11 13:09:16 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e7ca05fa8600 \ No newline at end of file