newbie: how to output temperature to LCD

Peter-C

Member
Using the manual code I have an LCD displaying 'Hello World', but I can't work out how tweak it to display a readtemp variable stored in b0. Serout produces no display (but I don't know which pin shoud do the sending). Any pointers will be very welcome.
 

eclectic

Moderator
Which and what?

Peter. Some questions please;

Which Picaxe?

What is the code? (Or the page in the manual)

What sort of LCD?

What method of connection?

e.
 

Peter-C

Member
Eclectic- its an 18A, to an 8X2 HD44780 LCD. Wired as per Hippy's excellent website for 18A http://www.hippy.freeserve.co.uk/picaxelc.htm (tried to paste diagram but it lost all format)
Code listed below. Many thanks.
Code:
eeprom 0,("hello there")

        gosub init

Main:   let b1=1
        gosub wrins

         for b3=0 to 5
         read b3,b1
         
         gosub wrchr 
         next b3
         
         let b1=192
         gosub wrins
         
         for b3 = 6 to 11
         read b3,b1
         gosub wrchr
         next b3

init: let pins=0 
	let b4=0 
	'let dirs = 252
	pause 200 
	let pins=48 
	pulsout 3,1 
	pause 10 
	pulsout 3,1 
	pulsout 3,1 
	let pins = 32 
	pulsout 3,1 
	pulsout 3,1 
	let pins = 128 
	pulsout 3,1 
	let b1=14 
	gosub wrins 
return 


wrchr: let pins =b1 & 240 
	high 2 
	pulsout 3,1 
	let b2=b1*16 
	let pins = b2 & 240 
	high 2 
	pulsout 3,1 
return 


wrins: let pins = b1 & 240 
	pulsout 3,1 
	let b2 = b1*16 
	let pins = b2 & 240 
	pulsout 3,1 
	high 2 
return
 
Last edited:

eclectic

Moderator
There's no way I'd even dream of adding to Hippy's work!

I tried this last year, then I took the easy way.
If your finances allow, the AXE033 module.

Look at the AXE033 datasheet page 8

Say, for example you read the temperature on input 1
and serout on output 7

Serout 7, N2400, (254,1) ' Clear screen
pause 500

Main:
readtemp 1, b1
serout 7, N2400, (254,128) ' move to line 1
serout 7, N2400, ( #b1)
pause 1000
Goto main

e.
 

Peter-C

Member
I have a couple of these LCDs aso I would very much like to get them working. With Hippy's wiring scheme I have data lines from output 4,5,6,and 7 but your code doesn't seem to produce any image on the screen no matter which output I choose. The LCD was previously talking to the chip because I have 'Hello world'. I just have to find the code to let me send my variable to it.
Can anybody help?
 

D n T

Senior Member
Been there, I have to find the code

Page 22 of basic commands.
Use the "bdcto ascii" command.
You have the vaiable that you got from you readadc ( lets say b0)
Then you have to have a variable for the tens ( say b10) and for the units ( say b1)
then I think I just substituted the variables into the LCD out
I alraedy had a "mask" on the LCD ( like TEMP: ) so the reader knows what they are reading and the code below just inserts the variable in the charctor you want it, in my case, the 12th and 13th charactor of the first row.
I had to work out the number for the caractor position, I cant remember where I got that , the PICAXE manual I think.
Anyway, charactor 1 first line is: 128
and charactor 1 second line is : 192
hence you add to those numbers to move your chosen position across....

My example ( a modified hippy code, thanks hippy):
BIN_ASCII:
bintoascii reading ,ten, one
return

LCDbyte = 141 ; position cursor at 140 ( 128 + 12 ) ( the 12th character on the first line)
gosub SendCmdByte ; send information to LCD

LCDbyte = ten ; put the value "ten" in the 140 position
gosub SendDataByte ; send information to LCD

LCDbyte = 142 ; position at 141 (128 + 13) ( the 13th charactor on the first line)
gosub sendcmdbyte ; send information to LCD

LCDbyte = one ; put the value "one" in the 141 position
gosub senddatabyte ; send information to LCD

------------------------- End of example -----------------

I hope this helps and I hope I don't have to edit it too many times

NEW BIT OF CODE for the mask...
( changed the mask to "ABC" because I want to keep it quiet until I get it right).

You can still see how I left the charactors where I wanted the variables to go as a blank space.
I have to put * in instead of blanks because the forum automatically seems to format, so* you*will*still*beable*to*see*what*I*mean
I suppose its like the signs that petrol stations have over here, most of it is permanent and painted on, but where the price is has slides to put the daily price into.
----------------------Start of example-----------------
LCDmask:

DisplayTopLine:

MoveCursorToStartOfFirstLine:

LCDbyte = $80
GOSUB SendCmdByte

FOR counter = 0 TO 15
lookup counter, ("ABCD:***. ABC:** %"),LCDbyte
GOSUB SendDataByte
NEXT

MoveCursorToStartOfSecondLine:

LCDbyte = $C0
GOSUB SendCmdByte

DisplayBottomLine:


FOR counter = 0 TO 15
lookup counter,("ABCD:**. *ABCD "),LCDbyte
GOSUB SendDataByte
NEXT

return
----------------------------------End of example------------------------------------------
 
Last edited:

eclectic

Moderator
Not been there.

Peter. My apologies.

I should have stated that my code was for the AXE033,
to show how simple the whole thing was.

Last year, I bought some “cheap” LCD units from Ebay.
I then bought a couple of firmware chips.
They work, and work well, but.............
it took me a long time to solder and check.
The chips and LCD take up more space (My poor constructional skills!)

The AXE033 is neat, and straightforward to assemble
and works first time.

The old LCD units are now in a draw somewhere, gathering dust.
e.
 

Peter-C

Member
Thanks for the code - it serves to demonstrate that I am seriously out of my depth!
Isn't LCDBYTE a pic basic command, rather than normal basic? My Prog Editor doesn't like it and I am completely stuck and confused.
I am going for a lie down!
 

premelec

Senior Member
Note that LCDByte is being used as a variable NOT a command....
e.g. Symbol LCDByte = b11 ' holds value to send to LCD....
Good luck!
 

Technical

Technical Support
Staff member
The code segment you need is:

Code:
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
As already said, the AXE033 makes life much easier!
 
Last edited:

Peter-C

Member
This is a major breakthrough Technical, very many thanks.
I have it working now and am in the process of tidying up the code before I post the whole thing on this forum for future reference.
 

Peter-C

Member
18A to HD4470 LCD working code

As promised in earlier post, I have managed to get my LCD working, giving a readtemp display on a standard 8x2 LCD. Several members have been good enough to steer me on this, so I post the finished code for the next poor newbie who is looking for a cut and paste solution. My understanding of the code is limited and I am sure it can be improved.
My purpose is to make it available to others, though any suggested improvements will be welcomed
Code:
'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
 
Last edited:

D n T

Senior Member
Apologies, LCDbyte is a symbol.

Can I post a complete code on here if I reference the author, although it has been published by some one else in a book I had to buy??

If not I will edit my code so you can use it

P.s. check your private messages
 
Last edited:
Top