One more time...and disregard previous post from yesterday
Now that I have a cold solder joint fixed, I'm talking to a ds18b20 (w/3 ft. wires) using a 16f876 running at 20Mhz with latest PBP 2.5.
Serial #, fam code, etc. reads fine using Rentron's code.
Can't figure out why the startup temp 85C (185F) is stuck using the posted Rentron code (partial code shown changed to accomodate a 2-line lcd ...)
Is there a magic step to unlock the scratchpad from startup temp? Any ideas on what to try next?
thanks in advance...
---------------------------------------------------------------------
'* Notes : Changed Original code for 16x2 serial LCD. *
'* : Display F deg only. Using Lab X2 w/ 16F876-20/SP *
'* : *
'************************************************* *
DEFINE OSC 20 ' We're using a 20MHz oscillator
Comm_Pin VAR PortC.0 ' One-wire Data-Pin "DQ" on PortC.0
Busy VAR BIT ' Busy Status-Bit
R_Temp VAR WORD ' RAW Temperature readings
Lo_ByteR var R_Temp.Byte0
Hi_ByteR var R_Temp.Byte1
TempC VAR WORD ' Temp in deg C
TempF VAR WORD ' Temp in deg F
Float VAR WORD ' Holds remainder for + temp C display
Cold_Bit VAR R_Temp.Bit11' Sign-Bit for +/- Temp. 1 = Below 0 deg C
Real_Cold CON 1 ' Define Real_Cold = 1
BAUD CON 16468 ' N9600 for serial LCD
DISP VAR PortB.0 ' Pin to drive serial LCD
Deg CON 223 ' Data to display Deg ° symbol
CLR CON 1 ' CLR LCD command
LINE1 CON 128 ' LCD line #1
LINE2 CON 192 ' LCD line #2
'LINE3 CON 148 ' LCD line #3
'LINE4 CON 212 ' LCD line #4
INS CON 254 ' LCD command mode parameter
Sign VAR BYTE ' +/- sign for temp display
Dummy VAR BYTE ' Dummy for Div32
Pause 500
SEROUT2 DISP,BAUD, [INS,CLR]
SerOut2 DISP, BAUD, ["My display"] ' Display "Hello"
Pause 1000 ' Wait .5 second
Start_Convert:
OWOUT Comm_Pin, 1, [$CC, $44]' Skip ROM search & do temp conversion
Wait_Up:
OWIN Comm_Pin, 4, [Busy] ' Read busy-bit
IF Busy = 0 THEN Wait_Up ' Still busy..?, Wait_Up..!
OWOUT Comm_Pin, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory
OWIN Comm_Pin, 2, [Lo_ByteR, Hi_ByteR]' Read two bytes / end comms
SEROUT2 DISP,BAUD, [INS,CLR]
GOSUB Convert_Temp
pause 500
GOTO Start_Convert
Convert_Temp: ' +32.0 to +257 F
IF Cold_Bit = Real_Cold THEN Yikes ' If Cold_Bit = 1, it's below "0" deg C
Sign = "+"
Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
Dummy = 1125 * R_Temp
TempF = DIV32 100
IF TempF >6795 THEN ' Over 99.5 deg F..?
TempF = TempF + 3200
SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 4,_
DEC TempF DIG 3,DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
ELSE
TempF = TempF + 3200
SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 3,_
DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
ENDIF
pause 500
TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
Float = ((Lo_ByteR & $0F) * 625) ' Lower 4-bits of result * 625
'changed IBIN to display 12 bits only due to display limit of 16
SEROUT2 DISP,BAUD, [INS,LINE2, "R=", IBIN12 R_Temp]
pause 2000
RETURN
Bookmarks