程序如下:
void ex
ti_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
GPIO_InitStructure.GPIO_Pin=k_left|k_down|k_right;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource2);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; //´ò¿ªEXTI2µÄÈ«¾ÖÖжÏ
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //ÇÀÕ¼ÓÅÏȼ¶Îª0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //ÏìÓ¦ÓÅÏȼ¶Îª0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹÄÜ
NVIC_Init(&NVIC_InitStructure);
// GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource3);
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
// NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn; //´ò¿ªEXTI2µÄÈ«¾ÖÖжÏ
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //ÇÀÕ¼ÓÅÏȼ¶Îª0
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //ÏìÓ¦ÓÅÏȼ¶Îª0
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹÄÜ
// NVIC_Init(&NVIC_InitStructure);
//
// GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource4);
// //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
// NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; //´ò¿ªEXTI2µÄÈ«¾ÖÖжÏ
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //ÇÀÕ¼ÓÅÏȼ¶Îª0
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //ÏìÓ¦ÓÅÏȼ¶Îª0
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ʹÄÜ
// NVIC_Init(&NVIC_InitStructure);
//
/* ÉèÖÃÍⲿÖжϵÄģʽ */
EXTI_InitStructure.EXTI_Line=EXTI_Line2|EXTI_Line3|EXTI_Line4;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
0