Hi,
I've never used the DS18B20 or the DHT11.
Looking at the datasheet for the DS18B20 it seems like it returns the temperature in units of 0.1 degrees. Ie, if the returned value is 325 the actual temperature is 32.5C.
The DHT11 claims a resoultion of 8 bits and 1 degree but it still seems to send 16 bits of temperature data where the low byte is the decimal part (which I guess will always be 0).
Anyway, if you want to use the DHT11 instead of the DS18B20 what you want to do is make sure to scale the raw value so that they both give you the same value at a certain temperature. They might already DO that but you need to verify it. In the DS18B20 code your raw value seems to be the TempC variable while in the DHT11 code it's the temp variable.
At a known temperature (roughly) run the 18B20 code and output the TempC variable on the LCD. What does it say? Something like 225 for 22.5 degrees?
At the same temperarure (roughly) run the DHT11 code and output the Temp variable on the LCD. What does it say? Something like 220 for 22.5 degrees? Or something else?
If they are the same (roughly) then you're good to go as is. Otherwise you need to scale the DHT11 value so it gives the same result as the DS18B20 code for any given temperature (or you need to retune the PID filter).
With that said that DHT11 code looks REALLY convoluted, especially the highlighted part.
I wrote the following, not saying it'll work, have no sensor here to verify with.
Code:
PulsWidth VAR BYTE
BitValue VAR BIT
Humidity VAR WORD
Temperature VAR WORD
Checksum VAR BYTE
Main:
GOSUB ReadDHT11
LCDOUT $FE, 1, "RH: ", DEC Humidity, "%"
LCDOUT $FE, $C0, "Temp: ", DEC Temperature, "c"
PAUSE 1000
Goto Main
ReadDHT11:
' DHT11 reference: http://www.micropik.com/PDF/dht11.pdf
' Datasheet says resolution is 8 bits yet it sends 16 bits
' of data. This might be legacy from the higher resolution
' DHT22 sensor and the lower byte (the decimal part) is
' probably 0 all the time. No sensor here to verify with
' and datasheet is typical Chinese cut'n'paste stuff....
' Add the starbit stuff here !
' Read 16 bits of humidity data
FOR x = 15 to 0 step - 1
GOSUB GetBit
Humidity.0[x] = BitValue
NEXT x
' Read 16 bits of temperature data
FOR x = 15 to 0 step - 1
GOSUB GetBit
Temperature.0[x] = BitValue
NEXT x
' Read 8 bits of checksum data
FOR x = 7 to 0 step - 1
GOSUB GetBit
Checksum.0[x] = BitValue
NEXT x
' Checksum is the 8 bit sum of the 4 databytes
' this could be calculated and verified against
' the recieved checksum here.
RETURN
GetBit:
PulsIn PORTA.5, 1, PulsWidth
IF PulsWidth >= 9 AND PulsWidth <= 21 THEN BitValue = 0 ' if pulsewidth between 20 and 40uS then read as '0'
IF PulsWidth >= 29 AND PulsWidth <= 21 THEN BitValue = 1 ' if pulsewidth between 60 and 80uS then read as '1'
RETURN
/Henrik.
Bookmarks