CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem Using External Interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
leels



Joined: 16 Feb 2006
Posts: 4

View user's profile Send private message

Problem Using External Interrupt
PostPosted: Mon Mar 13, 2006 10:33 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 13, 2006 10:45 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: Problem Using External Interrupt
PostPosted: Mon Mar 13, 2006 10:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 13, 2006 10:56 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 13, 2006 11:07 am     Reply with quote

Here's an example program that might help:
http://www.ccsinfo.com/forum/viewtopic.php?t=17041&start=1
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Mon Mar 13, 2006 11:39 am     Reply with quote

You might also find this thread on debouncing a switch useful
http://www.ccsinfo.com/forum/viewtopic.php?t=24103
leels



Joined: 16 Feb 2006
Posts: 4

View user's profile Send private message

PostPosted: Mon Mar 13, 2006 12:07 pm     Reply with quote

Thank you PCM programmer and kender.
The interrupt now works flawlessly.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group