Making a menu selection


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default Making a menu selection

    Hi,

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

    Code:
    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.

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Making a menu selection

    Quote Originally Posted by lerameur View Post
    Hi,

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

    Code:
    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.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: Making a menu selection

    ok wow work great now, thank you

    K

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default Re: Making a menu selection

    This should help you.


    Quote Originally Posted by lerameur View Post
    a menu selection SUB that will not exit until select button is pressed.
    Code:
    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

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts