Shop OBEX P1 Docs P2 Docs Learn Events
how can display a variable — Parallax Forums

how can display a variable

antonisantonis Posts: 9
edited 2006-02-22 09:09 in BASIC Stamp
hello,
i'made a circuit to drive a LCD with 3 wire, with help of 74hc595 shift register.
I can do my LCD show me message where i store in my eprom with DATA command but i don't undertand what is the way to show a value of· a variable for example i have· a bouton and every time where i pressed count increament and store in a variable.
how i can see this in my LCD:

ex:

addv VAR Nib

start:
·if IN1=1 THEN add
·GOTO start

add:
·addv=addv+1
·goto start
'How i can see the addv on LCD

THIS IS MY CODE FOR THIS WORKS
'
pin definition
'
'LCD_PINS
clk···· CON··· 0······················· 'clock pin on 74hc595
latch·· CON··· 1······················· 'latch pin on 74hc595
sdata·· CON··· 2······················· 'data pin on 74hc595

'
LCD control characters
ClrLCD· CON···· $01···················· ' clear the LCD
CrsrHm· CON···· $02···················· ' move cursor to home position
CrsrLf· CON···· $10···················· ' move cursor left
CrsrRt· CON···· $14···················· ' move cursor right
DispLf· CON···· $18···················· ' shift displayed chars left
DispRt· CON···· $1C···················· ' shift displayed chars right
DDRam·· CON···· $80···················· ' Display Data RAM control
CGRam·· CON···· $40···················· ' Char Gen RAM control
'
LCD_variables
char··· VAR···· Byte··················· ' character sent to LCD
temp··· VAR···· Byte··················· ' work variable for LCD routines
index·· VAR···· Byte··················· ' loop counter
lcd_E·· VAR···· temp.BIT2·············· ' LCD Enable pin
lcd_RS· VAR···· temp.BIT3·············· ' Register Select (1 = char)

'
EPROM DATA
msg1··· DATA·· "test circuit"
'
Initialize the LCD (Hitachi HD44780 controller)
LCDini:
· PAUSE 500···························· ' let the LCD settle
· char = %0011························· ' 8-bit mode
· GOSUB LCDcmd
· PAUSE 5
· GOSUB LCDcmd
· GOSUB LCDcmd
· char = %0010························· ' put in 4-bit mode
· GOSUB LCDcmd
· char = %00001100····················· ' disp on, crsr off, blink off
· GOSUB LCDcmd
· char = %00000110····················· ' inc crsr, no disp shift
· GOSUB LCDcmd
'
main program
Start:
·GOSUB LCDcmd
·FOR index = 0 TO 11
·READ Msg1 + index,char······· ' get character from EEPROM
·GOSUB LCDwr
·NEXT

GOTO start

'
LCD routines
LCDcmd:
· lcd_RS = 0····················· ' command mode
· GOTO LCDout
LCDwr:
· lcd_RS = 1····················· ' character mode
· GOTO LCDout
LCDout:
· temp.HIGHNIB = char.HIGHNIB··· ' get high nibble
· lcd_E = 1
· SHIFTOUT SData, Clk, 1, [noparse][[/noparse]temp]
· PULSOUT Latch, 1
· lcd_E = 0···························· ' drop Enable line low
· SHIFTOUT SData, Clk, 1, [noparse][[/noparse]temp]
· PULSOUT Latch, 1
· temp.HIGHNIB = char.LOWNIB··········· ' get low nibble
· lcd_E = 1
· SHIFTOUT SData, Clk, 1, [noparse][[/noparse]temp]
· PULSOUT Latch, 1
· lcd_E = 0
· SHIFTOUT SData, Clk, 1, [noparse][[/noparse]temp]
· PULSOUT Latch, 1
· RETURN

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-11 17:26
    You have to convert you variable to ASCII for display on an LCD.· Here's a simple routine that will duplicates the DEC5 modifier using any many PBASIC instructions; use this after you've positioned the cursor:

    Lcd_DEC5:
    · FOR idx = 4 TO 0
    ··· temp = (myValue DIG idx) + "0"
    ··· GOSUB LCDwr
    · NEXT
    · RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • antonisantonis Posts: 9
    edited 2006-02-22 09:09
    Thanks
    this··works very good
Sign In or Register to comment.