/* Clear the LCD */ LCD_Clear(); /* Set the LCD Back Color */ LCD_SetBackColor(Blue);
/* Set the LCD Text Color */ LCD_SetTextColor(White);
/* Disable the JoyStick interrupts */ //关闭外部中断: IntExtOnOffConfig(DISABLE);
//先确认时钟是否正常 if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { LCD_DisplayString(Line1, "Time and Date are not configured, please go the Calendar menu and set the time and date parameters. Press JoyStick to continue..."); while(ReadKey() == NOKEY) { } /* Clear the LCD */ LCD_Clear(); /* Display the previous menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; //退出 }
tmp = RTC_GetCounter();
/* Save the Alarm value in the Backup register */ BKP_WriteBackupRegister(BKP_DR6, (tmp & 0x0000FFFF)); BKP_WriteBackupRegister(BKP_DR7, (tmp >> 16));
Alarm_PreAdjust(); LCD_ClearLine(Line8); LCD_DisplayStringLine(Line6, " MCU in STOP Mode "); LCD_DisplayStringLine(Line7, " Wait For RTC Alarm ");
/* Request to enter STOP mode with regulator ON */ PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI);
/* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP();
LCD_DisplayStringLine(Line4, " STOP Mode "); LCD_DisplayStringLine(Line5, "Wake-Up by RTC Alarm"); LCD_DisplayStringLine(Line6, "Press JoyStick to "); LCD_DisplayStringLine(Line7, "continue... ");
while(ReadKey() == NOKEY) { }
/* Clear the LCD */ LCD_Clear(); /* Display the previous menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); }
/******************************************************************************* * Function Name : RTC_Configuration * Description : Configures the RTC. * Input : None * Output : None * Return : None *******************************************************************************/ void RTC_Configuration(void) { /* Enable PWR and BKP clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
/* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE);
/* Reset Backup Domain */ BKP_DeInit();
/* Enable LSE */ RCC_LSEConfig(RCC_LSE_ON); /* Wait till LSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { } /* Select LSE as RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* Enable RTC Clock */ RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC registers synchronization */ RTC_WaitForSynchro();
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask();
/* Enable the RTC Second */ //RTC_ITConfig(RTC_IT_SEC, ENABLE); RTC_ITConfig(RTC_IT_ALR, ENABLE);
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask();
RTC_SetPrescaler(2-1);
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); }
/******************************************************************************* * Function Name : RTCAlarm_IRQHandler * Description : This function handles RTC Alarm interrupt request. * Input : None * Output : None * Return : None *******************************************************************************/ void RTCAlarm_IRQHandler(void) { if(RTC_GetITStatus(RTC_IT_ALR) != RESET) {
EXTI_ClearITPendingBit(EXTI_Line17);
/* Check if the Wake-Up flag is set */ if(PWR_GetFlagStatus(PWR_FLAG_WU) != RESET) { /* Clear Wake Up flag */ PWR_ClearFlag(PWR_FLAG_WU); }
/* Clear the RTC Second interrupt */ RTC_ClearITPendingBit(RTC_IT_ALR);
/* Enable time update */ TimeDisplay = 1;
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Reset RTC Counter when Time is 23:59:59 */ if(RTC_GetCounter() == 0x00015180) { RTC_SetCounter(0x0); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } } }