View Full Version : Lcd Menu
  
eliecer
- 29th January 2005, 05:09
I speak a little english
I need a lcd menu with three or four levels, with submenu, with keypad 
if I press a key from keypad then goto the first level if I pres the same key goto the second level etc.
each level may have a number for example
first level
1.motor
2.lamp 
second level
 
3.servo
4.Temp
third level
5.Optional
so, when I press the key number one from keypad goto the submenu motor, because motor is the 
first menu in this submenu will be a program. The lcd is 2*26 hitachi controller, pbp 2.42.
I am making the program but I am lost.  help  me please I am very lost.
my email 
[email protected].
mister_e
- 29th January 2005, 11:08
Is your keypad routine's working.  If so, can you post your code here?  With your current stuff, we can provide you some idea.  It can be as simple then using BRANCH or BRANCHL statement from PBP.
NavMicroSystems
- 29th January 2005, 12:53
eliecer
as Steve has already mentioned, 
if you post the code you have so far, 
and some information about your hardware 
(i.e. are you using a matrix-keypad, or just some buttons) etc.
we will have a look at it.
If you are going to setup "complex" menu structures 
the display text will "eat up" a lot of codespace.
to solve that problem have a look at This (http://www.picbasic.co.uk/forum/showthread.php?s=&threadid=1015&highlight=EEPROM)
eliecer
- 31st January 2005, 03:28
this is my code example with buttons I made this code myself. I simulate those examples with
proteus 5.2 lite if you have proteus, tell me and send you by mail the examples.this lcd if for 2*16.
PIC16f873. I post the pictures like attached file. I am using buttons from portc.0 up to portc.7.
if press portc.0 several times this dislay on lcd the diferent levels. this code is good but 
I need a button(for example, portc.1 etc) to enter the submenu 1, other button to enter the submenu 2, etc.
other button for back. the same is to keypad(key number one to enter first submenu etc).
you can choose the easily code(buttons or keypad). 
 
' Define LCD connections
DEFINE  LCD_DREG        PORTB
DEFINE  LCD_DBIT        4
DEFINE  LCD_RSREG       PORTB
DEFINE  LCD_RSBIT       0
DEFINE  LCD_EREG        PORTB
DEFINE  LCD_EBIT        2
' Define program variables
b0  var   byte      
   
ADCON1= 7        ' Make PORTA and PORTE digital
low portb.1
         lcdout $fe,1,  "      RED"
         lcdout $fe,$c0,"   ELECTRICA" 
                  
loop: if portc.0=0 then 
b0=b0+1
select case b0
case 1
gosub retardo
lcdout $fe,1,"1.Motor"
lcdout $fe,$c0,"2.Lampara"
case 2
gosub retardo
lcdout $fe,1,"3.Temperatura"
lcdout $FE,$c0,"4.Servo"
case  3
gosub retardo
lcdout $fe,1,"5.Opcional"
end select
endif
goto loop
End
retardo:
pause 250
return
This is my code example with keypad I get the routine keypad on internet.
this code is for lcd 4*16 but I have a lcd 2*16
' Define LCD connections
DEFINE  LCD_DREG        PORTC
DEFINE  LCD_DBIT        4
DEFINE  LCD_RSREG       PORTC
DEFINE  LCD_RSBIT       1
DEFINE  LCD_EREG        PORTC
DEFINE  LCD_EBIT        3
' Define program variables
col     VAR     BYTE            ' Keypad column
row     VAR     BYTE            ' Keypad row
key     VAR     BYTE            ' Key value
disp_key	VAR	BYTE			' Key ASCII value
b0 var byte
OPTION_REG.7 = 0        ' Enable PORTB pullups (16F877)
ADCON1 = 7              ' Make PORTA and PORTE digital
low PORTC.2
Pause 150               ' Wait for LCD to start
LCDOut $fe, 1, "      RED"  ' Display sign on message
LCDOUT $fe,$C0,"   ELECTRICA"
           ' Get a key from the keypad
 loop: GoSub getkey 			' Check to see if a key was pressed
       if key =$c then   
                   
             
          lcdout $fe,1,"1.Motor"
           lcdout $fe,$C0,"2.Lampara"
           lcdout $fe,144,"3.Servo"
           lcdout $fe,208,"4.Temperatura"  
          endif
          
      
         
           
 if key =$d then
    lcdout $fe,1,"5.opcional"
  endif
       
      goto loop              ' Do it forever
' Subroutine to get a key from keypad
getkey:
	' Check for keypress
	For row = 0 TO 3        ' Loop for 4 rows in keypad
        PORTB = 0       ' All output pins low
        TRISB = ~(DCD row)  ' Set one row pin to output
        '@ NOP				' Fudge for 18F452
        col = PORTB >> 4	' Read column pins
        IF col != $0F Then	' Check if key is pressed
        	
              	' Begin speaker tick
        	GoTo gotkey 	' If any keydown, exit
        EndIF
	Next row				' Repeat for the next row
	
	key = $FF				' No keys down, set key to $FF
      
    Return          		' Return to main loop
	
gotkey: 						' Change row and column to key number 0 - 15
	Pause 15                ' Debounce
	 				' End speaker tick
	
	' Wait for all keys up
	PORTB = 0               ' All output pins low
	TRISB = $F0             ' Least significant 4 pins out, top 4 pins in
	IF ((PORTB >> 4) != $0F) Then gotkey	' If any keys down, loop
	key = (row * 4) + (NCD (col^$0F)) - 1	' Combine row and column into numeric value
	
	
	' Translate key to display label:
	' 1  2  3  A
	' 4  5  6  B
	' 7  8  9  C
	' *  0  #  D
	LookUp key,["123A456B789C*0#D"],disp_key
	
	
Return			' Return to main loop
End
mister_e
- 31st January 2005, 03:59
O.K i'll refer to your first code.
Lets assume that PORTC is set to input... but i'll prefer to set it myself..
TRISC=255 'PORTC as all input
And now this snippet ..
loop: 
      if portc.0=0 then 
          b0=b0+1
    
          select case b0
    
                 case 1
'
'
'
' 
goto loop
Your select case will never work untill you press all the button down...
To fix it:
loop: 
      b0=PORTC 'get the reading of PORTC
    
          select case b0
    
                 case 1
BUT if i refer to your schematic, we will need to revert the logic or use other CASE.
I mean.  If you need to read only PORTC.0 =0 the result comming from your PORTC will be %11111110 or 254 and blah blah blah for all the other option.  If you feel safer to read like this
PORTC.0=0  PORTC=1
PORTC.1=0 PORTC=2
PORTC.2=0 PORTC=4
and blah blah blah
what you have to do is to use a simple XOR $ff like this
b0 = PORTC ^ $ff
and now you have the *normal* bit reading from PORTC.
To implement your stuff it will look something like this
loop:
b0 = PORTC ^ $ff
select case b0
     case 1
          gosub menu1
     case 2
          gosub menu2
     case 4
          gosub menu3
     case 8
          gosub menu4
'
'
'
end select
goto loop
that's it that's all , basketball ;)
eliecer
- 13th February 2005, 20:29
I speak a little english
I made a lcd menu, very good with trhee buttons
MENU,ENTER and BACK
So, now I need A Scroll LCD messague I imagine is with FOR.. NEXT.
This is the code example, it's free. WORK OK 100%
' Definiciones
DEFINE  OSC             4                      'oscilador de 4 Mhz
' Constante de Tiempos (time)
        SYMBOL  T1  = 200
        
