void Time_Adjust(void) { struct tm when; time_t now; when.tm_sec= 0; when.tm_min= 35; when.tm_hour= 21; when.tm_mday= 14; when.tm_mon= 11; when.tm_year= 107; when.tm_wday= 0; // when.tm_yday= 33; when.tm_isdst= 0; //或通过UI得到以上数据 now = mktime(&when);
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Change the current time */ RTC_SetCounter(now); // RTC_SetCounter(0xfffffff0); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); }
void Time_Display(u32 TimeVar) { static struct tm when; time_t now;
now = (time_t)TimeVar; //TimeVar为RTCCcounter中的值 when = *localtime( &now ); printf( "Current time is %s
", asctime( &when ) );
} 具体操作请参考RTC例程
|