PDA

View Full Version : Making a menu selection



lerameur
- 24th February 2011, 00:31
Hi,

I am trying to make a menu selection SUB that will not exit until select button is pressed. I am using the PIC18F4550


Selection var PortC.6
Next1 var PortC.7
'/////////////////////////////////////
'/////// GetModeOfOperation ////////
'/////////////////////////////////////
GetModeOfOperation:

Lookup Op_Mode, [55,65],Operation_Mode

Select Case Operation_Mode
Case 55
lcdout $FE,1, " Charger Mode "
Case 65
lcdout $FE,1, " Recycle Mode"
End Select

lcdout $FE,$C0, "Next or Select"
pause 200

if Selection=1 then return
if Next1=1 then Op_Mode = Op_Mode + 1
if Op_Mode > 1 then Op_Mode = 0
Gosub GetModeOfOperation

Return

The problem, is that my sub routine exits (return) after 4 seconds while nothing has been pressed.

cncmachineguy
- 24th February 2011, 02:03
Hi,

I am trying to make a menu selection SUB that will not exit until select button is pressed. I am using the PIC18F4550


Selection var PortC.6
Next1 var PortC.7
'/////////////////////////////////////
'/////// GetModeOfOperation ////////
'/////////////////////////////////////
GetModeOfOperation:

Lookup Op_Mode, [55,65],Operation_Mode

Select Case Operation_Mode
Case 55
lcdout $FE,1, " Charger Mode "
Case 65
lcdout $FE,1, " Recycle Mode"
End Select

lcdout $FE,$C0, "Next or Select"
pause 200

if Selection=1 then return
if Next1=1 then Op_Mode = Op_Mode + 1
if Op_Mode > 1 then Op_Mode = 0
Gosub GetModeOfOperation

Return

The problem, is that my sub routine exits (return) after 4 seconds while nothing has been pressed.

I just learned today that in th 18's you can overflow the stack. I don't really know the what happens when you do, but I suspect a "reset" maybe. Anyhow, I think the gosub needs to be a goto. otherwise you just keep calling itself without a return. everytime it saves PC to the stack, but never reads it back.

lerameur
- 24th February 2011, 02:59
ok wow work great now, thank you

K

Jerson
- 24th February 2011, 03:44
This should help you.




a menu selection SUB that will not exit until select button is pressed.




Selection var PortC.6

Next1 var PortC.7

'/////////////////////////////////////
'/////// GetModeOfOperation ////////
'/////////////////////////////////////
GetModeOfOperation:
while Selection = 0 ' exit when selection becomes 1

Lookup Op_Mode, [55,65],Operation_Mode

Select Case Operation_Mode
Case 55
lcdout $FE,1, " Charger Mode "
Case 65
lcdout $FE,1, " Recycle Mode"
End Select

lcdout $FE,$C0, "Next or Select"
pause 200

if Next1=1 then Op_Mode = Op_Mode + 1
if Op_Mode > 1 then Op_Mode = 0
wend
Return