' modo LCD de 8 bits 
DEFINE  LCD_DREG        PORTB
DEFINE  LCD_DBIT        4
DEFINE  LCD_RSREG       PORTB
DEFINE  LCD_RSBIT       0
DEFINE  LCD_EREG        PORTB
DEFINE  LCD_EBIT        2
' Define program variables
SYMBOL SW1    = PORTC.0                   ' Switch 1 "MENU"
SYMBOL SW2    = PORTC.1                   ' Switch 2 "DEFILE"
SYMBOL SW3    = PORTC.2                   ' Switch 3 "ENTER"
     
        
' Variables diversas
        MENU            VAR BYTE                ' Position dans les MENUS
        POSI            VAR BYTE                ' Position sur le LCD
        
      
'*** INITIALISATION ************************************************** *****************************
' Initialisation of ports
        ADCON1  = 7                             ' Set PORTA  to digital
        low PORTB.1
' Initialisation
        PAUSE 300                               ' Wait for LCD to initialise
        LCDOUT $FE,1                            ' Clear LCD
        
       
' Inicializacion de variables
        MENU = 0
        
LCDOUT $FE,128,"   Soft Elio   "
'
'************************************************* *************************************************
' cuerpo del programa
'************************************************* *************************************************
MAIN:
        IF SW1 = 0 THEN
