extern void KEYS_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
/* config the extiline(PB0) clock and AFIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);
/* Configyre P[A|B|C|D|E]0 NIVC */
NVIC_InitStruct.NVIC_IRQChannel = EXTI4_15_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPriority = 0x00;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
/* EXTI line gpio config(PF7) */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_2;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOF, &GPIO_InitStruct);
/* EXTI line(PF7) mode config */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOF, EXTI_PinSource7);
EXTI_InitStruct.EXTI_Line = EXTI_Line7;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//EXTI_Trigger_Falling;// | EXTI_Trigger_Rising;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
}
我设置了PF7为外部中断,触发方式为上升沿和下降沿。在ISR里面,我需要对上升沿和下降沿有不同的处理,所以需要分辨当前触发了中断时是上升沿还是下降沿,不知道代码怎么写,最好是用到固件库的方式,不要直接操作寄存器,这样移植性好点。现在我正在找合适的范例,不知道找不找得到。 |