/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
//RCC->BDCR |= RCC_BDCR_RTCEN;
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/***********************************************************************/
/* Configure the RTC data register and RTC prescaler */
RTC_InitStructure.RTC_AsynchPrediv = 0x7F;//AsynchPrediv;
RTC_InitStructure.RTC_SynchPrediv = 0xFF;//SynchPrediv;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
/* Check on RTC init */
if (RTC_Init(&RTC_InitStructure) == ERROR)
{
DisplayString(20,100,"***** RTC Prescaler failed ",0xf800); // 原程序用的是串口,这里直接在LCD上显示
}
/* Configure the time register */
RTC_TimeRegulate(); // 这个是输入时间的,改动很大,但并不是设置控制寄存器的
}
else
{
/* Check if the Power On Reset flag is set */
if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
{
DisplayString(20,100,"Power On Reset occurred....", 0xf800);
}
/* Check if the Pin Reset flag is set */
else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
{
DisplayString(20,100,"External Reset occurred....",0xf800);
}
DisplayString(20,120,"No need to configure RTC....",0xf800);
/* Enable the PWR clock */
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); // 已经打开了。
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Clear the RTC Alarm Flag */
RTC_ClearFlag(RTC_FLAG_ALRAF);
/* Display the RTC Time and Alarm */
//RTC_TimeShow();
RTC_GetTime(RTC_Format_BCD, &RTC_TimeStructure);
//RTC_AlarmShow();
RTC_GetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
}