/* Enable the LSE OSC */
RCC_LSICmd(ENABLE); /*使能LSI时钟*/
/* Wait till LSE is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET); /*等待LSI就绪*/
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/* Configure the RTC data register and RTC prescaler */
/* ck_spre(1Hz) = RTCCLK(LSI) /(AsynchPrediv + 1)*(SynchPrediv + 1)*/
RTC_InitStructure.RTC_AsynchPrediv = 99;
RTC_InitStructure.RTC_SynchPrediv = 399;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStructure); //1HZ
/* Set the time to 00h 00mn 00s AM */
RTC_TimeStruct.RTC_H12 = RTC_H12_AM;
RTC_TimeStruct.RTC_Hours = 0x00;
RTC_TimeStruct.RTC_Minutes = 0x00;
RTC_TimeStruct.RTC_Seconds = 0x00;
RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);
/* Set the alarmA Masks */
RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 0x01;
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_Seconds;
RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
/* Set AlarmA subseconds and enable SubSec Alarm : generate 1 interripts per Second */
RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0XFF, RTC_AlarmSubSecondMask_SS14_8);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Enable the alarmA */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
void RTC_IRQHandler(void)
{
/* Check on the AlarmA flag and on the number of interrupts per Second (60*8) */
if(RTC_GetITStatus(RTC_IT_ALRA) != RESET)
{
/* ALARM is enabled */
if((Start_RTC == 1)&&(SetValue.RemainingTime>0))
{
SetValue.RemainingTime--;
}
/* Clear RTC AlarmA Flags */
RTC_ClearITPendingBit(RTC_IT_ALRA);
}
/* Clear the EXTIL line 17 */
EXTI_ClearITPendingBit(EXTI_Line17);
/* Enable the LSE OSC */
RCC_LSICmd(ENABLE); /*使能LSI时钟*/
/* Wait till LSE is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET); /*等待LSI就绪*/
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/* Configure the RTC data register and RTC prescaler */
/* ck_spre(1Hz) = RTCCLK(LSI) /(AsynchPrediv + 1)*(SynchPrediv + 1)*/
RTC_InitStructure.RTC_AsynchPrediv = 99;
RTC_InitStructure.RTC_SynchPrediv = 399;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStructure); //1HZ
/* Set the time to 00h 00mn 00s AM */
RTC_TimeStruct.RTC_H12 = RTC_H12_AM;
RTC_TimeStruct.RTC_Hours = 0x00;
RTC_TimeStruct.RTC_Minutes = 0x00;
RTC_TimeStruct.RTC_Seconds = 0x00;
RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);
/* Set the alarmA Masks */
RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 0x01;
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_Seconds;
RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
/* Set AlarmA subseconds and enable SubSec Alarm : generate 1 interripts per Second */
RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0XFF, RTC_AlarmSubSecondMask_SS14_8);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Enable the alarmA */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
void RTC_IRQHandler(void)
{
/* Check on the AlarmA flag and on the number of interrupts per Second (60*8) */
if(RTC_GetITStatus(RTC_IT_ALRA) != RESET)
{
/* ALARM is enabled */
if((Start_RTC == 1)&&(SetValue.RemainingTime>0))
{
SetValue.RemainingTime--;
}
/* Clear RTC AlarmA Flags */
RTC_ClearITPendingBit(RTC_IT_ALRA);
}
/* Clear the EXTIL line 17 */
EXTI_ClearITPendingBit(EXTI_Line17);