Strange SELECT...CASE Behaviour

Fowkc

Senior Member
Hi Guys,

When simulating a SELECT...CASE structure:
<code><pre><font size=2 face='Courier'>
'Get state of input pins
PINSTATE = PINS
SELECT CASE PINSTATE

CASE UPL 'Up slack on left
SIDE = LEFT
GOSUB upslack

CASE UPR 'Up slack on right
SIDE = RIGHT
GOSUB upslack

CASE OUTL 'All out on left
SIDE = LEFT
GOSUB allout

CASE OUTR 'All out on right
SIDE = RIGHT
GOSUB allout

ELSE
'All outputs low
PINS = 0
END SELECT
</font></pre></code>

I found that after executing one of the GOSUBs (e.g. GOSUB upslack) and returning, the code in the ELSE section (PINS = 0) would then also run. Should it not go directly to the END SELECT?

The fix is simple enough, but I wondered if the PICAXE itself would do this or whether it's a problem with the simulator?
 

hippy

Ex-Staff (retired)
The code generated for a real PICAXE seems to be okay, and I didn't have any problems with simulation either.

The simulator does step to the ELSE statement but then to ENDSELECT and didn't execute the 'pins=0' statement; is that what you are seeing ? You could replace 'pins=0' with something more obvious like 'b13=$AA' and verify if the variable value changes when simulating.

If it does change it merits further investigation and which Programming Editor version and PICAXE variant being simulated would the be useful; I used version 5.0.7 for 08M and 18X.
 

Fowkc

Senior Member
Yep, if any of the conditions are met and one of the CASE statements executes, upon the return, the ELSE code will also execute.

It's with the 18X, ProgEd version is 5.0.7 (a fresh install).

Bizzare, but the 18X runs the program OK.
 
Top