一个简单的基于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); } } |
程序及串口数据
很详细啊,感谢分享。
应该也是大势所趋的独门秘笈之一. 毕竟是ARM的亲儿子