|
|
View previous topic :: View next topic |
Author |
Message |
SerialGmr8
Joined: 30 Nov 2007 Posts: 13
|
PIC 16F877A interrupt on B4 strange activity |
Posted: Fri May 23, 2008 9:01 am |
|
|
Greetings programming gurus.
Im trying to interrupt when a change (hi/low) is detected on PIN B4 on my pic16f877a. My code in entirety is as follows;
Code: |
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
int8 value = 0;
#INT_RB
void portchange_isr ()
{
value = input(PIN_B4);
}
void main()
{
output_low(pin_c5);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RB);
set_tris_B(0xF0);
while(1)
{
if (value == 0)
{
output_low(pin_c5);
}
else
{
output_high(pin_c5);
}
}
}
//IDE VERSION 4.057
//PCM VERSION 4.057
//PCB VERSION 4.057
|
The issue I am having is as follows.
I know that the interrupt routine gets called and executed, however i have PIN_C5 connected to an LED. This LED seems to stay on all the time. I know the interrupt gets called, because when I toggle (with a wire) between 5v and zer0 volts at b4, the led brightens and dims accordingly.
It almost seems like I have a floating issue, but the only wires connected to my chip are grounds and the vcc. Might anyone be able to shed some light on this situation for me ?
Best Regards,
SerialGmr8 |
|
|
Ttelmah Guest
|
|
Posted: Fri May 23, 2008 9:26 am |
|
|
As you have it setup, B4, B5, B6, and B7, will all trigger the interrupt. If these are not pulled to a rail, then you will get spurious triggers. Enable the portb pullups on the port, so these pins are all pulled high, before enabling the interrupt, to avoid this.
Best Wishes |
|
|
SerialGmr8
Joined: 30 Nov 2007 Posts: 13
|
|
Posted: Fri May 23, 2008 9:48 am |
|
|
Thank you Ttelmah. All is well with my code
Regards,
SerialGmr8 |
|
|
|
|
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
|