'#############################################################################
'# This LCD code uses the Upper part of Port B for the LCD parallel mode and #
'# it illustates the LCD example in manual 3 #
'#############################################################################
EEPROM 0,("Current Temperature:") ' store the text in the EEPROM memory
gosub init ' initialise LCD
main:
let b1 = 1 ' set b1 to ‘clear display’ instruction
gosub wrins ' send instruction to LCD
let b1 = 12 ' set b1 to ‘hide cursor’ instruction
gosub wrins ' send instruction to LCD
For b0 = 0 to 15 ' For...next loop
read b0, b1 ' read letter from EEPROM into variable b1
gosub wrchr ' send character to LCD
Next b0
pause 400 ' pause for 0.4s
goto main ' loop
end
init:
'#########################################################
'# Initiation subprocedure for the LCD # #
'# Use Port B For LCD # #
'# B.7 - 14 (DB7) # #
'# B.6 - 13 (DB6) # #
'# B.5 - 12 (DB5) # #
'# B.4 - 11 (DB4) # #
'# B.2 - 4 (RS) # #
'# B.3 - 6 (E) # #
'#########################################################
let pinsB = 0 ' Clear all output lines
let b3 = 0 ' Reset variable b3
let dirsB = 252 ' Set pins 2-7 as output lines (Stamp only).
pause 200 ' Wait 200 ms for LCD to reset.
let pinsB = 48 ' Set to 8-bit operation.
pulsout B.3,1 ' Send data by pulsing ‘enable’
pause 10 ' Wait 10 ms
pulsout B.3,1 ' Send data again
pulsout B.3,1 ' Send data again
let pinsB = 32 ' Set to 4-bit operation.
pulsout B.3,1 ' Send data.
pulsout B.3,1 ' Send data again.
let pinsB = 128 ' Set to two line operation
pulsout B.3,1 ' Send data.
let b1 = 14 ' Screen on, cursor on instruction
gosub wrins ' Write instruction to LCD
return
posative: readtemp C.1,a1 ; read value into a1
if a1 > 127 then negative ; test for negative
serout B.7,N2400,(#a1) ; transmit value to serial LCD
goto main
negative:
let a1 = a1 - 128 ; adjust neg value
serout B.7,N2400,("-") ; transmit negative symbol
serout B.7,N2400,(#a1) ; transmit value to serial LCD
goto wrchr
wrchr:
'#######################################################################
'# Write Character to LCD subprocedure, sends one character to the LCD # #
'#######################################################################
let pinsB = b1 & 240 ' Mask the high nibble of b1 into b2.
high B.2 ' Make sure RS is high
pulsout B.3,1 ' Pulse the enable pin to send data.
let b2 = b1 * 16 ' Put low nibble of b1 into b2.
let pinsB = b2 & 240 ' Mask the high nibble of b2
high B.2 ' Make sure RS is high
pulsout B.3,1 ' Pulse enable pin to send data.
return
wrins:
'############################################################################
'# Write Instruction to LCD - subprocedure, sends an instruction to the LCD # #
'############################################################################
let pinsB = b1 & 240 ' Mask the high nibble of b1 into b2.
pulsout B.3,1 ' Pulse the enable pin to send data.
let b2 = b1 * 16 ' Put low nibble of b1 into b2.
let pinsB = b2 & 240 ' Mask the high nibble of b2
pulsout B.3,1 ' Pulse enable pin to send data.
high B.2 ' Back to character mode
return