Hi All,
Just for future reference in this thread and to avoid complexity confusion for other readers, I thought i'd also post how you achieve the same thing using the mbed libraries:
// example of using InterruptIn
// - connect p6 to 3.3v to trigger an interrupt
#include "mbed.h"
DigitalOut led1(LED1);
DigitalOut led4(LED4);
InterruptIn button(p6);
void button_handler() {
led1 = !led1;
}
int main(void) {
button.rise(&button_handler);
while (1) {
led4 = !led4;
wait(0.25);
}
}
The full details at on the InterruptIn handbook page.
You could also mix and match; use the DigitalOut of the mbed library to control the LEDs, and the register-poking to setup and handle the interrupt. All depends on what you are trying to achieve.
Glad you got it working!
Simon
Hello,
I have a question about interrupts. I have a pushbutton connected at p6
and set it so that it lights up led1 whenever I press it. The program compiles fine since the status led (LED4)
is on. However the interrupt routine doesn’t work. Can somebody point what am I missing.
#include "mbed.h" #define LED1 (1 << 18) //#define LED2 (1 << 20) //#define LED3 (1 << 21) #define LED4 (1 << 23) #define BUTTON (1 << 8) int main(void) { //set led 1 and 2 pins as output LPC_GPIO1->FIODIR |= LED1 | LED4; //set button as input LPC_GPIO0->FIODIR &= ~BUTTON; LPC_GPIO1->FIOSET |= LED4; while (1) { } } // Setup External Interrupt void EINT3_init (void) { // Set PINSEL0 ( p6) for P0.8 as gpio LPC_PINCON->PINSEL0 &= ~(1 << 8); //set the interrupt for 0.8 for falling edge LPC_GPIOINT->IO0IntEnF |= (1<<8); NVIC_EnableIRQ(EINT3_IRQn ); } //EINT3 Handler void EINT3_IRQHandler(void) { //clear interrupt LPC_GPIOINT->IO0IntClr = (1<<8); //toggle led LPC_GPIO1->FIOSET |= LED1; }