/* Set up NVIC when I/O pins are configured as external interrupts. */
NVIC_EnableIRQ(EINT0_IRQn);
NVIC_EnableIRQ(EINT1_IRQn);
NVIC_EnableIRQ(EINT2_IRQn);
NVIC_EnableIRQ(EINT3_IRQn);
return;
}其函数初始化了I/O口并设置了I/O口中断功能,然后使能中断。
void GPIOSetInterrupt( uint32_t portNum, uint32_t bitPosi, uint32_t sense,
uint32_t single, uint32_t event )
{
switch ( portNum )
{
case PORT0:
if ( sense == 0 )
{
LPC_GPIO0->IS &= ~(0x1<<bitPosi);
/* single or double only applies when sense is 0(edge trigger). */
if ( single == 0 )
LPC_GPIO0->IBE &= ~(0x1<<bitPosi);
else
LPC_GPIO0->IBE |= (0x1<<bitPosi);
}
else
LPC_GPIO0->IS |= (0x1<<bitPosi);
if ( event == 0 )
LPC_GPIO0->IEV &= ~(0x1<<bitPosi);
else
LPC_GPIO0->IEV |= (0x1<<bitPosi);
break;
case PORT1:
if ( sense == 0 )
{
LPC_GPIO1->IS &= ~(0x1<<bitPosi);
/* single or double only applies when sense is 0(edge trigger). */
if ( single == 0 )
LPC_GPIO1->IBE &= ~(0x1<<bitPosi);
else
LPC_GPIO1->IBE |= (0x1<<bitPosi);
}
else
LPC_GPIO1->IS |= (0x1<<bitPosi);
if ( event == 0 )
LPC_GPIO1->IEV &= ~(0x1<<bitPosi);
else
LPC_GPIO1->IEV |= (0x1<<bitPosi);
break;
case PORT2:
if ( sense == 0 )
{
LPC_GPIO2->IS &= ~(0x1<<bitPosi);
/* single or double only applies when sense is 0(edge trigger). */
if ( single == 0 )
LPC_GPIO2->IBE &= ~(0x1<<bitPosi);
else
LPC_GPIO2->IBE |= (0x1<<bitPosi);
}
else
LPC_GPIO2->IS |= (0x1<<bitPosi);
if ( event == 0 )
LPC_GPIO2->IEV &= ~(0x1<<bitPosi);
else
LPC_GPIO2->IEV |= (0x1<<bitPosi);
break;
case PORT3:
if ( sense == 0 )
{
LPC_GPIO3->IS &= ~(0x1<<bitPosi);
/* single or double only applies when sense is 0(edge trigger). */
if ( single == 0 )
LPC_GPIO3->IBE &= ~(0x1<<bitPosi);
else
LPC_GPIO3->IBE |= (0x1<<bitPosi);
}
else
LPC_GPIO3->IS |= (0x1<<bitPosi);
if ( event == 0 )
LPC_GPIO3->IEV &= ~(0x1<<bitPosi);
else
LPC_GPIO3->IEV |= (0x1<<bitPosi);
break;
default:
break;
}
return;
}该函数配置了GPIOnIS、GPIOnIBE、GPIOnIEV等寄存器,设置了中断的边沿触发或者电平触发和边沿方式或者电平方式触发等内容。