//初始化
GPIO_InitTypeDef Gpio_strcut;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB,ENABLE);
Gpio_strcut.GPIO_Pin = GPIO_Pin_6;
Gpio_strcut.GPIO_Mode = GPIO_Mode_IN;
Gpio_strcut.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &Gpio_strcut);
//中断配置
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, GPIO_Pin_6);
EXTI_InitStructure.EXTI_Line = EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;//ÓÅÏȼ¶×îµÍ
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//中断响应函数
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line6) != RESET)
{
delay_us(500);
if(EXTI_GetITStatus(EXTI_Line6) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line6);
}
}
} |