View Full Version : Ds18b20
ahmed_salah
- 3rd June 2009, 15:38
i have a problem i made temp sensore project based on ds1820 but i want to replace it with ds18B20 for high resolution but when i change it i got strange readings , i think that i have to change something in code can some one help me do that attached is code
fratello
- 6th June 2009, 18:51
OWOut DQ, 1, [$CC, $4E, 0, 0, DS18B20_12bit] '
OWOut DQ, 1, [$CC, $44] ' Start conversion
WaitLoop:
While not DQ
Wend
OWOut DQ, 1, [$CC, $BE]
OWIn DQ, 2, [Temperature.Lowbyte, Temperature.Highbyte]
Convert_Temp:
If Temperature.15 then
Temperature= ~Temperature +1
Twist = 1
Endif
TempC = (Temperature & $7FF) >> 4
Float = ((Temperature.Lowbyte & $0F ) * 25 )>>2
Temperature = TempC*100 + Float
If Twist then
V= 10000 - Temperature ' 25 C=12500 0 C=10000 -10 C=9000
Twist = 0
else
V= 10000 + Temperature
EndIf
' SUBROUTINES:
'----------------------------------------
SelectSign:
If v = 10000 then ' Temperature = 0 C.
Sign=" " ' No sign
Else
If v < 10000 then ' <> 0
Sign="-" ' Temperature below 0 C.
Else
Sign="+" ' Temperature above 0 C.
EndIf
EndIf
Return
'----------------------------------------
DisplayTemp:
If V >= 10000 then ' Above 0 C.
Temperature=V-10000
Else
Temperature=10000-V ' Below 0 C.
EndIf
LcdOut $FE, $C0, Sign, DEC (Temperature / 100), ".", DEC2 Temperature, " ",223,"C "
Return
ahmed_salah
- 7th June 2009, 09:23
hi,
thanks for replay but i am beginner in pbp so can u guide me where is the part i have to replace in my old code
ahmed_salah
- 7th June 2009, 10:45
hi,
i update the code u send me before can u check it please soi can begin testing
Acetronics2
- 7th June 2009, 10:57
Hi, Ahmed
This subject in the SEARCH function of the Forum Gives 72 Hits ... including working programs for the 18B20
so, just use it !!!
Alain
ahmed_salah
- 7th June 2009, 18:42
hi,
no replies nothing work tell now i got blank screen
fratello
- 8th June 2009, 06:50
Put here the schematic, please.
Acetronics2
- 8th June 2009, 08:39
Hi, Ahmed
Just comparing the 18B20 Datasheet, page 5 to the 1820 Data., Page 4 will help you to understand how temperatures are coded in both cases ...
and what you have to modify to get a nice result ...
Alain
ahmed_salah
- 8th June 2009, 09:31
hi,
thanks for replay please find attached schematic
i am trying also to get rom id for ds18b20 but i got only 8 hex digit attached is the code
Acetronics2
- 8th June 2009, 09:44
At first, try
...
for i = 0 to 7
LcdOut HEX2 ID[i]
next i
...
should print missing Zeroes ...
Alain
ahmed_salah
- 8th June 2009, 10:34
hi,
acetronics , still got 8 characters only
ahmed_salah
- 9th June 2009, 06:35
hi,
i update the code to read rom id and i can read it now working code attached , but still can not read temp. any update
fratello
- 9th June 2009, 10:56
Here is all that You have need : http://www.picbasic.co.uk/forum/showthread.php?t=10345&highlight=ds18b20
ahmed_salah
- 13th June 2009, 22:00
hi,
thanks for help i update the code and i can read temp now but the resolution is 0.5 degree even when i set resolution to 12 bit , attached is the code
fratello
- 14th June 2009, 08:00
Try this, please and post the results.
mvs_sarma
- 14th June 2009, 08:46
Try this, please and post the results.
the file had four Minor errors. corrected file and a complied hex are attached
ahmed_salah
- 14th June 2009, 09:35
hi,
can u please send me picbasic code so i can know where is the error cause i am not god in assembely
ahmed_salah
- 14th June 2009, 09:50
hi,
i try the code u send me but still the same result nochange the resolution still 0.5
Acetronics2
- 14th June 2009, 13:01
Hi, Ahmed
No surprise ... you do not write tte DS Config Word in the right registers ...
our friend Fratello saw that ( and corrected it ... )
a pair of zeros is missing in your command line ...
Alain
ahmed_salah
- 14th June 2009, 13:35
hi,
still the same resolution 0.5 even after i update the code , attached is the code u send me if u want to check
Acetronics2
- 14th June 2009, 14:24
Hi, Ahmed
I must admit Fratello's program only shows half degrees ... ( just tested on an EasyPic 5 )
but still have not found Why !!!
Alain
ahmed_salah
- 14th June 2009, 14:32
hi,
i am using pic basic pro 2.44 do u think this the problem
mvs_sarma
- 14th June 2009, 14:58
hi,
can u please send me picbasic code so i can know where is the error cause i am not god in assembely
complied code and also the corrected .asm are attached.
Acetronics2
- 14th June 2009, 15:00
Hi, Ahmed
I Finally got it !!!
the problem is in the Waiting loop ... that doesn't wait !!!
sooo... add :
Busy VAR BIT
at the top of the program
and change :
WaitLoop:
' While not DQ ' NOT Working !!!
' Wend
by
WaitLoop:
OWIn DQ, 4, [Busy] ' Check for still busy converting
'PORTC.4 = 1 ' Show waiting for conv complete
If Busy = 0 Then
GOTO waitloop
ENDIF
' PORTC.4 = 0
Port C.4 was chosen to show the time the DS is Busy ... very useful tool to verify conversion is really complete !!!
Have fun,
Alain
ahmed_salah
- 14th June 2009, 15:21
hi,
so thanks for help now i got resolution 1/100 i am so happy but i want to underestand what no 4 in statement OWIn DQ, 4, [Busy] means ???
i have another question i want to read the o/p to pc serial port i connect 1k resistance to portb.1 and send it to pc rx pin (2) and circuit ground to pc gnd pin (5)
note : i am using usb to serial converter
i update the program just for testing to send a message but i notice that the Rx led on usb to serial converter flashes and nothing out on hyberterminal ????
attached is code
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.