Hi everybody. I know there is a super extensive post on interrupts already on the forum, but I had a hard time getting any of the example code to work for my application. Basically, I want a pin to receive a 3-5V input occasionally, and output high to another pin as a result. I tried to test it using the code below:
ONINTERRUPT WKPINT_0,handle_intp0
PMR5.bit0 = 1 ;enables pin as WKP interrupt instead of normal I/O
IEGR2.bit0 = 1 ;0 = Pin will interrupt on a falling edge, 1 to interrupt on a rising edge.
ENABLE WKPINT_0
IsOn var byte
main
high P4
if (IsOn = 1) then
High P17
endif
goto main
handle_intp0
IsOn = 1
resume
So basically I used a High input from P4 to simulate the external input I will be receiving, and then hooked up Pin 4 to Pin 0 to see if it triggered the interrupt and lit up an LED on P17. I’m pretty sure I have a fundamental misunderstanding of how the interrupt works, and that’s why I can’t figure it out. Thanks for any help you can offer.
Since, my major posts on interrupts was posted, Studio was changed such that by default all interrupts are disabled where before they were enabled. So you need to enable them to get them to work…
[code]ONINTERRUPT WKPINT_0,handle_intp0
PMR5.bit0 = 1 ;enables pin as WKP interrupt instead of normal I/O
IEGR2.bit0 = 1 ;0 = Pin will interrupt on a falling edge, 1 to interrupt on a rising edge.
ENABLE WKPINT_0
ENABLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ADDED TO TURN GLOBAL INTERRUPTS ON ;;;;;;;;;;;;;;;;;;;;;
IsOn var byte
main
high P4
if (IsOn = 1) then
High P17
endif
goto main
I tried the code below and plugged P4 into P0 to try and trigger the interrupt. No luck. Any advice?
;Interrupt init
ONINTERRUPT WKPINT_0,handle_intp0
PMR5.bit0 = 1 ;enables pin as WKP interrupt instead of normal I/O
IEGR2.bit0 = 1 ;0 = Pin will interrupt on a falling edge, 1 to interrupt on a rising edge.
ENABLE WKPINT_0
ENABLE
I am not sure, with your hookup… Maybe do something like: Low P4
before you enable the interrupts to make sure P4 is low. Not sure what the Pause 100 is for in the interrupt.
Note: It will only work once as p4 never goes back low. if it were me, I would try something more like:
low p4 ; make sure it is init low…
low p17 ; start in some known state…
PMR5.bit0 = 1 ;enables pin as WKP interrupt instead of normal I/O
IEGR2.bit0 = 1 ;0 = Pin will interrupt on a falling edge, 1 to interrupt on a rising edge.
ENABLE WKPINT_0
ENABLE
main:
toggle p4
pause 100 ; give a little time between turning on or off…
goto main