RTC_TimeTypeDef GetRTCTime; void RTC_Initializes(void) { RTC_InitTypeDef RTC_InitStructure; RTC_DateTimeTypeDef RTC_DateTimeStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); RCC_LSICmd(ENABLE); RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);//ÄÚ²¿ RCC_RTCCLKCmd(ENABLE); PWR_BackupAccessCmd(ENABLE); //????RTC RTC_WaitForSynchro(); if(RTC_ReadBackupRegister(RTC_BKP_DR0) != RTC_FLAG_BKP) { RTC_Configuration(); //??RTC RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; if(RTC_Init(&RTC_InitStructure) == ERROR) { while(1); //????? } RTC_DateTimeStructure.Year = 16; RTC_DateTimeStructure.Month = 6; RTC_DateTimeStructure.Date = 5; RTC_DateTimeStructure.Week = 7; RTC_DateTimeStructure.Hour = 10; RTC_DateTimeStructure.Minute = 0; RTC_DateTimeStructure.Second = 0; RTC_SetDateTime(RTC_DateTimeStructure); //?????RTC(2016?6?5? ?? 12:00:00) RTC_WriteBackupRegister(RTC_BKP_DR0, RTC_FLAG_BKP); //if(ON)ON=1;//????????? } else { #ifdef RTC_CLOCK_SOURCE_LSI RCC_LSICmd(ENABLE);//???? #endif RTC_WaitForSynchro(); //??RTC?RTC_APB???? } } void RTC_AlarmConfig(void) { RTC_TimeTypeDef RTC_TimeStructure; RTC_AlarmTypeDef RTC_AlarmStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); PWR_BackupAccessCmd(ENABLE); RCC_LSICmd(ENABLE); RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);//ÄÚ²¿ RCC_RTCCLKCmd(ENABLE); RTC_AlarmCmd(RTC_Alarm_A,DISABLE);//¹Ø±ÕÄÖÖÓA /* Get current time */ RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure); RTC_AlarmStructure.RTC_AlarmTime.RTC_H12=RTC_H12_AM; RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours=RTC_TimeStructure.RTC_Hours; RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes=RTC_TimeStructure.RTC_Minutes; RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds=RTC_TimeStructure.RTC_Seconds+5; if(RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds == 60)RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds=0; // // RTC_AlarmStructure.RTC_AlarmDateWeekDay=0x31; // RTC_AlarmStructure.RTC_AlarmDateWeekDaySel=0x00; // RTC_AlarmStructure.RTC_AlarmMask=0x00; // RTC_AlarmStructure.RTC_AlarmTime.RTC_H12=RTC_H12_AM; // // // RTC_SetAlarm(RTC_Format_BIN,RTC_Alarm_A,&RTC_AlarmStructure); RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31; RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date; RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay | RTC_AlarmMask_Minutes | RTC_AlarmMask_Hours; // RTC_AlarmStructure.RTC_AlarmTime=RTC_TimeTypeInitStructure; RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); /* Clear the Alarm A Pending Bit */ RTC_ClearITPendingBit(RTC_IT_ALRA); //Êä³öÉ趨µÄÄÖÖÓ»½ÐÑʱ¼ä // RTC_ITConfig(RTC_IT_ALRA, ENABLE); RTC_ITConfig(RTC_IT_ALRA, ENABLE); /* Enable the alarm */ RTC_AlarmCmd(RTC_Alarm_A, ENABLE); /* EXTI configuration */ EXTI_ClearITPendingBit(EXTI_Line17); EXTI_InitStructure.EXTI_Line = EXTI_Line17; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the RTC Alarm Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority=1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //PWR_BackupAccessCmd(DISABLE); } void RTC_IRQHandler(void) { RTC_TimeTypeDef RTC_TimeStructure; RTC_AlarmTypeDef RTC_AlarmStructure; SystemInit(); // RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); // PWR_BackupAccessCmd(ENABLE); // RCC_LSICmd(ENABLE); // RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);//ÄÚ²¿ // RCC_RTCCLKCmd(ENABLE); if (RTC_GetITStatus(RTC_IT_ALRA) != RESET) { RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure); RTC_AlarmStructure.RTC_AlarmTime.RTC_H12=RTC_H12_AM; RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours=RTC_TimeStructure.RTC_Hours; RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes=RTC_TimeStructure.RTC_Minutes; RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds=RTC_TimeStructure.RTC_Seconds+5; if(RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds == 60)RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds=0; RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31; RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date; RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay | RTC_AlarmMask_Minutes | RTC_AlarmMask_Hours; RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); RTC_ClearITPendingBit(RTC_IT_ALRA); } EXTI_ClearITPendingBit(EXTI_Line17); //PWR_BackupAccessCmd(DISABLE); } 进去一次后程序就停在了这里: |
评分
查看全部评分