external interrupt programming

Thread Starter

bobparihar

Joined Jul 31, 2014
93
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

Code:
#include<reg51.h>
sbit a=P2^1;                                                            // for led
void ext(void) interrupt 0
{
  a=0;
 
}
void main()
{
  IE=0x81;                                                      // using external 0 interrupt
 
  while(1)
  {
  a=1;
  }
}
 

Attachments

Last edited by a moderator:

ErnieM

Joined Apr 24, 2011
8,040
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.
 

Papabravo

Joined Feb 24, 2006
13,551
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
 
Top