/******************************************************************************* * Function Name : BACKUP_IRQHandler * Description : This function handles BACKUP global interrupt request. * Input : None * Output : None * Return : None *******************************************************************************/ void BACKUP_IRQHandler(void) { uint32_t tmp; vuint32_t i, j; if (BKP_RTC_GetFlagStatus(BKP_RTC_FLAG_ALRF) == SET) { if (STOPModeStatus) { /* Wake-up from STOP mode is handled by an RTC Alarm */ /* Disable SLEEPONEXIT mode */ tmp = SCB->SCR; tmp &= ~SCB_SCR_SLEEPONEXIT_Msk; SCB->SCR = tmp; STOPModeStatus = 0; } else /* RTC Alarm handling */ if (AlarmSetStatus) { for (i = 0; i < 5; i++) { PORT_SetBits(LEDs_PORT, LEDs_PINs); for (j = 0; j < 300000; j++) { } PORT_ResetBits(LEDs_PORT, LEDs_PINs); for (j = 0; j < 300000; j++) { } } } } if (BKP_RTC_GetFlagStatus(BKP_RTC_FLAG_SECF) == SET) { BKP_RTC_ITConfig(BKP_RTC_IT_SECF, DISABLE); /* If counter is equal to 86339: one day was elapsed */ tmp = BKP_RTC_GetCounter(); if ((tmp / 3600 == 23) && (((tmp % 3600) / 60) == 59) && (((tmp % 3600) % 60) == 59)) { /* Wait until last write operation on RTC registers has finished */ BKP_RTC_WaitForUpdate(); /* Reset counter value */ BKP_RTC_SetCounter(0); /* Wait until last write operation on RTC registers has finished */ BKP_RTC_WaitForUpdate(); /* Increment the date */ Date_Update(); } BKP_RTC_ITConfig(BKP_RTC_IT_SECF, ENABLE); } }
/******************************************************************************* * Function Name : RTC_IRQHandler * Description : This function handles RTC global interrupt request. * Input : None * Output : None * Return : None *******************************************************************************/ void RTC_IRQHandler(void) { /* If counter is equal to 86339: one day was elapsed */ if((RTC_GetCounter()/3600 == 23)&&(((RTC_GetCounter()%3600)/60) == 59)&& (((RTC_GetCounter()%3600)%60) == 59)) /* 23*3600 + 59*60 + 59 = 86339 */ { /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Reset counter value */ RTC_SetCounter(0x0); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Increment the date */ Date_Update(); } /* Clear the RTC Second Interrupt pending bit */ RTC_ClearITPendingBit(RTC_IT_SEC); }
/******************************************************************************* * Function Name : Calendar_Init * Description : Initializes calendar application. * Input : None * Output : None * Return : None *******************************************************************************/ void Calendar_Init(void) { uint32_t i = 0, tmp = 0, pressedkey = 0; /* Initialize Date structure */ date_s.month = 01; date_s.day = 01; date_s.year = 2009; if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { LCD_SetBackColor(Blue); LCD_SetTextColor(White); LCD_DisplayStringLine(Line7, "Time and Date Config"); LCD_DisplayStringLine(Line8, "Select: Press SEL "); LCD_DisplayStringLine(Line9, "Abort: Press Any Key"); while(1) { pressedkey = ReadKey(); if(pressedkey == SEL) { /* Adjust Time */ Time_PreAdjust(); return; } else if (pressedkey != NOKEY) { return; } } } else { /* PWR and BKP clocks selection ------------------------------------------*/ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Initialize Date structure */ date_s.month = (BKP_ReadBackupRegister(BKP_DR3) & 0xFF00) >> 8; date_s.day = (BKP_ReadBackupRegister(BKP_DR3) & 0x00FF); date_s.year = BKP_ReadBackupRegister(BKP_DR2); daycolumn = BKP_ReadBackupRegister(BKP_DR4); dayline = BKP_ReadBackupRegister(BKP_DR5); if(RTC_GetCounter() / 86399 != 0) { for(i = 0; i < (RTC_GetCounter() / 86399); i++) { Date_Update(); } RTC_SetCounter(RTC_GetCounter() % 86399); LCD_DisplayStringLine(Line8, " Days elapsed "); tmp = i/100; LCD_DisplayChar(Line8, 276,(tmp + 0x30)); tmp = ((i%100)/10); LCD_DisplayChar(Line8, 260,(tmp + 0x30)); tmp = ((i%100)%10); LCD_DisplayChar(Line8, 244,(tmp + 0x30)); LCD_DisplayStringLine(Line9, " Press SEL "); while(ReadKey() != SEL) { } LCD_ClearLine(Line8); LCD_ClearLine(Line9); LCD_DisplayStringLine(Line9, "Push SEL to Continue"); Date_Display(date_s.year, date_s.month, date_s.day); while(ReadKey() != SEL) { } BKP_WriteBackupRegister(BKP_DR4, daycolumn); BKP_WriteBackupRegister(BKP_DR5, dayline); } } }