View previous topic :: View next topic |
Author |
Message |
leels
Joined: 16 Feb 2006 Posts: 4
|
Problem Using External Interrupt |
Posted: Mon Mar 13, 2006 10:33 am |
|
|
Hello All...
I am having a bit of problem trying to use the external interrupt on a PIC16F873A. I have the external interrupt port (pin b0) connected to the battery through a push button and a pull up resistor (15K) to the ground. I'm using the following routine to toggle a led everytime the pushbutton is activated.
#int_ext
void pushbutton_isr()
{
if(TransposeOn == 0)
{
output_high(LED_OUT_1);
TransposeOn = 1;
}
else if(TransposeOn == 1)
{
output_low(LED_OUT_1);
TransposeOn = 0;
}
}
I'm also using the following enables for the interrupts...
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
Now the problem is, the interrupt routine only seems to be working ONCE. So the first time I activate the pushbutton, the led lights but then any subsequent activation of the pushbutton does not seem to run the intrrupt service routine. So the led stays on. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 13, 2006 10:45 am |
|
|
Do you have a continuous loop after you enable interrupts ?
If not, add one as shown in bold below:
Quote: | enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(1); |
|
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
Re: Problem Using External Interrupt |
Posted: Mon Mar 13, 2006 10:49 am |
|
|
leels wrote: | a pull up resistor (15K) to the ground |
This is probably a typo, but a pull-up resistor can not be connected to the ground. If it is connected to the ground, it's a pull-down resistor. Just in case, check where your resistor is actually connected. |
|
|
leels
Joined: 16 Feb 2006 Posts: 4
|
|
Posted: Mon Mar 13, 2006 10:56 am |
|
|
1) I have a do{ }while(true) loop in the code.
2) Thank you for correcting the typo kender. It is a pull-down resistor connected between the pin b0 and ground. I'm quite sure that the circuit is correct. When I push the butteon, pin b0 gets high. When the button is not activated, the pin b0 stays low.
The datasheet for the controller mentions that the interrupt flag bit needs to be cleared by the code. Would this be a case? and how would I go about doing that?
Thanks for your help |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
|
leels
Joined: 16 Feb 2006 Posts: 4
|
|
Posted: Mon Mar 13, 2006 12:07 pm |
|
|
Thank you PCM programmer and kender.
The interrupt now works flawlessly. |
|
|
|