I've been working on a basic menu system the past few weeks. Since my programming skills don't really exist, I've spent more time reading the manuals (especially #2) than coding and have learned lots! However, I've finally run into a problem I just can't debug myself. First, an explanation of my setup. I have a 20X2 plugged into a 08M proto board with firmware version C.1 and four AAs that have been run down to about 4.8 volts. I'm using a SparkFun SerLCD V2.5 connected to port A.0 and three push buttons for menu navigation attached to C.6, C.7 and B.0 (with 10K pulldowns and a 1K in series like suggested in manual #3, page 25).
The code is part of the backlight settings menu, which will eventually let you change the backlight's brightness and whether it is on or off. The actual code is supposed to display the backlight settings menu and sub menus (see diagram for details). The problem I'm having is that it won't respond to any button presses. I have pinC.6 as up, C.7 as down and B.0 as enter. I use the "<" symbol to show what point the menu is at at the "+" and "-" signs to show if there are more options farther down or up the menu.
When I power up the setup, I get the SF splash-screen for a short while and then it goes blank. If I press the down button I can get the screen to display the top section of the menu with the pointer at "Brightness". I have working code that lets me navigate the "Brightness" sub menu so my wiring isn't the problem.
This is the code I'm having problems with right now.
I am using EEPROM location 0 to store backlight values when turned off and location 1 for remembering on/off condition. I'm using byte "BLMenu" to store the current location of the pointer on the menu. I'm sure there are more elegant ways of doing this but this is what I came up with. The last 'if' statement section still hasn't been filled in but I figured I could leave it empty till I made sure everything was working; am I wrong in doing so? I'm not quite sure what else you would need to know to point me in the right direction but I'm willing to supply any details neccesary.
Diagram of what I'm trying to achieve. The return part will eventually take you back to the main menu.
The code is part of the backlight settings menu, which will eventually let you change the backlight's brightness and whether it is on or off. The actual code is supposed to display the backlight settings menu and sub menus (see diagram for details). The problem I'm having is that it won't respond to any button presses. I have pinC.6 as up, C.7 as down and B.0 as enter. I use the "<" symbol to show what point the menu is at at the "+" and "-" signs to show if there are more options farther down or up the menu.
When I power up the setup, I get the SF splash-screen for a short while and then it goes blank. If I press the down button I can get the screen to display the top section of the menu with the pointer at "Brightness". I have working code that lets me navigate the "Brightness" sub menu so my wiring isn't the problem.
This is the code I'm having problems with right now.
Code:
symbol Up=pinC.6 'define symbols
symbol Down=pinC.7
symbol Enter=pinB.0
symbol BLMenu=b3
symbol MMenu=b2
high A.0
pause 850
read 0,b0 'reads saved backlight value
if b0<128 then let b0=128 'code checks value is out of range
elseif b0>157 then let b0=157 'if it is, it will bring it back to the correct value
endif
let b1=b0-128 'does some math to scale brightness from 29 to 100
let b1=b1*1000/289
blint: read 1,b4
if b4=0 then
pause 5
serout A.0,T9600_8,(254,128)
pause 5
serout A.0,T9600_8,("Off< Brightness -")
elseif b4=1 then
pause 5
serout A.0,T9600_8,(254,128)
pause 5
serout A.0,T9600_8,("On< Brightness -")
elseif b4>1 then
write 1,0
pause 5
serout A.0,T9600_8,(254,128)
pause 5
serout A.0,T9600_8,("Off< Brightness -")
endif
blsub: if Up=1 and BLMenu=1 and b4=0 then
pause 5
serout A.0,T9600_8,(254,128)
pause 5
serout A.0,T9600_8,("Off< Brightness -")
let BLMenu=0
elseif Up=1 and BLMenu=1 and b4=1 then
pause 5
serout A.0,T9600_8,(254,128)
pause 5
serout A.0,T9600_8,("On< Brightness -")
let BLMenu=0
elseif Up=1 and BLMenu=2 then
pause 5
serout A.0,T9600_8,(254,128)
pause 5
serout A.0,T9600_8,("Brightness< +Return... +")
let BLMenu=1
endif
if Down=1 and BLMenu=0 and b4=0 then
pause 5
serout A.0,T9600_8,(254,128)
pause 5
serout A.0,T9600_8,("Off +Brightness< -")
elseif Down=1 and BLMenu=1 and b4=1 then
pause 5
serout A.0,T9600_8,(254,128)
pause 5
serout A.0,T9600_8,("On +Brightness< -")
endif
if Enter=1 and BLMenu=0 then
elseif Enter=1 and BLMenu=1 then
elseif Enter=1 and BLMenu=2 then
endif
goto blsub
Diagram of what I'm trying to achieve. The return part will eventually take you back to the main menu.
Last edited: