LCD temperature display

sambo77

New Member
Hi everyone,

I'm building a temperature controller which requires temperature readout on an LCD display. I am using an 18X with ds18b20 sensors and a 40x2 display.

I have the hardware setup and working fine with the LCD interface as per Hippy's instructions at http://http://www.hippy.freeserve.co.uk/picaxelc.htm

I can get plain text stored in EEPROM to display on the LCD fine, but I am not sure how to display variables produced by the readtemp command.

Here is the code I am using to drive the LCD:
SYMBOL RS = 2 ; 0 = Command 1 = Data
SYMBOL E = 3 ; 0 = Idle 1 = Active
SYMBOL DB4 = 4 ; LCD Data Line 4
SYMBOL DB5 = 5 ; LCD Data Line 5
SYMBOL DB6 = 6 ; LCD Data Line 6
SYMBOL DB7 = 7 ; LCD Data Line 7

SYMBOL RSCMDmask = %00000000 ; Select Command register
SYMBOL RSDATmask = %00000100 ; Select Data register

SYMBOL get = b11
SYMBOL byte = b12
SYMBOL rsbit = b13

PowerOnReset:

GOSUB InitialiseLcd

DisplayTopLine:

EEPROM 6,("Hello")

FOR get = 6 TO 10
READ get,byte
GOSUB SendDataByte
NEXT

MoveCursorToStartOfSecondLine:

byte = $C0
GOSUB SendCmdByte

DisplayBottomLine:

EEPROM 11,("World!")

FOR get = 11 TO 16
READ get,byte
GOSUB SendDataByte
NEXT

END

InitialiseLcd:

FOR get = 0 TO 5
READ get,byte
GOSUB SendInitCmdByte
NEXT

' Nibble commands - To initialise 4-bit mode

EEPROM 0,( $33 ) ; %0011---- %0011---- 8-bit / 8-bit
EEPROM 1,( $32 ) ; %0011---- %0010---- 8-bit / 4-bit

' Byte commands - To configure the LCD

EEPROM 2,( $28 ) ; %00101000 %001LNF00 Display Format
EEPROM 3,( $0C ) ; %00001100 %00001DCB Display On
EEPROM 4,( $06 ) ; %00000110 %000001IS Cursor Move

; L : 0 = 4-bit Mode 1 = 8-bit Mode
; N : 0 = 1 Line 1 = 2 Lines
; F : 0 = 5x7 Pixels 1 = N/A
; D : 0 = Display Off 1 = Display On
; C : 0 = Cursor Off 1 = Cursor On
; B : 0 = Cursor Steady 1 = Cursor Flash
; I : 0 = Dec Cursor 1 = Inc Cursor
; S : 0 = Cursor Move 1 = Display Shift

EEPROM 5,( $01 ) ; Clear Screen

RETURN

SendInitCmdByte:

PAUSE 15 ; Delay 15mS

SendCmdByte:

rsbit = RSCMDmask ; Send to Command register

SendDataByte:

pins = byte & %11110000 | rsbit ; Put MSB out first
PULSOUT E,1 ; Give a 10uS pulse on E
pins = byte * %00010000 | rsbit ; Put LSB out second
PULSOUT E,1 ; Give a 10uS pulse on E

rsbit = RSDATmask ; Send to Data register next

RETURN
Could someone show me what changes I need to make to display temperature values acquired by readtemp?

Thanks for your help,
Sam
 

westaust55

Moderator
Welcome to the PICAXE forum.
If you are expecting negative values as well as positive then you will need to check for the sign as well.

Code:
SYMBOL sign = b2
:
:
Sign = “ “
IF temp > 127 THEN
sign = “+”
ENDIF
byte = sign
GOSUB  SendDataByte
If temp > 100
Byte = temp / 100 + $30
Else 
bytes = “ “
ENDIF
GOSUB  SendDataByte
If temp > 10
Byte = temp // 100 / 10 + $30
ELSE
Byte = “ “
GOSUB  SendDataByte
Byte = temp // 10 + $30
GOSUB  SendDataByte

EDIT: The above is the long hand way and shows you how to extract each digit and use a leading blank when here are less that 3 digits.
Also have a look at the BINTOASCII command in PICAXE manual 2
That can save you some of the above maths and also the need to add $30 to each value sent to create the ASCII code equivalent for each digit.
 
Last edited:

sambo77

New Member
Thanks for your help westaust55, got it working! i kind of threw myself into the deep end not having any experience with the picaxe programming, still a bit to learn! will also try out the bintoascii command as you suggested
 
Top