相关初始化程序为: /******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { int len; u8 bufs[50]; #ifdef DEBUG debug(); #endif
/* System Clocks Configuration */ RCC_Configuration();
/* NVIC configuration */ NVIC_Configuration();
/* SysTick end of count event each 1ms with input clock equal to 9MHz (HCLK/8, default) */
TIM_Configuration(); GPIO_Configuration();
if (BKP_ReadBackupRegister(BKP_DR1) != 0x5AA5) { /* Backup data register value is not correct or not yet programmed (when the first time the program is executed) */
/* Adjust time by values entred by the user on the hyperterminal */ Time_Adjust(secondcount);
BKP_WriteBackupRegister(BKP_DR1, 0x5AA5); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { //printf("
Power On Reset occurred...."); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { //printf("
External Reset occurred...."); }
//printf("
No need to configure RTC...."); /* Wait for RTC registers synchronization */ RTC_WaitForSynchro();
/* Enable the RTC Second */ RTC_ITConfig(RTC_IT_SEC, ENABLE); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); }
LcdInit(); InitKey();
/* Initialize the SPI FLASH driver */ SPI_FLASH_Init();
#ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ #ifdef VECT_DFU NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x4000); #else NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif #endif
/* Configure one bit for preemption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE);
/* Reset Backup Domain */ BKP_DeInit();
/* Enable the LSI OSC */ RCC_LSICmd(ENABLE); /* Wait till LSI is ready */ while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {} /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/* 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);
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask();
/* Set RTC prescaler: set RTC period to 1sec */ RTC_SetPrescaler(40000);
/* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask();
/* To output second signal on Tamper pin, the tamper functionality must be disabled (by default this functionality is disabled) */ BKP_TamperPinCmd(DISABLE);
/* Enable the RTC Second Output on Tamper Pin */ BKP_RTCOutputConfig(BKP_RTCOutputSource_Second); }
int RTC_LSE_Configuration(void) { u32 tick1,tick2;