STM32F4——RTC实时时钟
时间:11-09
来源:互联网
点击:
A(u8 week,u8 hour,u8 min,u8 sec){ EXTI_InitTypeDef EXTI_InitStructure;RTC_AlarmTypeDef RTC_AlarmTypeInitStructure;RTC_TimeTypeDef RTC_TimeTypeInitStructure;RTC_AlarmCmd(RTC_Alarm_A,DISABLE);//关闭闹钟A RTC_TimeTypeInitStructure.RTC_Hours=hour;//小时RTC_TimeTypeInitStructure.RTC_Minutes=min;//分钟RTC_TimeTypeInitStructure.RTC_Seconds=sec;//秒RTC_TimeTypeInitStructure.RTC_H12=RTC_H12_AM;RTC_AlarmTypeInitStructure.RTC_AlarmDateWeekDay=week;//星期RTC_AlarmTypeInitStructure.RTC_AlarmDateWeekDaySel=RTC_AlarmDateWeekDaySel_WeekDay;//按星期闹RTC_AlarmTypeInitStructure.RTC_AlarmMask=RTC_AlarmMask_None;//精确匹配星期,时分秒RTC_AlarmTypeInitStructure.RTC_AlarmTime=RTC_TimeTypeInitStructure;RTC_SetAlarm(RTC_Format_BIN,RTC_Alarm_A,&RTC_AlarmTypeInitStructure);RTC_ClearITPendingBit(RTC_IT_ALRA);//清除RTC闹钟A的标志EXTI_ClearITPendingBit(EXTI_Line17);//清除LINE17上的中断标志位 RTC_ITConfig(RTC_IT_ALRA,ENABLE);//开启闹钟A中断RTC_AlarmCmd(RTC_Alarm_A,ENABLE);//开启闹钟A EXTI_InitStructure.EXTI_Line = EXTI_Line17;//LINE17EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//中断事件EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //上升沿触发 EXTI_InitStructure.EXTI_LineCmd = ENABLE;//使能LINE17EXTI_Init(&EXTI_InitStructure);//配置NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;//抢占优先级1NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//子优先级2NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能外部中断通道NVIC_Init(&NVIC_InitStructure);//配置}
周期唤醒配置:
void RTC_Set_WakeUp(u32 wksel,u16 cnt){ EXTI_InitTypeDef EXTI_InitStructure;RTC_WakeUpCmd(DISABLE);//关闭WAKE UPRTC_WakeUpClockConfig(wksel);//唤醒时钟选择RTC_SetWakeUpCounter(cnt);//设置WAKE UP自动重装载寄存器RTC_ClearITPendingBit(RTC_IT_WUT); //清除RTC WAKE UP的标志EXTI_ClearITPendingBit(EXTI_Line22);//清除LINE22上的中断标志位 RTC_ITConfig(RTC_IT_WUT,ENABLE);//开启WAKE UP 定时器中断RTC_WakeUpCmd( ENABLE);//开启WAKE UP 定时器 EXTI_InitStructure.EXTI_Line = EXTI_Line22;//LINE22EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//中断事件EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //上升沿触发 EXTI_InitStructure.EXTI_LineCmd = ENABLE;//使能LINE22EXTI_Init(&EXTI_InitStructure);//配置NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;//抢占优先级1NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//子优先级2NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能外部中断通道NVIC_Init(&NVIC_InitStructure);//配置}
相关的中断服务函数:
//RTC闹钟中断服务函数void RTC_Alarm_IRQHandler(void){ if(RTC_GetFlagStatus(RTC_FLAG_ALRAF)==SET)//ALARM A中断{RTC_ClearFlag(RTC_FLAG_ALRAF);//清除中断标志printf("ALARM A!\r\n");} EXTI_ClearITPendingBit(EXTI_Line17); //清除中断线17的中断标志 }//RTC WAKE UP中断服务函数void RTC_WKUP_IRQHandler(void){ if(RTC_GetFlagStatus(RTC_FLAG_WUTF)==SET)//WK_UP中断{ RTC_ClearFlag(RTC_FLAG_WUTF); //清除中断标志LED1=!LED1; } EXTI_ClearITPendingBit(EXTI_Line22);//清除中断线22的中断标志 }
STM32F4RTC实时时 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)