-
using the DS18B20
HI,
I have been trying to make a DS18S20 work, I have used the code on Rentron to guide me.
http://www.rentron.com/PicBasic/one-wire3.htm
BUt what I get around 3000 degrees as my output.
I basically took his code and removed the Fahrenheit calculation and put it on a LCDout command. with no minus temperature.
shouldn't the command Div32 give me the temperature in Celcius directly ?
ken
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, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
GOSUB Convert_Temp
GOTO Start_Convert
Convert_Temp:
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
Lcdout $fe, 1 'Clear screen
Lcdout "Value: ", DEC TempC, Deg,"C " 'Display the decimal value
RETURN
END
-
Hi lerameur,
In your code, after TempC = DIV32 10 you are missing following two lines.
Code:
Dummy = 1125 * R_Temp
TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
------------------------
-
I tried that too,but I get 2 degrees steady output. I thought it would be somewhere in my LCDout command,
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, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
GOSUB Convert_Temp
GOTO Start_Convert
'65
Convert_Temp: ' +32.0 to +257 F
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
TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
Float = ((R_Temp.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625
Lcdout $fe, 1 'Clear screen
Lcdout " TempC = ",Sign,DEC TempC,".",DEC Float,Deg,"C " 'Display the decimal value
RETURN
-
For the DS18S20 just read the temperature, divide by 2, and that will be the
temp in deg C for positive temps.
For negative temp in deg C, complement the value read, divide by 2, then
add 1. That's all you need to do for a DS18S20 deg C conversion.
The code you're trying to use is for a DS18B20 which is 12-bit. The DS18S20
isn't 12-bit. Compare both datasheets for an explanation.
-
If i look on the chip, it says DS1820, but on my order sheet from digikey it says DS18S20+CT-ND
You think they sent me the wrong chip ?
I got it working, juste did not seperate th loe and high bytes
k
-
HI I found this program ,
it seems to work , but it is 2 degrees higher then my other thermometer.
Ken
DQ var PortB.3
temp var word
loop:
owout DQ,1,[$cc]
owout DQ,0,[$44]
Pause 500
owout DQ,1,[$cc]
owout DQ,0,[$be]
owin DQ,0,[temp.byte0,temp.byte1]
lcdout $FE,1
temp=temp*5
lcdout " Temp = ",DEC2 temp/10,".", dec1 temp," ",$DF,"C"
goto loop
End
-
i got this part to work fine now