MENU = 1    
    GOSUB CONFIGURE                             
            
        ENDIF
        GOTO MAIN
        END
'************************************************* *************************************************
' MENU CONFIGURATION
'************************************************* *************************************************
CONFIGURE:
PAUSE T1
'--- Switch MENU-----------------------------------------------------------------------
        IF SW1 = 0 THEN        
                                 
            MENU = MENU + 1
            GOSUB AFFICHEMENU
SUITECONFIGURE:
            SELECT CASE MENU
                CASE 6                                          
                    PAUSE T1
                    IF SW1 = 0 THEN
                        MENU = 1
                        GOTO CONFIGURE
                    ENDIF
                    IF SW3 <> 0 THEN SUITECONFIGURE
                
            END SELECT
        ENDIF
           
'--- Switch "ENTER" -----------------------------------------------------------
SWITCH3:
        IF SW2 = 0 THEN
            LCDOUT $FE,1                                    ' Clear LCD
            SELECT CASE MENU
                                                                        
                
                CASE 2     :GOSUB PROG1:MENU=2
                
                CASE 3     :GOSUB PROG2:MENU=2
                'CASE 4     others aplications
                'CASE 5     
              
                        
            END SELECT
            GOSUB AFFICHEMENU
        ENDIF
        
        GOTO CONFIGURE
AFFICHEMENU:
        LCDOUT $FE,1
        SELECT CASE MENU
            CASE 2
                POSI = 129 : GOSUB MSG6 : GOSUB MSG1           
                POSI = 193 : GOSUB MSG2                        
            CASE 3
                POSI = 129 : GOSUB MSG6 : GOSUB MSG2           
                POSI = 193 : GOSUB 
            CASE 4
                POSI = 129 : GOSUB MSG6 : GOSUB MSG3          
                POSI = 193 : GOSUB MSG4          
               
            CASE 5
                POSI = 129 : GOSUB MSG6 : GOSUB MSG4           
                POSI = 193 : GOSUB MSG5                         
            CASE 6
                POSI = 129 : GOSUB MSG6 : GOSUB MSG5           
                POSI = 193 : GOSUB MSG1                       '
                 END SELECT
            RETURN                   
            
            
          PROG1:
          lcdout $fe,1, "       LED        "
          lcdout $fe,1, "    FLASHER    "
          pause T1
          high porta.0
          pause t2
          low porta.0
          goto PROG1
               
          IF SW3=0 THEN RETURN
          GOTO PROG1
                
          PROG2:
          INCLUDE "scroll.bas"     
                IF SW3=0 THEN RETURN
                GOTO PROG2
     
'************************************************* *************************************************
' Lista de mensajes
'************************************************* *************************************************
MSG1:   LCDOUT $FE,POSI,"1.Motor DC" : RETURN
MSG2:   LCDOUT $FE,POSI,"2.Motor AC" : RETURN
MSG3:   LCDOUT $FE,POSI,"3.Lampara" : RETURN
MSG4:   LCDOUT $FE,POSI,"4.Temperatura" : RETURN
MSG5:   LCDOUT $FE,POSI,"5.Opcional   " : RETURN
MSG6:  LCDOUT $FE,128,">" : RETURN
 
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.