时间初始化:
#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;
}
RTC开始默认时间
最新推荐文章于 2024-01-04 16:03:44 发布