涉及到 NVIC,GPIO,EXIT,AFIO 四个外设
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
NVIC_InitTypeDef NCIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NCIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQn;
NCIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NCIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NCIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NCIC_InitStructure);
```
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
//GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_InitStructure.EXTI_Line=EXTI_Line0;
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitStructure);`
```
void EXTI0_IRQHandler(void)
{
//确保是否产生了EXTI Line中断
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
Led_Toggle();// LED1 取反
//清除中断标志位
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
```