在线时间4854 小时
UID3309825
ST金币0
蝴蝶豆17
注册时间2016-9-4
论坛元老
- 最后登录
- 2020-12-9
|
a0a.1 32b0c
一个简单的基于mbed的RTC时间显示到串口程序
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
printf("RTC example\n");
//set_time(1387188300); // 起始时间Set RTC time to 16 December 2013 10:05:00 UTC
//从2013 10:05:00 开始计时
//按秒调整时间
//起始时间加一天即1387188300+86400
//起始时间加一月即1387188300+2592000 按30天算
//起始时间加一月即1387188300+31536000 按365天算
//1476612300 Sun Oct 16 10:05:53 2016
set_time(1476612300); // Sun Oct 16 10:05:53 2016
printf("Date and time are set.\n");
while(1) {
time_t seconds = time(NULL);
//printf("Time as seconds since January 1, 1970 = %d\n", seconds);
printf("Time as a basic string = %s", ctime(&seconds));//把time_t类型转换成字符串类型
//char buffer[32];
//strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds));
//printf("Time as a custom formatted string = %s", buffer);
myled = !myled;
wait(1);
}
}
|
|