external interrupt programming

Thread Starter


Joined Jul 31, 2014
i am programming interrupt 0 using 8051
my task is.. explained in the circuit diagram as follows

when ever till the push button pressed the led should goes low which is connected at P2.1

but the problem i am facing is if long press the button the led toggles quickly and repeatedly... but i want that till the button is pressed the led should be off

here is my code

sbit a=P2^1;                                                            // for led
void ext(void) interrupt 0
void main()
  IE=0x81;                                                      // using external 0 interrupt


Last edited by a moderator:


Joined Apr 24, 2011
I would add two resistors to this: first one to limit the current thru the LED. As is, you have an uncontrolled amount of current there. That could get huge and let smoke out.

Next you need one at the switch input to the + power so the input can change states.

Last, add bypass caps to all the chips so they work reliably.

Now for the code: I don't use this device so I am not sure if the interrupt fires for the + or the - input, but I betcha it doesn't fire on the level. Your code needs to be "stuck" in the interrupt section to keep the LED off, I do not believe it does that.


Joined Feb 24, 2006
Port 2 has internal weak pullups (40K approx). External interrupts can be either edge triggered or level triggered. Whichever way you do it you must clear the source of the interrupt in the service routine or you will execute the service routine repeatedly