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
Bookmarks