Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of set_time_example2 by
main.cpp@1:c14275b8ac8c, 2015-04-27 (annotated)
- Committer:
- chalikias
- Date:
- Mon Apr 27 19:48:24 2015 +0000
- Revision:
- 1:c14275b8ac8c
- Parent:
- 0:c635c2051b52
n-bed testing RTC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chalikias | 1:c14275b8ac8c | 1 | n-bed testing: SET RTC |
chalikias | 1:c14275b8ac8c | 2 | |
simon | 0:c635c2051b52 | 3 | // Example to setup the Real-Time Clock from a terminal, sford |
simon | 0:c635c2051b52 | 4 | |
simon | 0:c635c2051b52 | 5 | #include "mbed.h" |
simon | 0:c635c2051b52 | 6 | |
simon | 0:c635c2051b52 | 7 | int main() { |
simon | 0:c635c2051b52 | 8 | |
simon | 0:c635c2051b52 | 9 | // get the current time from the terminal |
simon | 0:c635c2051b52 | 10 | struct tm t; |
simon | 0:c635c2051b52 | 11 | printf("Enter current date and time:\n"); |
simon | 0:c635c2051b52 | 12 | printf("YYYY MM DD HH MM SS[enter]\n"); |
simon | 0:c635c2051b52 | 13 | scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec); |
simon | 0:c635c2051b52 | 14 | |
simon | 0:c635c2051b52 | 15 | // adjust for tm structure required values |
simon | 0:c635c2051b52 | 16 | t.tm_year = t.tm_year - 1900; |
simon | 0:c635c2051b52 | 17 | t.tm_mon = t.tm_mon - 1; |
simon | 0:c635c2051b52 | 18 | |
simon | 0:c635c2051b52 | 19 | // set the time |
simon | 0:c635c2051b52 | 20 | set_time(mktime(&t)); |
simon | 0:c635c2051b52 | 21 | |
simon | 0:c635c2051b52 | 22 | // display the time |
simon | 0:c635c2051b52 | 23 | while(1) { |
simon | 0:c635c2051b52 | 24 | time_t seconds = time(NULL); |
simon | 0:c635c2051b52 | 25 | printf("Time as a basic string = %s", ctime(&seconds)); |
simon | 0:c635c2051b52 | 26 | wait(1); |
simon | 0:c635c2051b52 | 27 | } |
simon | 0:c635c2051b52 | 28 | } |