thunchanok phutthaphaiboon
/
ReadRTC_example
version 1
main.cpp@0:29a6f70f93c3, 2017-12-11 (annotated)
- Committer:
- moove1334
- Date:
- Mon Dec 11 13:09:16 2017 +0000
- Revision:
- 0:29a6f70f93c3
version1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
moove1334 | 0:29a6f70f93c3 | 1 | #include "mbed.h" |
moove1334 | 0:29a6f70f93c3 | 2 | #include "string.h" |
moove1334 | 0:29a6f70f93c3 | 3 | #include "SDFileSystem.h" |
moove1334 | 0:29a6f70f93c3 | 4 | |
moove1334 | 0:29a6f70f93c3 | 5 | void ReadRTC(); //DONE |
moove1334 | 0:29a6f70f93c3 | 6 | void SetTime(); //DONE |
moove1334 | 0:29a6f70f93c3 | 7 | |
moove1334 | 0:29a6f70f93c3 | 8 | //---TIME---// |
moove1334 | 0:29a6f70f93c3 | 9 | int sec = 0; |
moove1334 | 0:29a6f70f93c3 | 10 | int min = 0; |
moove1334 | 0:29a6f70f93c3 | 11 | int hour = 0; |
moove1334 | 0:29a6f70f93c3 | 12 | int date = 0; |
moove1334 | 0:29a6f70f93c3 | 13 | int month = 0; |
moove1334 | 0:29a6f70f93c3 | 14 | int year = 0; |
moove1334 | 0:29a6f70f93c3 | 15 | |
moove1334 | 0:29a6f70f93c3 | 16 | int main() |
moove1334 | 0:29a6f70f93c3 | 17 | { |
moove1334 | 0:29a6f70f93c3 | 18 | //SetTime(); |
moove1334 | 0:29a6f70f93c3 | 19 | while(true) { |
moove1334 | 0:29a6f70f93c3 | 20 | ReadRTC(); |
moove1334 | 0:29a6f70f93c3 | 21 | printf("%d %d %d %d %d %d \n",year , month, date, hour, min, sec); |
moove1334 | 0:29a6f70f93c3 | 22 | } |
moove1334 | 0:29a6f70f93c3 | 23 | } |
moove1334 | 0:29a6f70f93c3 | 24 | |
moove1334 | 0:29a6f70f93c3 | 25 | void ReadRTC() |
moove1334 | 0:29a6f70f93c3 | 26 | { |
moove1334 | 0:29a6f70f93c3 | 27 | printf(">>> ReadRTC()\n"); |
moove1334 | 0:29a6f70f93c3 | 28 | struct tm * timeinfo; |
moove1334 | 0:29a6f70f93c3 | 29 | char str_sec[5]; |
moove1334 | 0:29a6f70f93c3 | 30 | char str_min[5]; |
moove1334 | 0:29a6f70f93c3 | 31 | char str_hour[5]; |
moove1334 | 0:29a6f70f93c3 | 32 | char str_date[5]; |
moove1334 | 0:29a6f70f93c3 | 33 | char str_month[5]; |
moove1334 | 0:29a6f70f93c3 | 34 | char str_year[5]; |
moove1334 | 0:29a6f70f93c3 | 35 | time_t rawtime; |
moove1334 | 0:29a6f70f93c3 | 36 | time (&rawtime); |
moove1334 | 0:29a6f70f93c3 | 37 | timeinfo = localtime(&rawtime); |
moove1334 | 0:29a6f70f93c3 | 38 | strftime(str_year,5,"%Y",timeinfo); |
moove1334 | 0:29a6f70f93c3 | 39 | strftime(str_month,5,"%m",timeinfo); |
moove1334 | 0:29a6f70f93c3 | 40 | strftime(str_date,5,"%d",timeinfo); |
moove1334 | 0:29a6f70f93c3 | 41 | strftime(str_hour,5,"%H",timeinfo); |
moove1334 | 0:29a6f70f93c3 | 42 | strftime(str_min,5,"%M",timeinfo); |
moove1334 | 0:29a6f70f93c3 | 43 | strftime(str_sec,5,"%S",timeinfo); |
moove1334 | 0:29a6f70f93c3 | 44 | sec = atoi(str_sec); |
moove1334 | 0:29a6f70f93c3 | 45 | min = atoi(str_min); |
moove1334 | 0:29a6f70f93c3 | 46 | hour = atoi(str_hour); |
moove1334 | 0:29a6f70f93c3 | 47 | date = atoi(str_date); |
moove1334 | 0:29a6f70f93c3 | 48 | month = atoi(str_month); |
moove1334 | 0:29a6f70f93c3 | 49 | year = atoi(str_year); |
moove1334 | 0:29a6f70f93c3 | 50 | } |
moove1334 | 0:29a6f70f93c3 | 51 | |
moove1334 | 0:29a6f70f93c3 | 52 | void SetTime() |
moove1334 | 0:29a6f70f93c3 | 53 | { |
moove1334 | 0:29a6f70f93c3 | 54 | set_time(1513036800); |
moove1334 | 0:29a6f70f93c3 | 55 | } |