16F84A and RB0 interrupt

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
twelveeyedfish
Posts: 2
Joined: Thu Mar 16, 2006 3:50 pm
Location: Huddersfield
Contact:

16F84A and RB0 interrupt

Post by twelveeyedfish »

I have been trying for several hours to get this RB0 interrupt to work and i'm not sure why. Having a little trouble with it... thought perhaps you might have some ideas.

The program achieves nothing inparticular. Pressing the RB0 button should simply clear the PORTA leds. There is also a routine flashing bit7 of PORTB - the aim of the excercise - identifying which interrupt was tripped.

#include<io16f84.h>
//#include <htc.h>
#pragma vector=0x04 //sets interrupt vector
__interrupt void my_ISR(void);


void main(void)
{
unsigned int i;
RP0=1;
TRISB=0x01; //portB output/input
TRISA=0x00; //porta output
OPTION=0x07;
RP0=0;
TMR0=0x00; //clear timer
PORTA=0x00;
PORTB=0x00;
INTCON=0xB0; //sets up interrupt options

while (1)
{
for (i=0;i<32000;i++);
PORTA=PORTA+1; //arbitrarily count up on PORTA
} //end of while(1)

} //end of void(main)void


//Interrupt service routine
//only runs when timer overflows/RB0 is pressed

__interrupt void my_ISR(void)
{
GIE=0; //disables interrupts for a bit
if(T0IE==1) //if timer causes interrupt
{
T0IF=0; //clear flag
PORTB=PORTB^0x80; //toggle bit7
TMR0=0x00; //ensure timer is cleared
}
if(INTF==1) //if RB0 caused interrupt
{
INTF=0; //clear flag
PORTA=0x00; //set PORTA at zero
}
else;

GIE=1; //re enables interrupts
} //end of void main(void)

:) thank you :)
Fish

User avatar
Steve
Matrix Staff
Posts: 3421
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

Hi,

Some of our development boards have an issue where the RB0 interrupt cannot be triggered by a press of the RB0 switch. This is because the dev board has quite a few peripherals connected to port B i/o lines and this affects the on/off voltage of the switches - so pressing the switch does not bring the voltage fully up to 5V.

If you look at the datasheet of the PICmicro you are using, you will see that the input "on" voltage threshold is lower that the RB0 interrupt "on" voltage. This explains why the switch works as a general i/o line, but doesn't when it is used for interrupt purposes.

To get around this, you can get relatively clean access to RB0 via the screw terminals on the right-hand side of the board and the interrupt will work.

twelveeyedfish
Posts: 2
Joined: Thu Mar 16, 2006 3:50 pm
Location: Huddersfield
Contact:

Post by twelveeyedfish »

Well spotted. it's now working using an alternative 5v source.

Have you devised a workaround for this. Have only just experimented but having played around with the multimeter turning the LCD on seems to fix it. Either way... problem solved :o) thanks!

Granted though i haven't looked at the datasheet for about 3 months!

Cheers for your help.
Fish

Post Reply