mbed workshop intro + cansat examples
RTC1.cpp@0:f309f06aeec7, 2012-05-10 (annotated)
- Committer:
- yamaguch
- Date:
- Thu May 10 21:14:34 2012 +0000
- Revision:
- 0:f309f06aeec7
1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch | 0:f309f06aeec7 | 1 | #include "mbed.h" |
yamaguch | 0:f309f06aeec7 | 2 | |
yamaguch | 0:f309f06aeec7 | 3 | int main() { |
yamaguch | 0:f309f06aeec7 | 4 | time_t seconds; |
yamaguch | 0:f309f06aeec7 | 5 | char buf[32]; |
yamaguch | 0:f309f06aeec7 | 6 | |
yamaguch | 0:f309f06aeec7 | 7 | seconds = (((2011 - 1969) * 365 + (2011 - 1968) / 4) |
yamaguch | 0:f309f06aeec7 | 8 | + 31 + 29 + 31 + 30 + 26) * 24 * 3600 |
yamaguch | 0:f309f06aeec7 | 9 | + 15 * 3600 + 14 * 60; |
yamaguch | 0:f309f06aeec7 | 10 | set_time(seconds); |
yamaguch | 0:f309f06aeec7 | 11 | seconds = time(NULL); |
yamaguch | 0:f309f06aeec7 | 12 | strftime(buf, sizeof(buf), "%x %X", localtime(&seconds)); |
yamaguch | 0:f309f06aeec7 | 13 | printf("mbed rtc = %s (timestamp = %d)\n", buf, seconds); |
yamaguch | 0:f309f06aeec7 | 14 | } |