Lcd +ds18s20

lorddc

Member
Hi, i have wired to a breadboard a 16x2 HD44780 LCD with a picaxe18m2, i have managed to get it to display (from a tutorial i got online) a phrase, i want to be able to display the temperature from the sensor (mentioned in topic title) so that it will display it on the LCD and refresh every now and again, but i have no idea where to start, please help


Edited to clarify my question
 
Last edited:

nick12ab

Senior Member
Hi, i have an lcd screen wired up via breadboard to a 16x2 HD44780 LCD, i have managed to get it to display (from a tutorial i got online) a phrase
How have you done this?

2lcds.PNG

Where is the PICAXE and what PICAXE are you using?

i want to be able to display the temperature from the sensor (mentioned in topic title) so that it will display it on the LCD and refresh every now and again, but i have no idea where to start, please help
See here for how to read the temperature from a DS18S20. You can then use the bintoascii command to get the data into a format for display.
 

lorddc

Member
just realised that it looks like i mean i have 2 lcds screens, i only have one lcd wired to an 18m2... the code i have already is below:

Code:
'#############################################################################
	'# 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
	
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

this was code i got form a tutorial and i edited the eeprom data to what i would like it to say instead, not sure how to write the code for the sensor and how to add it into that program
 
Last edited:

westaust55

Moderator
No you do not need two displays.
If yo already have an LCD display successfully working and say it is displaying your message on line 1 then you can display the temperature on line 2.

The PICAXE chips have a READTEMP and READTEMP12 commands which is disigned for the DS18B20 temp sensor.
The DS18S20 that you mention is not ideal as it has a different resolution but can be pressed into service.

The DS18B20 has a resolution of 0.0625 degree whereas from memory the DS18S20 has a resolution of 0.5 degree.

Try using the READTEMP12 command and from the returned 2's compliment number kneeling in mind the resolution calculat the temp.
There are many code examples posted for the DS18B20 and your version will only need slight adjustments.
Then used the BINTOASCII command to extract the individual digits from th temp value.
As the values are in ASCII format they can be sent in sequence to the LCD display just as you are sending the individual characters for your text message.
There are standard control codes for most LCD displays like 254, 192 to set the position where text will start on the LCD display.
Having a look at the Rev Ed display datasheets or you own displays Datasheet should give you a full list of these control codes.

Trust ther is enough information here for you to investigate and work out some code for yourself but after you investigate further, ask if you need more help


Finally when posting program code of more than a few lines, please wrap within [code] and [/code] tags so if appears in a sub window within your post.
This is in line with the requirements if the forum guidelines in the ReadMe First sticky post at the top of the active forum area,
 

westaust55

Moderator
Now at a PC and had a look at the DS18S20 datasheet. See here: http://datasheets.maximintegrated.com/en/ds/DS18S20.pdf

In simple terms for positive temperatures (ie >= 0 degC) when you read the data from the DS18S20 into a word variable you can take the lower byte of that word variable and divide by 2 which will give the temp as whole/integer degC.
If you do want the 0.0 or 0.5 option as a fractional part (you are only going to get that accuracy level) then before dividing by 2 test the least significant bit of the initial value. If the bit is a 1 add ".5" to the displayed data otherwise add ".0".

If you purchase a DS18B20 instead you have a far better resolution and can use the READTEMP or READTEMP12 in the intended manner.
 

lorddc

Member
edited it to put it in those tags, i thought there would be some i just couldnt find any at a quick glance, also i only have one LCD connected, that was a mistake in the way i had written the question, also i have the DS18b20 ~( http://www.ebay.co.uk/itm/281090058138?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649) after double checking the number,
Code:
	'#############################################################################
	'# 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
would this code work? i will test it on my picaxe as soon as i get home
looks like it wont work according to the simulate option, i will have to do more research, could someone point me to some code examples
 

russbow

Senior Member
Not tested in the simulator, but syntax check fails.
You are using a variable incorrectly. All byte variables are Bx so in your code you need to change all a1 usage to b1
( or another b variable that is not used further in the program.)
 

westaust55

Moderator
Yes the DS18B20 will be easier to use.

You have put the code for the DS18B20 into the middle of the LCD routines and used a variable a1 that is not defined.
Also you are using SEROUT to send to some other device rather than your parallel conencted LCD.
Finally you did not sue the BINTOASCII comemnd that I had previously mentioned.

Here is an untested modified version that hopefully will work:
Code:
	'#############################################################################
	'# 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
	

	readtemp C.1,b0			; read value into b0
	IF b1 < 127 then
positive:
	b1 = " "
	ELSE
negative	; test for negative
		let a1 = a1 - 128		; adjust neg value
		b1 = "-"
	ENDIF
	gosub wrchr ; send temp sign character
	BINTOASCII b0, b4,b5,b6
	b1 = b4	; send hundreds character
	gosub wrchr
	b1 = b5	; send tens character
	gosub wrchr
	b1 = b6	; send units character
	gosub wrchr
	
	
	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 &#8216;enable&#8217;
	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
Now looking at your message length (>16 characters), you need to shorten the message and research then add some LCD control commands (as I previously mentioend) to set the starting location for the test message and then for the actual temperature value.
 

nick12ab

Senior Member
Here is an untested modified version that hopefully will work:
Code:
	readtemp C.1,b0			; read value into b0
	IF b1 < 127 then
positive:
	b1 = " "
	ELSE
negative	; test for negative
		let a1 = a1 - 128		; adjust neg value
		b1 = "-"
	ENDIF
This won't work and where is the conversion for the DS18S20?

He doesn't need to work out the code himself because as linked by me earlier Rev-Ed have published this code to do it:
Code:
	readtemp12 C.1, w0	; read DS18S20 as 12-bit
	if w0 > 255 then	; convert to a reading as if from DS18B20
	  w0 = -w0 / 2 or 128	; when reading is negative
	else
	  w0 = w0 / 2		; when reading is positive
	end if
	b1 = w0			; set as a byte result if required (optional)
 

westaust55

Moderator
This won't work and where is the conversion for the DS18S20?

He doesn't need to work out the code himself because as linked by me earlier Rev-Ed have published this code to do it:
Code:
	readtemp12 C.1, w0	; read DS18S20 as 12-bit
[/QUOTE]

Why not ? :confused: :confused:
See post 6 where part number was corrected:
[QUOTE]i have the DS18[B][COLOR="#FF0000"]b[/COLOR][/B]20[/QUOTE]
 

Naweed

New Member
Hi there iam doing something similar with those parts
Do u have the code for the temperature sensor.
Thanks
 
Top