STM8L EXITB一個埠兩個中斷的實現
阿新 • • 發佈:2019-01-22
void EXTI_Config(void)
{
EXTI_DeInit();
EXTI_SetPinSensitivity(EXTI_Pin_5,EXTI_Trigger_Falling);
ITC_SetSoftwarePriority(EXTI5_IRQn, ITC_PriorityLevel_1);
GPIO_Init(KEY_PORT, KEY_RT_PIN, GPIO_Mode_In_PU_IT);
EXTI_SetPinSensitivity(EXTI_Pin_3,EXTI_Trigger_Falling);
ITC_SetSoftwarePriority(EXTI3_IRQn,ITC_PriorityLevel_1);
GPIO_Init(GPIOB,GPIO_Pin_3,GPIO_Mode_In_FL_IT );
disableInterrupts(); //關閉中斷 //處理事件
EXTI_ClearITPendingBit(EXTI_IT_PortB ); //清除標誌位
enableInterrupts(); //使能全域性中斷
{
EXTI_DeInit();
EXTI_SetPinSensitivity(EXTI_Pin_5,EXTI_Trigger_Falling);
ITC_SetSoftwarePriority(EXTI5_IRQn, ITC_PriorityLevel_1);
GPIO_Init(KEY_PORT, KEY_RT_PIN, GPIO_Mode_In_PU_IT);
EXTI_SetPinSensitivity(EXTI_Pin_3,EXTI_Trigger_Falling);
ITC_SetSoftwarePriority(EXTI3_IRQn,ITC_PriorityLevel_1);
GPIO_Init(GPIOB,GPIO_Pin_3,GPIO_Mode_In_FL_IT );
disableInterrupts(); //關閉中斷 //處理事件
EXTI_ClearITPendingBit(EXTI_IT_PortB ); //清除標誌位
enableInterrupts(); //使能全域性中斷
}
中斷部分:
extern bool UserButton2;
INTERRUPT_HANDLER(EXTI3_IRQHandler, 11)
{
while(GPIO_ReadInputDataBit(GPIOB,GPIO_PIN_3)==0)
{
//UserButton2 = TRUE;
break;
}
EXTI_ClearITPendingBit(EXTI_IT_PortB);
EXTI_ClearITPendingBit(EXTI_IT_Pin3);
}
INTERRUPT_HANDLER(EXTI5_IRQHandler, 13)
{
u16 x =0;
while(GPIO_ReadInputDataBit(GPIOB,GPIO_PIN_5)==0)
{
x++;
Delay_(5);
if(x==300)
{
x =0; UserButton2 = TRUE;
break;
}
}
EXTI_ClearITPendingBit(EXTI_IT_PortB);
EXTI_ClearITPendingBit(EXTI_IT_Pin5);
}