以PA12口下降沿产生中断为例
//注:在这个初始化前应使能GPIOA的时钟!
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure; //EXTI初始化结构定义
NVIC_InitTypeDef NVIC_InitStructure;
//IRQ引脚初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化
//使能GPIO中断功能
EXTI_ClearITPendingBit(EXTI_Line12);//清除中断标志
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource12);//管脚选择
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//事件选择
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//触发模式
EXTI_InitStructure.EXTI_Line = EXTI_Line12; //线路选择
EXTI_InitStructure.EXTI_LineCmd = ENABLE;//启动中断
EXTI_Init(&EXTI_InitStructure);//初始化
//中断设置
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//占先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //启动
NVIC_Init(&NVIC_InitStructure); //初始化
中断例程:
//GPIO中断(PA12)处理函数
void EXTI15_10_IRQHandler(void)
{
//....
EXTI_ClearITPendingBit(EXTI_Line12);//清除中断标志
}
|
|