RTC开始默认时间
時間初始化:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>typedef unsigned int uint32_t;#define CLOCK_DEFAULT_START_DATE \
{ \0, /* tm_sec: 0 seconds (0-60, 60 = leap second)*/ \0, /* tm_min: 0 minutes (0-59) */ \12, /* tm_hour: 0 hours (0-23) */ \1, /* tm_mday: 1st day of the month (1 - 31) */ \0, /* tm_mon: January (0 - 11, 0 = January) */ \116, /* tm_year: Year 2016 (year since 1900) */ \0, /* tm_wday: Sunday (0 - 6, 0 = Sunday) */ \0, /* tm_yday: 1st day of the year (0-365) */ \-1 /* tm_isdst: Daylight saving time; enabled (>0), disabled (=0) or unknown (<0) */ \
}typedef struct
{struct tm startDate; // Date when RTC was started uint32_t rtcCountsPerSec; //< RTC count frequency [Hz]
} Clock_Init_TypeDef;#define CLOCK_INIT_DEFAULT \
{ \CLOCK_DEFAULT_START_DATE, /* 默認開始時間*/ \32768 /* RTC的頻率為32.768 kHz */ \ /* '\' 是連接符*/
}Clock_Init_TypeDef calendar = CLOCK_INIT_DEFAULT;int main()
{printf("%d-%02d-%02d %02d:%02d:%02d",calendar.startDate.tm_year+1900,calendar.startDate.tm_mon+1,calendar.startDate.tm_mday,calendar.startDate.tm_hour,calendar.startDate.tm_min,calendar.startDate.tm_sec);return 0;
}
總結
- 上一篇: RT-Thread的I/O设备模块及其驱
- 下一篇: C语言乘法表