/** * @brief Returns the date entered by user, using demoboard keys. * @param None * @retval None */ void Date_Adjust(void) { /* Display the current Date */ Date_Display(); /* Change the current Date */ Date_Regulate(); }
/******************************************************************************* * Function Name : Date_PreAdjust * Description : Pre-Adjusts the current date (MM/DD/YYYY). * Input : None * Output : None * Return : None *******************************************************************************/ static void Date_PreAdjust(void) { uint32_t tmp = 0, pressedkey = 0; /* Clear the LCD */ LCD_Clear(White); LCD_SetBackColor(Blue); LCD_SetTextColor(White); if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { 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(); /* Clear the LCD */ LCD_Clear(White); return; } else if (pressedkey != NOKEY) { return; } } } else { /* Display the current date */ Date_Display(date_s.year, date_s.month, date_s.day); /* Change the current date */ Date_Regulate(); BKP_WriteBackupRegister(BKP_DR2, date_s.year); tmp = date_s.month << 8; tmp |= date_s.day; BKP_WriteBackupRegister(BKP_DR3, tmp); BKP_WriteBackupRegister(BKP_DR4, daycolumn); BKP_WriteBackupRegister(BKP_DR5, dayline); } }
/** * @brief Setting up the time by Serial USART1. * @param None * @retval None */ void RTC_SetTimeBySerial(void) { if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { /* Backup data register value is not correct or not yet programmed (when the first time the program is executed) */ printf("\r\n * Begin RTC initialization"); /* RTC Configuration */ RTC_Configuration(); printf("\r\n * Please set calendar"); /* setup year, month, date in 4, 2, 2 digits each */ Date_Regulate(); printf("\r\n * Please set time"); /* Adjust time by values entered by the user on the hyperterminal */ Time_Adjust(); BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { printf("\r\n * Power On Reset occurred...."); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { printf("\r\n\n * External Reset occurred...."); } printf("\r\n * No need to configure RTC...."); /* Check whether we've written year or month or day value before */ if(BKP_ReadBackupRegister(BKP_DR2) == 0x0000 || BKP_ReadBackupRegister(BKP_DR3) == 0x0000) { /* setup year, month, date in 4, 2, 2 digits each */ Date_Regulate(); } else { uint16_t YY, MD; YY = BKP_ReadBackupRegister(BKP_DR2); MD = BKP_ReadBackupRegister(BKP_DR3); int month, day; if( (MD / 1000) % 10 == 0) { month = (MD / 100) % 10; } else { month = (MD / 1000) % 10 + (MD / 100) % 10 ; } if( (MD / 10) % 10 == 0 ) { day = MD % 10; } else { day = MD - (MD / 100) * 100; } printf("\r\n\n Previous written calendar data found !"); printf("\r\n Written values are as follows :"); printf("\r\n Year : %d, Month : %d, Day : %d", YY, month, day); printf("\r\n Above calendar datas will be used to set current calendar automatically\r\n"); TranslateIntoYear(YY); TranslateIntoMonth(month); TranslateIntoDay(day); } /* NVIC MUST BE CONFIGURED before branch into power on reset */ NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; /* Configure one bit for preemption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* Enable the RTC Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0xFF; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Configure EXTI Line17 (RTC Alarm)to generate an interrupt on rising edge */ EXTI_ClearITPendingBit(EXTI_Line17); EXTI_InitStructure.EXTI_Line = EXTI_Line17; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_Init(&EXTI_InitStructure); /* Wait for RTC registers synchronization */ RTC_WaitForSynchro(); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Alarm in 3 second */ //RTC_SetAlarm(3); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Enable the RTC Second, RTC Alarm interrupt */ RTC_ITConfig(RTC_IT_SEC || RTC_IT_ALR, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); } #ifdef RTCClockOutput_Enable /* Enable PWR and BKP clocks */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); /* Disable the Tamper Pin */ BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper functionality must be disabled */ /* Enable RTC Clock Output on Tamper Pin */ BKP_RTCOutputConfig(BKP_RTCOutputSource_Second); #endif /* Clear reset flags */ RCC_ClearFlag(); }