PDA

View Full Version : Menu Template for LCD Display



Carlinux
09-03-2008, 01:33 PM
Hi All,

I'm new to this forum and this is my small contribution to the forum !

Thanks,

Carl




' ================================================== =======================
' File...... menu1.bsp
' Version... 1.0
' Date...... August 2008
' Purpose... Menu Template for LCD 16x2 and BS2p serie
' Author.... Carl Gosselin
' E-mail.... carlgosselin@yahoo.com
' {$STAMP BS2px}
' {$PBASIC 2.5}
'
' -----[ I/O Definitions ]-------------------------------------------------
Lcd PIN 0 ' LCD Enable Pin
btn_plus PIN 11 '
btn_minus PIN 12 '
btn_menu PIN 13 '

' -----[ Variables ]-------------------------------------------------------
i VAR Byte
menu1_value VAR Byte
menu2_value VAR Byte
menu3_value VAR Word

' -----[ Default Values ]-------------------------------------------------------
menu1_value=15
menu2_value=140
menu3_value=300

' -----[ LCD Initialization ]--------------------------------------------------
Init_Lcd:
PAUSE 1000
FOR i = 0 TO 2
LCDCMD Lcd, 48 ' Reset LCD (Send 3 times)
PAUSE 5 ' Delay Require By LCD Specs
NEXT
LCDCMD Lcd, 32 ' Set 4-bit Mode
LCDCMD Lcd, 40 ' Set 2-line Mode
LCDCMD Lcd, 12 ' Turn On Display With No Cursor
LCDCMD Lcd, 6 ' Set To Auto-Increment Cursor
LCDCMD Lcd, 1 ' Clear Display

' -----[ Main Routine ]----------------------------------------------------
Main:
LCDOUT Lcd,128+1, ["Menu"]
LCDOUT Lcd,128+70, ["Examples"]
PAUSE 3000
LCDCMD Lcd, 1 ' Clear Display

DO
LCDOUT Lcd, 2, ["Main Page"]
PAUSE 5 ' Stops Display flickering
'####
'# Your Code Here
'####

IF btn_menu = 0 THEN ' Call the menus sub routine if the button is pressed
GOSUB menu
ENDIF
'####
'# Your Code Here
'####

LOOP
END

' -----[ Sub Routines ]----------------------------------------------------
menu:
DO
GOSUB menu_one
GOSUB menu_two
GOSUB menu_three
LCDCMD Lcd, 1
RETURN
LOOP
RETURN

menu_one:
LCDOUT Lcd, 1, ["2.Menu One"]
PAUSE 200
DO
LCDOUT Lcd, 128+64,["[-]"]
LCDOUT Lcd, 128+77,["[+]"]
LCDOUT Lcd, 128+67,[" "]
LCDOUT Lcd, 128+69,[DEC menu1_value, " Sec"]
IF btn_menu = 0 THEN
LCDCMD Lcd, 1
PAUSE 300
RETURN
ENDIF
IF btn_plus = 0 THEN
menu1_value=menu1_value+1
PAUSE 200
ELSEIF btn_minus = 0 THEN
menu1_value=menu1_value-1
PAUSE 200
ENDIF
IF menu1_value < 10 THEN menu1_value=10
IF menu1_value > 30 THEN menu1_value=30
LOOP
PAUSE 1000
LCDCMD Lcd, 1
RETURN

menu_two:
LCDOUT Lcd, 1, ["2.Menu Two"]
PAUSE 200
DO
LCDOUT Lcd, 128+64,["[-]"]
LCDOUT Lcd, 128+77,["[+]"]
LCDOUT Lcd, 128+67,[" "]
LCDOUT Lcd, 128+70,[DEC menu2_value,"F"]
IF btn_menu = 0 THEN
LCDCMD Lcd, 1
PAUSE 300
RETURN
ENDIF
IF btn_plus = 0 THEN
menu2_value=menu2_value+5
PAUSE 200
ELSEIF btn_minus = 0 THEN
menu2_value=menu2_value-5
PAUSE 200
ENDIF
IF menu2_value < 120 THEN menu2_value=120
IF menu2_value > 190 THEN menu2_value=190
LOOP
PAUSE 1000
LCDCMD Lcd, 1
RETURN

menu_three:
LCDOUT Lcd, 1, ["3.Menu Three"]
PAUSE 200
DO
LCDOUT Lcd, 128+64,["[-]"]
LCDOUT Lcd, 128+77,["[+]"]
LCDOUT Lcd, 128+67,[" "]
LCDOUT Lcd, 128+70,[DEC menu3_value,"Hz"]
IF btn_menu = 0 THEN
LCDCMD Lcd, 1
PAUSE 300
RETURN
ENDIF
IF btn_plus = 0 THEN
menu3_value=menu3_value+50
PAUSE 200
ENDIF
IF btn_minus = 0 THEN
menu3_value=menu3_value-50
PAUSE 200
ENDIF
IF menu3_value < 200 THEN menu3_value=200
IF menu3_value > 600 THEN menu3_value=600
LOOP
PAUSE 1000
LCDCMD Lcd, 1
RETURN

sam_sam_sam
09-04-2008, 01:50 AM
Carlinux (http://forums.parallax.com/member.php?u=54068)
Welcome to Parallax Forum

Very nice·work

Thanks for sharing it········

·················································· ············ · http://forums.parallax.com/images/smilies/smile.gifs

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·http://forums.parallax.com/images/smilies/idea.gif·that you may have and all of your time finding them

·
·
·
·
Sam

servello
09-04-2008, 05:27 AM
Very Nice.

Any chance something like this could be done for the BS2?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Deus tantum me iudicabit