下面给出一个应用例子。
/*-----------------------------------------------------------------------------------------------------*/
/* GPIO Interrupt Function Test */
/*-----------------------------------------------------------------------------------------------------*/
printf("P1.3 and P4.5 are used to test interrupt ......\n");
/* Configure P1.3 as Input mode and enable interrupt by rising edge trigger */
GPIO_SetMode(P1, BIT3, GPIO_PMD_INPUT);
GPIO_EnableInt(P1, 3, GPIO_INT_RISING);
NVIC_EnableIRQ(GPIO_P0P1_IRQn);
/* Configure P4.5 as Quasi-bidirection mode and enable interrupt by falling edge trigger */
GPIO_SetMode(P4, BIT5, GPIO_PMD_QUASI);
GPIO_EnableInt(P4, 5, GPIO_INT_FALLING);
NVIC_EnableIRQ(GPIO_P2P3P4_IRQn);
/* Waiting for interrupts */
不难发现一共三条语句:1,设置IO工作模式,2,使能对应的中断类型,3,设置中断请求。
另外注意到:嵌套向量中断控制器:Nested Vectored Interrupt Controller (NVIC)
|