Ds18b20+hd4478 parallel lcd+18m2+

westaust55

Moderator
Sorry, as you had (linked to) code for driving the LCD in parallel,
In the absence of information, I presumed that you wanted to know about getting the data from the DS18B20 and arranging that data.

I am using an iPhone at present so not about to try and type in large blocks of BASIC code.
In simplified pseudo code format what you need to do is:

1. READTEMP12 to fetch the temp to 0.0625 deg resolution
2. Convert the result from 2's compliment to a decimal number.
Decimal number will need to be either a value multiplied by say 100 to retain 2 decimal places
Or keep the whole degrees in one variable and the fractional part in a second variable.
3. Send the data to the LCD as:
(a) whole part
(b) a decimal point a char = "."
(c) the decimal part
For the numeric parts you can use the BINTOASCII command to convert a multi-digit decimal number into the separate digits pre-encoded in the ASCII format ready to be sent to the LCD.

If you need more assistance, try to be more specific on what step you need help with and also indicate which PICAXE chip you are using. Then folks here will be better placed to provide a few lines of code to help you.

EDIT:
I see also there in an old thread:
http://www.picaxeforum.co.uk/showthread.php?23910-Lcd-ds18s20&p=297888#post297888
You have also asked for the program code - which is in fact already attached to the post 12 as a txt file.
 
Last edited:

Naweed

New Member
Thanks for that but that code doesn't work random letters appear. I am using a 18M2+ chip. I need to know how and where to place my code. I am new to this as told earlier.
 

AllyCat

Senior Member
Hi,

Have you got the "Welcome Message" working correctly for the "Tutor" article linked in #1 ? If not, we need to identify if it's a hardware issue (bad or incorrect wiring) or software (bad or incorrectly copied program code).

The statement that "It is not important to know how the initiation (init), write character (wrchr) and write instruction (wrins) subprocedures works to use them" is moderately true if the hardware/software works, but can give real problems if it doesn't work. The "4-data lines" method used in the Tutor is much more difficult to debug than the normal 8-data lines arrangement. Starting with an 8-wire data bus (+2 control lines) can use simpler (and more understandable) program code, but I suppose has even more opportunies for getting the hardware wrong!

If the "Welcome" message is working, then change the EPROM data to "Temp.=snnn.nn C " and check it appears on the LCD screen. Then at the start of the Tutor's main: section add marks' READTEMP12 program with the SERTXD command replaced by:
Code:
   write 6 , b9
   write 7 , b8
   write 8 , b7
   write 9 , b6
   write 11 , b5
   write 12 , b4
That's not a "good" method, but it should help to get something on the LCD, which can then be improved.

Cheers, Alan.
 

Naweed

New Member
The Temp.=.... data is displayed on my screen. What do you mean by replacing the sertxd code. I did this .
EEPROM 0,("Temp.=snnn.nn C ") ' store the text in the EEPROM memory

gosub init ' initialise LCD
readtemp C.1,b1 ; read value into b1
write 6 , b9
write 7 , b8
write 8 , b7
write 9 , b6
write 11 , b5
write 12 , b4 ; transmit value to serial LCD
goto main

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
 

hippy

Technical Support
Staff member
The Temp.=.... data is displayed on my screen. What do you mean by replacing the sertxd code. I did this .
EEPROM 0,("Temp.=snnn.nn C ") ' store the text in the EEPROM memory

gosub init ' initialise LCD
readtemp C.1,b1 ; read value into b1
write 6 , b9
write 7 , b8
write 8 , b7
write 9 , b6
write 11 , b5
write 12 , b4 ; transmit value to serial LCD
goto main
You need to convert your READTEMP 'b1' value into ASCII characters to be placed within EEPROM.

It is best to remove those WRITE commands you added and that should display your "Temp.=snnn.nn C " message on the display - don't worry for now that it has S and N's where the sign and digits will one day be.

If it does show the expected message we can move on to getting a temperature displayed, otherwise we can resolve why that is not working before moving on to adding the temperature display.
 

AllyCat

Senior Member
Hi,

Use the BINTOASCII command as shown in the examples linked in post #2 above.

