extern "C" void GINT0_IRQHandler(void) { LPC_GINT0->CTRL |= (1<<0); // clear interrupt status // Code like LED1 toggle. // } extern "C" void GINT1_IRQHandler(void) { LPC_GINT1->CTRL |= (1<<0); // clear interrupt status // Code for LED2 toggle // } void gint_init(void) { LPC_SYSCON->SYSAHBCLKCTRL0 |= (1 << 19); // enable GINT LPC_GINT0->PORT_ENA[0] = 0x0000FFFF ; // port 0 16pins(expand) LPC_GINT0->PORT_POL[0] = 0xFFFF0000; // falling edge LPC_GINT0->CTRL |= (1<<0) | (0<<2); // interrupt active, OR condition , edge trigger LPC_GINT1->PORT_ENA[0] = 0x0000FFFF ; // port 0 16pin(expand) LPC_GINT1->PORT_POL[0] = 0xFFFFFFFF; // rising edge LPC_GINT1->CTRL |= (1<<0) | (0<<2) ; // interrupt active, OR condition , edge trigger NVIC_EnableIRQ(GINT0_IRQn); // enable GINT0 interrupt NVIC_EnableIRQ(GINT1_IRQn); // enable GINT1 interrupt } |
void gint_update(void) { LPC_SYSCON->SYSAHBCLKCTRL0 |= (1 << 19); // enable GINT LPC_GINT0->PORT_ENA[0] = 0x0000FFFF ; // port 0 16pins(expand) // Set the mask for the current button state (pseudocode) LPC_GINT0->PORT_POL[0] = 0x00000000; // blank mask for (int i = 0; i < 16; i++) { int shouldSetFallingEdgeBit = false == buttonIsPressed(i); LPC_GINT0->PORT_POL[0] |= (shouldSetFallingEdgeBit << i); } LPC_GINT0->CTRL |= (1<<0) | (0<<2); // interrupt active, OR condition , edge trigger NVIC_EnableIRQ(GINT0_IRQn); // enable GINT0 interrupt } extern "C" void GINT0_IRQHandler(void) { LPC_GINT0->CTRL |= (1<<0); // clear interrupt status // Poll the current button state, take appropriate action, store the button state for future use // // update the mask so that new button presses or releases will be handled gint_update(); } |