Hi all, I am trying to use external interrupt with the following code using LPC1768 micro controller. I have connected P2.10 and P2.11 to switches and GPIO0 used to connect the LED's. When I press the switches no LED is going on Port 0. But after pressing reset the LEDs are glowing twice because of only reset button. And the code is shown below for your suggestion.
#include<LPC17xx.h>
#define EXTMODE0 0 #define EXTMODE1 1
#define EXTPOLAR0 0 #define EXTPOLAR1 1
#define EINT0_PIN 20 #define EINT1_PIN 22
void delay(unsigned int value) { unsigned int i, j; for(i = 0; i < value; i++) for(j = 0; j < 2500; j++); }
void EINT0_IRQHandler() { LPC_SC->EXTINT = (1<<0); //clearing interrupt bit LPC_GPIO0->FIOSET = 0xffffffff; delay(1000); LPC_GPIO0->FIOCLR = 0xffffffff; delay(1000); }
void EINT1_IRQHandler() { LPC_SC->EXTINT = (1<<1); //clearing interrupt bit LPC_GPIO0->FIOSET = 0xffffffff; delay(1000); LPC_GPIO0->FIOCLR = 0xffffffff; delay(1000); }
int main() { LPC_SC->EXTMODE = (0<<EXTMODE0)|(0<<EXTMODE1); //level-sensitive mode LPC_SC->EXTPOLAR = (0<<EXTPOLAR0)|(0<<EXTPOLAR1); //low active state LPC_PINCON->PINSEL4 = (1<<EINT0_PIN)|(1<<EINT1_PIN); //switches connected to P2.10 and P2.11
LPC_GPIO0->FIODIR = 0xffffffff;
NVIC_EnableIRQ(EINT0_IRQn); NVIC_EnableIRQ(EINT1_IRQn);
while(1); }
www.danlhenry.com/.../keil_code.png
Could you try reading the posting tip and instructions for posting source code?
Do you have pull-ups on the switches? How are they wired?
Considered using the debugger to trace interaction
Dear All,
I am posting the source code in the format specified in the trailing message. And also switches are connected through the pull up resistor.
#include<LPC17xx.h> #define EXTMODE0 0 #define EXTMODE1 1 #define EXTPOLAR0 0 #define EXTPOLAR1 1 #define EINT0_PIN 20 #define EINT1_PIN 22 void delay(unsigned int value) { unsigned int i, j; for(i = 0; i < value; i++) for(j = 0; j < 2500; j++); } void EINT0_IRQHandler() { LPC_SC->EXTINT = (1<<0); //clearing interrupt bit LPC_GPIO0->FIOSET = 0xffffffff; delay(1000); LPC_GPIO0->FIOCLR = 0xffffffff; delay(1000); } void EINT1_IRQHandler() { LPC_SC->EXTINT = (1<<1); //clearing interrupt bit LPC_GPIO0->FIOSET = 0xffffffff; delay(1000); LPC_GPIO0->FIOCLR = 0xffffffff; delay(1000); } int main() { LPC_SC->EXTMODE = (0<<EXTMODE0)|(0<<EXTMODE1); //level-sensitive mode LPC_SC->EXTPOLAR = (0<<EXTPOLAR0)|(0<<EXTPOLAR1); //low active state LPC_PINCON->PINSEL4 = (1<<EINT0_PIN)|(1<<EINT1_PIN); //switches connected to P2.10 and P2.11 LPC_GPIO0->FIODIR = 0xffffffff; NVIC_EnableIRQ(EINT0_IRQn); NVIC_EnableIRQ(EINT1_IRQn); while(1); } </prep