In practice there are other "messy" details like the sign, which is why I suggested (perhaps not explicitly enough) that you should copy all the code from example 3 in the link above, just changing the SERTXD... line to the block of WRITE commands.

Cheers, Alan.
 

Naweed

New Member
Hi I did this. I think this is what u meant


Code:
EEPROM 0,("Temp.=snnn.nn C ") ' store the text in the EEPROM memory
		
	gosub init 			' initialise LCD
	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

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
 
Last edited by a moderator:

AllyCat

Senior Member
Hi,

Presumably it doesn't work?

at the start of the Tutor's main: section add marks' READTEMP12 program with the SERTXD command replaced by:....
You have "lost" the "init:" label (which the Program Editor should have told you) and put the "main:" label in the wrong place (it should be near the "Celcius:" label).

I don't have suitable hardware to fully test any code, but I think you're getting close.

EDIT: Ah, I see you have just not listed the subroutines (init:, etc). So your main problem is probably the GOTO Celcius which should be at the end of the main program loop.

Cheers, Alan.
 
Last edited:

Naweed

New Member
is this how.


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,("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
 
Last edited by a moderator:

AllyCat

Senior Member
Hi,

If you update the FOR ... NEXT loop comment to " ; For...next loop - Copy the Temperature Data to the LCD " it should be obvious that there's no point in doing that until the temperature has been read and calculated. But that will never happen because the "GOTO main" loops the program flow back before the temperature is ever measured !

If you put the line "GOSUB Celsius" immediately after the main: label and change the GOTO Celsius at the end to RETURN , then I think the program should work. Then it needs to be generally "tidied up" and comments added such as for the write 7 , b8 " ; write the temperature hundreds digit to EPROM ".

Cheers, Alan.
 

Naweed

New Member
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,("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
 gosub Celsius

 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
return

 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

is this it....
 
Last edited by a moderator:

westaust55

Moderator
@Naweed,

Firstly, a couple of general comments:
1. please place your posted code within [code] and [/code] tags
as mentioned in this thread: http://www.picaxeforum.co.uk/showthread.php?7679-Read-Me-First!
at the top of the forum pages.

2. Try to indent you code so the the flow and loops, tests etc are more quickly seem and understood.

To help you I have taken you code and inserted tabs/indents to show you how that looks.
Your program as per the above post will not display the temperature as you have an GOSUB Celsius below the GOTO Main resulting in program execution never reaching that GOSUB thus no temperature being read or displayed.
I have commented/remarked out that statement in the below copy.


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,("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

    gosub Celsius
    pause 5000 ' pause for 5s
    goto main ' loop




 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
    return


 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
 

Naweed

New Member
Thank you so much .It works great. I have a question. Its currently being displayed as Temp.=+ 21.43C. Is it possible for me to have The Temperature on the 1st line and +/- 21.43C on the bottom line.
 

westaust55

Moderator
Yes it can be done:

Try the following. It takes a path of least change to format as you wish.
There are better ways particularly if the first line will never change (rather than keep sending that data each time).


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,("Temperature = 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 23 ' For...next loop - Read Technology Tutor text into LCD
	  IF b0 = 0 THEN
	    b1 = 128	; commend to move to start of first line
	    GOSUB  wrins	; send instruction to move to second line
	  ELSEIF b0 = 14 THEN    
 	    b1 = 192	; command to move to start of second line	
 	    GOSUB wrins	; send instruction to move to second line
	  ENDIF
	  
        read b0, b1 ' read letter from EEPROM into variable b1
        gosub wrchr ' send character to LCD

    Next b0

    gosub Celsius
    pause 5000 ' pause for 5s
    goto main ' loop



	

 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 14 , b9
    write 15 , b8
    write 16 , b7
    write 17 , b6
    write 19 , b5
    write 20 , b4

    PAUSE 1000
    return


 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
 

Naweed

New Member
Thanks for that the 'temperature' is on the first line but it is from the start. How can i space it so it comes in the centre and can i get rid of the equal sign.
And can i also space out the bottom line.
Thanks so far
 

westaust55

Moderator
First edit the line:
EEPROM 0,("Temperature = snnn.nn C ") ' store the text in the EEPROM memory
to remove the "=" and

Then, in the lines:
Code:
 IF b0 = 0 THEN
	    b1 = 128	; commend to move to start of first line
	    GOSUB  wrins	; send instruction to move to second line
	  ELSEIF b0 = 14 THEN    
 	    b1 = 192	; command to move to start of second line	
 	    GOSUB wrins	; send instruction to move to second line
	  ENDIF
change the values for 128 and 192.
Increment 128 moves the start position by 1 character for each +1 to the 128
likewise the value 192 for the second line.

You could also at the EEPROM statement remove some of the spaces after "temperature" but then you MUST ALSO make some other changes in the code.
 

Naweed

New Member
Hi there thank you so much for all the help you and and all those who have contributed to this. Thank you so much. It works perfectly.
 

hippy

Technical Support
Staff member
Note that updating an EEPROM message with WRITE commands is not the recommended way to update a display.

That is acceptable for testing and proving things work but if used in a final version and left running continuously the EEPROM may become worn out and fail after a week or two, perhaps sooner.

It would be recommended to move away from using those WRITE commands as soon as possible.
 

westaust55

Moderator
Concur with hippy that continued writing to EEPROM memory (the WRITE command) is not the best as has been indicated since post ~6 by others.

@Naweed,
Now you need to get back to:
  1. using the READTEMP12 command
  2. Using the BINTOASCII command to break the value into the separate digits with each already ASCII encoded
  3. Pass each ASCII encoded byte variable (eg b9, b10, b11, etc) into variable b0
  4. Call (GOSUB) the Wrchr subroutine to send to the LCD display.

The temperature text does not change and can be left in EEPROM.

Don't forget that you also need to:
1. Send the command to place the cursor where needed before resenting the temperature value
2. Send the decimal point (b0 = "." ) between the whole part and fractional/decimal part.
 
Last edited:

westaust55

Moderator
Instead of the WRITE commands to store the values from the BINTOASCII into EEPROM as an intermediate step, after the BINTOASCII move each of the values, one at a time to b0 and then GOSUB wrchr to send them to the LCD screen directly.

Before sending b5, you need to add
B0 = "."
GOSUB wrchr
To display the decimal point.

Have a go to make the changes yourself. If it does not work come back and folks here can give you guidance.
Using my iPhone at the moment so not going to attempt posting large blocks of code.
 

Naweed

New Member
Code:
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 14 , b9
    write 15 , b8
    write 16 , b7
    write 17 , b6
    write 19 , b5
    write 20 , b4

    PAUSE 1000
    return
what do u mean before b5
 
Last edited by a moderator:

westaust55

Moderator
Remove those WRITE commands entirely.
Then use code like
B0 = B9 : GOSUB wrchr
:
B0 = B6 : GOSUB wrchr

B0 = "." : GOSUB wrchr

B0 = B5 : GOSUB wrchr
B0 = B4 : GOSUB wrchr
 

Naweed

New Member
Code:
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

    b0 = b9 gosub wrchr:
    b0 = b8 gosub wrchr:
    b0 = b7 gosub wrchr:
    b0 = b6 gosub wrchr:
    b0 = b5 gosub wrchr:
    b0 = b4 gosub wrchr:

    PAUSE 1000
    return
is this how, its not showing the temperature.just "temperature" on line 1 and snnn.nn C on line 2
 
Last edited by a moderator:

hippy

Technical Support
Staff member
You may need to add a "b1=$C0:gosub wrins" before the "b0 = b9:gosub wrchr" to ensure the LCD cursor is positioned at the start of the second line before outputting the temperature.
 

Naweed

New Member
Code:
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


    b1=$C0:gosub wrins
    b0 = b9 gosub wrchr:
    b0 = b8 gosub wrchr:
    b0 = b7 gosub wrchr:
    b0 = b6 gosub wrchr:
    b0 = b5 gosub wrchr:
    b0 = b4 gosub wrchr:

    PAUSE 1000
like this.... weird charcaters appear on line 2
 
Last edited by a moderator:

hippy

Technical Support
Staff member
Delete the "b0 = b9 gosub wrchr:". You are not using 'b9' so guess its use mistakenly crept in somehow.

Added: Actually b9 is being used, perhaps as a sign symbol, +/-.

Maybe explain what "weird characters" appear.
 
Last edited:

hippy

Technical Support
Staff member
Change -

b0 = b9 gosub wrchr:
b0 = b8 gosub wrchr:
b0 = b7 gosub wrchr:
b0 = b6 gosub wrchr:
b0 = b5 gosub wrchr:
b0 = b4 gosub wrchr:

to -

b1 = b9 : gosub wrchr
b1 = b8 : gosub wrchr
b1 = b7 : gosub wrchr
b1 = b6 : gosub wrchr
b1 = "." : gosub wrchr
b1 = b5 : gosub wrchr
b1 = b4 : gosub wrchr
 

westaust55

Moderator
@Naweed,

Please go back and look at the request to use code tags around your code as per the first item on my list in post 16.

Seems I introduced an error when I accidentally used b0 as the variable to pass data to the wrchr: routine which hippy has corrected to b1.

At post 27 hippy suggested that you add a line
B1 = $C0 : GOSUB wrins
That value $C0 is the same as the decimal 192 I provided back at post 20.
From what you indicated above, that is the scone line shows
",,,,,nn.nn C"
You need to adjust that value ($C0 or 192) if you want the value centred.
Ultimately you will be better of to remove fetching the "nn.nn C" part from EEPROM and just add the "C" in the same way the sign (+/-) and decimal point are being sent.

As hippy has mentioned, please post your entire code so that folks can see exactly when is happening and better guide you.
 

Naweed

New Member
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,("Temperature   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 23 ' For...next loop - Read Technology Tutor text into LCD
	  IF b0 = 0 THEN
	    b1 = 128+2	; commend to move to start of first line
	    GOSUB  wrins	; send instruction to move to second line
	  ELSEIF b0 = 14 THEN    
 	    b1 = 192+3	; command to move to start of second line	
 	    GOSUB wrins	; send instruction to move to second line
	  ENDIF
	  
        read b0, b1 ' read letter from EEPROM into variable b1
        gosub wrchr ' send character to LCD

    Next b0

    gosub Celsius
    pause 2500 ' pause for 2.5s
    goto main ' loop



	

 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

    b1 = b9 : gosub wrchr
    b1 = b8 : gosub wrchr
    b1 = b7 : gosub wrchr
    b1 = b6 : gosub wrchr
    b1 = "." : gosub wrchr
    b1 = b5 : gosub wrchr
    b1 = b4 : gosub wrchr

    return


 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
ok I changed the write to b1=...

now what it shows is " Temperature " on line 1
and " snnn.nn C + 2" and the 2 sometimes changes to a 1
 
Last edited by a moderator:

westaust55

Moderator
Try this:

and PLEASE, PLEASE PLEASE try to use the [code] and [/code] tags around your code when posted as it preserves the formatting and makes the flow easier to see

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,("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

	b1 = 128+2 ; command to move to start position on the first line
	GOSUB wrins ; send instruction to move to first line
	For b0 = 0 to [COLOR="#0000FF"]10[/COLOR] ' For...next loop - Read Temperature text into LCD
          read b0, b1 ' read letter from EEPROM into variable b1
          gosub wrchr ' send character to LCD
        Next b0
	gosub Celsius
	pause 2500 ' pause for 2.5s
	goto main ' loop


' ################################################# ############################
 '# This LCD code uses the Upper part of Port B for the LCD parallel mode and #
 '# it illustates the LCD example in manual 3                                 #
 '#############################################################################

 

	

 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 = " " ; zero blanking b8
      IF b7 = "0" THEN 
        b7 = " " ' zero blanking b7
      ENDIF 
    ENDIF 
    
    [COLOR="#0000FF"]b1 = 192 : gosub wrins ; move to start of second line[/COLOR]
    b1 = b9 : gosu0b wrchr
    b1 = b8 : gosub wrchr
    b1 = b7 : gosub wrchr
    b1 = b6 : gosub wrchr
    b1 = "." :gosub wrchr
    b1 = b5 : gosub wrchr
    b1 = b4 : gosub wrchr
[COLOR="#0000FF"]    b1= " "	: gosub wrchr
    b1 = "C": gosub wrchr[/COLOR]

    return


 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
 
Top