'This prog displays a temperature from a ds18b20 on input pin one of Pic 18A
'to a standard HD44780 LCD, wired as in www.hippy.freeserve.co.uk/picaxelc.htm
'I am sure the code can be made neater, but it works.With thanks to those who
'supplied the code.
start: eeprom 0,("Celcius")
gosub init
readtemp 1,b0 'read temperature into b0
if b0 > 127 then 'test for negative number
let b0 = b0 - 128
let b1 = "-"
else
let b1 = "+"
end if
gosub wrchr ' output + or -
bintoascii b0,b10,b11,b12 'convert b0 bytes into 3 ascii characters
let b1 = b10 'send 3 characters to LCD
gosub wrchr
let b1 = b11
gosub wrchr
let b1 = b12
gosub wrchr
let b1=192 'line2
gosub wrins
for b3=0 to 6 'insert text from line2 cell 0 to cell 6
read b3,b1
gosub wrchr
next b3
'gosub wrchr
debug
let b1=12 'Hide Cursor
gosub wrins
goto start
init: pause 10000
let pins=0 'Clear all output lines
let b4=0 'Reset variable b3
pause 15 'Wait for 200ms for LCD to reset
let pins=48 'Set to 8 bit operation
pulsout 3,1 'Send data by pulsing enable
pause 10 'Wait 10ms
pulsout 3,1 'Send data again
pulsout 3,1 'Send data again
let pins = 32 'Set to 4 bit operation
pulsout 3,1 'Send data
pulsout 3,1 'Send data again
let pins = 128 'Set to two line operation
pulsout 3,1 'Send data
let b1=1 'Move cursor to start of line
gosub wrins
return
wrchr:let pins =b1 & 240 'Mask the high nibble of b1 into b2
high 2 'Make sure RS is high
pulsout 3,1 'Pulse the enable pin to send data
let b2=b1*16 'Put low nibble of b1 into b2
let pins = b2 & 240 'Mask the high nibble of b2
high 2 'Make sure RS is high
pulsout 3,1 'Pulse enable pin to send data
pause 15 'Pause (poss timing issues reported)
return
wrins: pause 15
let pins = b1 & 240 'Mask the high nibble of b1 into b2
pulsout 3,1 'Mask the high nibble of b1 into b2
let b2 = b1*16 'Put low nibble of b1 into b2
let pins = b2 & 240 'Mask the high nibble of b2
pulsout 3,1 'Pulse enable pin to send data
Pause 15
high 2 'Back to character mode
return