|
#define LPC_GPIO0_BASE 0x2009C000
#define LPC_GPIO1_BASE 0x2009C020
#define LPC_GPIO2_BASE 0x2009C040
#define LPC_GPIO3_BASE 0x20098060
#define LPC_GPIO4_BASE 0x2009C080
typedef enum {
GPIOINT_PORT0, /*!< GPIO PORT 0 */
GPIOINT_PORT2 = 2 /*!< GPIO PORT 2 */
}LPC_GPIOINT_PORT_T;
#define LPC_GPIO ((LPC_GPIO_T *) LPC_GPIO0_BASE)
#define LPC_GPIOINT ((LPC_GPIOINT_T *) LPC_GPIOINT_BASE)
#define GPIO_INTERRUPT_PIN 17 /* GPIO pin number mapped to interrupt */
#define GPIO_INTERRUPT_PORT GPIOINT_PORT0 /* GPIO port number mapped to interrupt */
int main(void)
{
/* Generic Initialization */
SystemCoreClockUpdate();
/* Board_Init calls Chip_GPIO_Init and enables GPIO clock if needed,
Chip_GPIO_Init is not called again */
Board_Init();
Board_LED_Set(0, false);
/* Configure GPIO interrupt pin as input */
Chip_GPIO_SetPinDIRInput(LPC_GPIO, GPIO_INTERRUPT_PORT, GPIO_INTERRUPT_PIN);
/* Configure the GPIO interrupt */
Chip_GPIOINT_SetIntFalling(LPC_GPIOINT, GPIO_INTERRUPT_PORT, 1 << GPIO_INTERRUPT_PIN);
/* Enable interrupt in the NVIC */
NVIC_ClearPendingIRQ(GPIO_INTERRUPT_NVIC_NAME);
NVIC_EnableIRQ(GPIO_INTERRUPT_NVIC_NAME);
/* Wait for interrupts - LED will toggle on each wakeup event */
while (1) {
__WFI();
}
return 0;
}
不太明白这个函数中 形参 port的具体定义,一开始以为是P0~P4,但是看到enum里面只有 0和2,,瞬间傻了,不知道这个Port是干嘛的,而且这个Port形参每个IO口程序里面都有
STATIC INLINE void Chip_GPIO_SetPinDIRInput(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin)
{
pGPIO[port].DIR &= ~(1UL << pin);
}
STATIC INLINE void Chip_GPIOINT_SetIntFalling(LPC_GPIOINT_T *pGPIOINT, LPC_GPIOINT_PORT_T port, uint32_t pins)
{
if (port == GPIOINT_PORT0) {
pGPIOINT->IO0.ENF = pins;
} else {
pGPIOINT->IO2.ENF = pins;
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|