Shop OBEX P1 Docs P2 Docs Learn Events
Outputing a variable to LCD — Parallax Forums

Outputing a variable to LCD

gtchiefgtchief Posts: 7
edited 2005-04-13 14:46 in BASIC Stamp
We want to combine the code below·and we also want to include a calculated variable after top speed.· Any suggestions?

' {$STAMP BS2}
'
[noparse][[/noparse] Constants ]
' Ports used
················ RS CON 4 ' Register Select (1 = char)
················ E CON 5· ' LCD Enable pin (1 = enabled)
' 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
'
[noparse][[/noparse] Variables ]
'
················ char VAR Byte· ' character sent to LCD
················ index VAR Byte ' loop counter
'
[noparse][[/noparse] EEPROM Data ]
'
················ Msg DATA "Top Speed: "·· ' preload message

'
[noparse][[/noparse] Initialization ]
'
Init:··········· DIRL = %00111111·· ' set pins 0-5 as outputs
················ OUTS = $0000······ ' clear the pins
' Initialize the LCD (Hitachi HD44780 controller)
'
LCDinit:········ PAUSE 500 ' Wait for LCD init
················ ' =================================
················ ' STANDARD HITACHI 44780 4-BIT INIT
················ ' =================================
················ char=%00000011 ' Set 8-bit mode (1)
················ GOSUB LCDcmd
················ char=%00000011 ' Set 8-bit mode (2)
················ GOSUB LCDcmd
················ char=%00000011 ' Set 8-bit mode (3)
················ GOSUB LCDcmd
················ char=%00000010 ' Set 4-bit mode
················ GOSUB LCDcmd
················ char=%00101111 ' Set duty cycle 11xx = 5x11 matrix
················ GOSUB LCDcmd·· ' 10xx = 5x8 matric
················ char=%00000000 ' Display control mode
················ GOSUB LCDcmd
················ char=%00001000 ' Set display OFF, cursor OFF, blink OFF
················ GOSUB LCDcmd
················ char=%00000000 ' Display control mode
················ GOSUB LCDcmd
················ char=%00001111 ' Set display ON, cursor ON, blink ON
················ GOSUB LCDcmd·· ' 11CB -> C=1 cursor on, B=1 blink on
················ char=%00000000 ' Entry control mode
················ GOSUB LCDcmd
················ char=%00000110 ' Set cursor right, no display shift
················ GOSUB LCDcmd·· ' 01IS -> I=1 cursor right, S=1 shift display
················ char = ClrLCD· ' Clear LCD
················ GOSUB LCDcmd
'
[noparse][[/noparse] Main Code ]
'
Start:
················ FOR index = 0 TO 39
·················· READ Msg + index, char ' get character from memory
·················· GOSUB LCDwr··········· ' write it to the LCD
················ NEXT

················ PAUSE 4000·············· ' wait 2 seconds
················ 'char = ClrLCD··········· ' clear the LCD
················ GOSUB LCDcmd
················ PAUSE 4000
················ GOTO LCDinit·············· ' do it all over
'
[noparse][[/noparse] Subroutines ]
'
' Send command to the LCD
'
LCDcmd:········· LOW RS ' enter command mode
'
' Write ASCII char to LCD
'
LCDwr:
················ OUTA = char.HIGHNIB ' output high nibble
················ PULSOUT E, 1······· ' strobe the Enable line
················ OUTA = char.LOWNIB· ' output low nibble
················ PULSOUT E, 1
················ HIGH RS············ ' return to character mode
················ RETURN

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-13 14:46
    Here's a very simple routine that will print your value at the current cursor position on the LCD.· Mind you, this is simple, so the value is 0-padded:

    Print_Value:
    · FOR idx = 4 TO 0···················· ' print five digits
    ··· char = (theValue DIG idx) + "0"··· ' get digit, convert to ASCII
    ··· GOSUB LCDwr······················· ' print on LCD
    · NEXT
    · RETURN

    Change the starting value of the FOR-NEXT loop to control how many digits get printed.· If, for example, you only needed three digits on the display, the starting value would be 2.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
Sign In or Register to comment.