vectorspace
Member
I'm sure that I am missing something here but can't figure out what it is.
I thought an interrupt condition resulted in disabling the interrupt. The following example seems to contradict that. It works as expected when simulated but when downloaded into the 18M2, it doesn't do what's expected. Namely, after entering the interrupt, it gets stuck there. After a little trial and a lot of error, the situation was corrected with a "setint OFF' statement in the interrupt routine. From what I understand, and please don't overestimate that, the interrupt should be disabled once an interrupt condition occurs.
The code (with comments):
What am I missing?
I thought an interrupt condition resulted in disabling the interrupt. The following example seems to contradict that. It works as expected when simulated but when downloaded into the 18M2, it doesn't do what's expected. Namely, after entering the interrupt, it gets stuck there. After a little trial and a lot of error, the situation was corrected with a "setint OFF' statement in the interrupt routine. From what I understand, and please don't overestimate that, the interrupt should be disabled once an interrupt condition occurs.
The code (with comments):
Code:
' =========================== WhatsUpButton.bas ============================
' This program runs on a PICAXE-18M2. Eight segments of an
' an LED bar display are connected to outputs B.0-B.7 w/resistors bla bla.
' Input switches are on inputs C.(0,1,6,7) with pull-down resistors
' which hold them low (4.7k resistor to ground) and go high when activated.
' Pressing any switch results in counting up binary ONE on the LEDs.
' =========================================================================
' === Constants ====
symbol simu = 1 'A simulated complex program.
' === Variables ====
symbol LEDs = outpinsB ' Control some LEDs.
' === Directives ===
#picaxe 18M2 ' ID which Rev Ed MCU is used.
#no_data ' Don't waste time sending nothing.
' ========================== Main Program ==========================
main:
dirsB = %11111111 ' All outputs.
dirsC = %00001000 ' C.3 is an output, C.1,C.2,and C.4-7 are inputs.
LEDs = %00000000 ' start count at 0
setint OR %11000011, %11000011, C ; interrupt if C.(0,1,6,7) are high
do ' Just sitting around and waiting. . .
b11 = pinsC ' See what's going on here.
debug ' Show what's going on here.
wait simu ' Simulate a significant and useful program.
loop ' Round and round . . .
' ==================== Here Come The Subroutines=== ================
interrupt:
setint OFF ' Exactly why is this a 'works' vs. 'don't work' item?
' If you remove the "setint OFF" statement, the simulation will still
' run just like one would expect. However, download to the 18M2 (v2.B)
' without the 'setint OFF' statement and it just don't do right.
' The first press of the button sends the program into the land of limbo.
' The latest manual (as of 8-19-2011) states: "When the interrupt occurs,
' the interrupt is permanently disabled." If this is correct for my 18M2
' (v2.B), then, AFAIK, the 'setint OFF' statement shouldn't be necessary.
' BUT, after trying everything else, it seems to be necessary. ??????
b11 = pinsC ' See what's going on here.
debug ' Show what's going on here.
inc LEDs ' Do something interesting after pressing a button.
pause 25 ' Debounce for make
ecnuob:
if pinC.0 is on then GOTO ecnuob ' Wait for break.
if pinC.1 is on then GOTO ecnuob ' Wait for break.
if pinC.6 is on then GOTO ecnuob ' Wait for break.
if pinC.7 is on then GOTO ecnuob ' Wait for break.
pause 25 ' Debounce for break.
if LEDs = 256 then
LEDs = 1 'Roll over if you don't have enough LED's etc.
endif
setint OR %11000011, %11000011, C 'Since it's disabled, enable it.
return ' Get back to where you once belonged.
Last edited: