补充一下函数
void RTC_Config(void)
{
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
// RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE); //wu ADD 5 5
/* Allow access to RTC 后备域解锁*/
PWR_BackupAccessCmd(ENABLE);
#if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/
/* The RTC Clock may varies due to LSI frequency dispersion. */
/* Enable the LSI OSC */
RCC_LSICmd(ENABLE);
/* Wait till LSI is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
SynchPrediv = 0xFF;
AsynchPrediv = 0x7F;
#elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */
/* Enable the LSE OSC */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
SynchPrediv = 0xFF;
AsynchPrediv = 0x7F;
#else
#error Please select the RTC Clock source inside the main.c file
#endif /* RTC_CLOCK_SOURCE_LSI */
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Write to the first RTC Backup Data Register */
RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2); //wu add 5 14
}
void RTC_TimeRegulate(void)
{
// uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF;
/***********************wu add 3 5 DATE Settings***************************************/
RTC_DateStructure.RTC_Year = 13;
RTC_DateStructure.RTC_Month = 5;
RTC_DateStructure.RTC_Date = 4;
RTC_DateStructure.RTC_WeekDay=6;
if(RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure) == ERROR)
{
}
else
{
RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure);
RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2); //这句话很重要,不能省,不然每次烧写程序都会重新设置时间。
}
/**************************************************************************************/
//printf("\n\r==============Time Settings=====================================\n\r");
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
RTC_TimeStructure.RTC_Hours = 11;
RTC_TimeStructure.RTC_Minutes = 6;
RTC_TimeStructure.RTC_Seconds = 0;
/* Configure the RTC time register */
if(RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure) == ERROR)
{
// printf("\n\r>> !! RTC Set Time failed. !! <<\n\r");
}
else
{
// printf("\n\r>> !! RTC Set Time success. !! <<\n\r");
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
/* Indicator for the RTC configuration */
RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);//给DR0赋值0x32F2,注明已经配置过,下次无需再配置
} |