'Help please' with LCD menu creation...

XLSERVICE

New Member
Has anyone created a menu system for a RS232 LCD? I have 'up, down, left, right and OK' switches to navigate through a menu with sub menus. I am using a 28X Picaxe.

My current code is very long winded and would be tricky to add submenus and extra menus later..

is there a way to navigate around a table or matrix?

Cheers....

main: b0=0
serout 7,N2400,(254,1)
serout 7,N2400,("Menu Active")
serout 7,N2400,(254,12)
pause 1000
goto menu1

menu1: serout 7,N2400,(254,128)
serout 7,N2400,(254,1)
serout 7,N2400,("Light GREEN LED <OK")
serout 7,N2400,(254,192)
serout 7,N2400,("Light BLUE LED")
m1loop:
;if pin1=1 then action1
button 4,1,254,0,b0,1,action1
;if pin2=1 then menu2
button 3,1,254,0,b0,1,menu2
button 0,1,254,0,b0,1,main
goto m1loop


menu2: serout 7,N2400,(254,128)
serout 7,N2400,(254,1)
serout 7,N2400,("Light GREEN LED")
serout 7,N2400,(254,192)
serout 7,N2400,("Light BLUE LED <OK")
m2loop:
;if pin1=1 then action2
button 4,1,254,0,b0,1,action2
;if pin3=1 then menu1
button 2,1,254,0,b0,1,menu1
button 3,1,254,0,b0,1,menu3
button 0,1,254,0,b0,1,main
goto m2loop

menu3: serout 7,N2400,(254,128)
serout 7,N2400,(254,1)
serout 7,N2400,("Light BLUE LED")
serout 7,N2400,(254,192)
serout 7,N2400,("Light BOTH LEDs <OK")
m3loop:
;if pin1=1 then action2
button 4,1,254,0,b0,1,action3
;if pin3=1 then menu1
button 2,1,254,0,b0,1,menu2
button 0,1,254,0,b0,1,main
goto m3loop




action1:
low 1
high 0
pause 500
goto menu1


action2:
low 0
high 1
pause 500
goto menu2

action3:
High 1
High 0
goto menu3
 

Tom2000

Senior Member
Has anyone created a menu system for a RS232 LCD? I have 'up, down, left, right and OK' switches to navigate through a menu with sub menus. I am using a 28X Picaxe.

My current code is very long winded and would be tricky to add submenus and extra menus later..

is there a way to navigate around a table or matrix?

Cheers....
You usually wind up writing your menu structure as a state machine, which you might implement as a long if..then..else statement. (On..gosub might also come in handy.)

You'll use one register as your state variable. At each stage of your menu operation, you'll update the state variable (or "mode byte"). Your if..then..else statement will test the state variable so it knows "where you are" in your operation each time you call the if..then..else.

To implement your heirarchy, stick another state macine where you'd like to implement each submenu.

Your top-level structure might look something like this:

Code:
main:

   StateVar = 0   ; Initialize state


do

   do

     ; test your primary button.  Stay in this loop until it's pressed and debounced

   loop

   on StateVar gosub Menu1 Menu2 Menu3

loop

end

  
Menu1:

   ; do stuff

   StateVar = 1    ; point to next subroutine

return


Menu2:

   ; do stuff

   StateVar = 2    ; point to next subroutine

return


Menu3:

   ; do stuff

   StateVar = 0    ; point to first subroutine

return
This might not reduce your code size, but it will definitely be simpler to write, read, and debug.

Here's the Wikipedia link to their Finite State Machine article to get you started.

Good luck!

Tom
 

George Sephton

Senior Member
Hey,
I haven't actually got round to building my menu but Im doing a similar thing. Although Im going to use an i2c Eeprom (24LC256 - - Cos it's massive!) I designed the menu system flowchart, to sub menus ..etc and came up with all of the strings that would stay the same and programmed it all into my eeprom then recorded the values so when Im ready I'll have the PICAXE equivelant of:
>Menu button
>Get values 0 to 15 and display on LCD
If Down > Get 16 to 31 >DISPLAY
If Enter > Get 32 to 47 >DISPLAY

With that you could use on sub and a lookup (maybe) to work out a system with less code). If its a short menu you could always use the internal Eeprom.
 

XLSERVICE

New Member
Excellent... Loads of great advise, thank you..
Is the EPROM used to speed up the display responce? or just to leave more code space on the Pic?

I had a read up on the State Machine???!!, time to go back to school I think!!
 

westaust55

Moderator
The external i2c (24LC256) EEPROM will not speed up response time.

It has a capacity of 32 k-Bytes which will give George a lot of space for text associated with the menu and likely other applications.
 

BeanieBots

Moderator
Using the PICAXE EEPROM gives several advantages.
When using for example a 2X16 LCD, the messages can be layed out in a very readable manner. Also, just a simple little subroutine is all thats required. Just pass it a number relating to the message you want to send.

Have a look at my "Pb charger" code. The link was posted by lbenson earlier.
You should see all the messages in the EEPROM section and the two subroutines "Msg_1" and "Msg_2" that send them it to the LCD lines 1 & 2.
There's also another routine that just sends 8 chars. and the numbers are all displayed right justified. It also uses the under rated "button" command with a little trick to know the difference between the first push and a repeat.
 
Top