I'm hoping someone on this forum might be able to help me with programming the external interrupt RB0/INT on the PIC16F84a. I'm using the V2 development board with 'Assembly for PICMicro' V2 CD but that shouldn't be the problem. All the exercises in the tutorials functions correctly. Below I have created a very simple program that should initialise the interrupt and light the A0 LED. When a RB0 interrupt is triggered it should call the interrupt routine that turns of the LED. It's that simple but I can't make it work. Can anyone see an obvious problem that I have missed. Any help would be much appreciated.
Cheers
Graham
; The following line embeds configuration data into the PICmicro
__CONFIG H'3FF9' ; xt mode
; At start LED A0 should illunimate. If RB0 is triggered this should
; call the ISR and turn off the LED.
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include "C:\PROGRA~1\MPLAB\P16F84a.INC"
org 0
goto start
org 4
bcf STATUS,RP0 ;goto bank 0
movlw 0x00
movwf PORTA ;turn off LED A0
bcf INTCON,INTF ;clear interrup flag
retfie
start
bcf INTCON,INTF ;clear interrupt flag
bsf INTCON,INTE ;enable RB0 interrupt
bsf INTCON,GIE ;enable global interrupt
bsf STATUS, RP0 ;goto bank 1
movlw 0xff
movwf TRISB ;config portb as inputs
movlw 0x00
movwf TRISA ;config porta as outputs
bcf STATUS, RP0 ;goto bank 0
movlw 0x01
movwf PORTA ;turn on LED A0
wait
movlw 0x01 ;loop
goto wait
END
RB0/INT 16F84a Programing Problem
-
- Valued Contributor
- Posts: 548
- Joined: Tue Jun 26, 2007 11:23 am
- Has thanked: 6 times
- Been thanked: 44 times
Re: RB0/INT 16F84a Programing Problem
Hello Graham,
I could not see any problems with your program and was eventually able to make it work without any modifications.
The problem might be caused by the voltages that are generated by the switches on the development board. The interrupt circuit works at slightly different voltage levels to the normal port input and the switch circuit does not seem to achieve the voltage that would guarantee a high level. The program worked when the RB0 input was momentarily shorted to the Vdd pin with a wire link.
Another option that worked on my V3 development board was to turn on portb pull-ups by adding the following line into the initialisation code while accessing bank 1:
bcf OPTION_REG, NOT_RBPU ;enable PORTB pull-ups
I could not see any problems with your program and was eventually able to make it work without any modifications.
The problem might be caused by the voltages that are generated by the switches on the development board. The interrupt circuit works at slightly different voltage levels to the normal port input and the switch circuit does not seem to achieve the voltage that would guarantee a high level. The program worked when the RB0 input was momentarily shorted to the Vdd pin with a wire link.
Another option that worked on my V3 development board was to turn on portb pull-ups by adding the following line into the initialisation code while accessing bank 1:
bcf OPTION_REG, NOT_RBPU ;enable PORTB pull-ups
-
- Posts: 35
- Joined: Fri Dec 26, 2008 4:02 pm
Re: RB0/INT 16F84a Programing Problem
Thanks for the help. I finally got to the bottom of the problem.
I'm using the v2 Development Board and I noticed that sometimes the RB0 interrupt worked in my programs and other times it didn't. However, most of the time it didn't work.
With reference to the voltage levels I've looked up the specified trigger levels for the 16F84a.
Input low (max) 0.2 x Vss
Input high (min) 0.36 x Vss
I measued the low/high voltages on RB0 and found them to be 0.2 and 3.2 volts which are within limits when Vss was set to 5-volts
However, I decided to bridge the 390ohm pull-up resister for RB0 with a 670ohm raising the high state voltage from 3.2 to 3.6 volts and this appears to resolved the problem.
I'm using the v2 Development Board and I noticed that sometimes the RB0 interrupt worked in my programs and other times it didn't. However, most of the time it didn't work.
With reference to the voltage levels I've looked up the specified trigger levels for the 16F84a.
Input low (max) 0.2 x Vss
Input high (min) 0.36 x Vss
I measued the low/high voltages on RB0 and found them to be 0.2 and 3.2 volts which are within limits when Vss was set to 5-volts
However, I decided to bridge the 390ohm pull-up resister for RB0 with a 670ohm raising the high state voltage from 3.2 to 3.6 volts and this appears to resolved the problem.