'#############################################################################
'# 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,("Temp.=snnn.nn C ") ' 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 Technology Tutor text into LCD
read b0, b1 ' read letter from EEPROM into variable b1
gosub wrchr ' send character to LCD
Next b0
pause 5000 ' pause for 5s
goto main ' loop
end
Celsius:
Readtemp12 C.1,w1 'read in result ds18b20
convert:
let b9 =43 'Display + (43) space (32)
IF W1 > 64655 THEN ' info - 55 degrees = 64656
let b9 =45 'Display - (45)
W1 = - W1 ' info if - ie w1=1000 display - 10.00 C
ENDIF
W1 = W1 * 25 / 4 ' info + ie w1=8500 display 85.00 C
BINTOASCII w1,b8,b7,b6,b5,b4
IF b8 = "0" THEN : b8 = " " :ENDIF ' zero blanking b8
IF b8 = " " AND b7 = "0" THEN : b7 = " " :ENDIF ' zero blanking b7
write 6 , b9
write 7 , b8
write 8 , b7
write 9 , b6
write 11 , b5
write 12 , b4
PAUSE 1000
GOTO celsius
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 3000 ' Wait 3000 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
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