I have a program that has several "sub programs" that will run. These sub programs are selected using an interrupt to select the next sub program. So as one presses the button, the next sub program runs in a loop until the next button press.
One of the sub programs will have several long wait statements in it, as shown as an example in "sub prog3". If the button is pressed while the unit is executing the wait, the interrupt does increment the progselect properly, but it jumps back to the wait till it is done and then runs the next sub program.
If I add a "goto main" inside the interrupt subroutine to get out of the wait 30 s, the program fails. I know for sure that the interrupt is working during the wait, it just goes back to waiting till it is done and then goes to the next sub program.
Is there a better way to go about this? It works very well as long as it is not waiting for a long period of time.
Thanks for looking!!!!!
#chip 12F1840 , 16
#DEFINE SWITCH PORTA.3
DIR SWITCH IN
SET IOCAN3 ON
ON Interrupt PORTBCHANGE CALL SWTEST 'INTERRUPT WHEN SWITCH GOES LOW
PROGSELECT = 1
'*********************** MAIN PROGRAM *******************
MAIN:
SELECT CASE PROGSELECT
CASE 1
PROG1
CASE 2
PROG2
CASE 3
PROG3
END SELECT
GOTO MAIN
'*********************** SUB PROGRAM 1 *******************
SUB PROG1
DO
'DO A BUNCH OF STUFF
LOOP WHILE PROGSELECT = 1
END SUB
'*********************** SUB PROGRAM 2 *******************
SUB PROG2
DO
'DO A BUNCH OF STUFF
LOOP WHILE PROGSELECT = 2
END SUB
'*********************** SUB PROGRAM 3 *******************
SUB PROG3
DO
'DO A BUNCH OF STUFF
WAIT 30 S '<--- CAN'T GET OUT OF THIS WITH BUTTON PRESS
LOOP WHILE PROGSELECT = 3
END SUB
'*********************** SWITCH INTERRUPT *******************
SUB SWTEST
IF SWITCH = 0 THEN 'DEBOUNCE ROUTINE FROM FORUM
BUTTONCOUNT = 0
DO WHILE SWITCH = 0
wait 10 ms
buttoncount +=1
LOOP
END IF
if buttoncount > 3 then
PROGSELECT = PROGSELECT + 1
IF PROGSELECT = 4 THEN PROGSELECT = 1
END IF
SET IOCAF3 OFF
'GOTO MAIN <--- TRY TO GET OUT OF WAIT HERE CRASHES PROGRAM
END SUB
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a program that has several "sub programs" that will run. These sub programs are selected using an interrupt to select the next sub program. So as one presses the button, the next sub program runs in a loop until the next button press.
One of the sub programs will have several long wait statements in it, as shown as an example in "sub prog3". If the button is pressed while the unit is executing the wait, the interrupt does increment the progselect properly, but it jumps back to the wait till it is done and then runs the next sub program.
If I add a "goto main" inside the interrupt subroutine to get out of the wait 30 s, the program fails. I know for sure that the interrupt is working during the wait, it just goes back to waiting till it is done and then goes to the next sub program.
Is there a better way to go about this? It works very well as long as it is not waiting for a long period of time.
Thanks for looking!!!!!
Instead of a single long delay use lots of smaller delays inside of a loop.
Example: