With bascom it is usually easy to change chips its as simple as changing the $regfile to the chip you are using if the pin-out is identical then hardware changes are not need most of the time. I will be interested when you get this working if the humidity it reads is accurate I have played with the DHT11 and found it to be so far out that its useless. I have compared it to a wet/dry hygrometer made by Bacharach Instruments and while this shows 64% the DHT11 showed 37%, the temperature reading is ok. I have other devices that use similar sensors they all show readings that are also way off. Indeed on one day it was poring rain and the best it could do was 42% while the wet/dry was 87%. I also found a number of discussions on the net saying the same thing.
Regards Paul
Here is code I worked on
[code:1:c71a5b35b2]
$regfile = "m168def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
$baud = 2400 ' use baud rate
$hwstack = 200
$swstack = 200
$framesize = 200
Dim Tmp As Byte
Dim H As Byte
Dim Crc As Byte
Dim Mybyte As Byte
Dim Dht11(5) As Byte '5 bytes for 40 bits
Dim Dht(2) As String * 16
'--Created 5 global bytes so no longer pass data
'Declare Sub Get_th(tmp As Byte , H As Byte)
Declare Sub Get_th
Config Lcdpin = Pin , Db4 = Portd.5 , Db5 = Portd.4 , Db6 = Portd.3 , Db7 = Portd.2 , E = Portd.6 , Rs = Portd.7
Config Lcd = 16x2
Dht_put Alias Portc.5
Dht_get Alias Pinc.5
Dht_io_set Alias Ddrc.5
'Config Dht_get = Input
Do
Wait 4
Call Get_th
Cls
Locate 1 , 1
Lcd "Temp " ; Tmp
Locate 2 , 1
Lcd "Humidity " ; H
Wait 5
Cls
Locate 1 , 1
Lcd "crc>" ; Crc 'Dht(1)
Locate 2 , 1
Lcd "added>" ; Mybyte 'Dht(2)
Wait 5
Loop
End
Sub Get_th
'Local Crc As Byte
'Local Mybyte As Byte
Local Sensor_data As String * 40
Local Tmp_str8 As String * 8
Local Tmphex As String * 2
Local Hhex As String * 2
Local Count As Byte
Count = 0
Sensor_data = ""
Set Dht_io_set
Reset Dht_put
Waitms 25
Set Dht_put
Waitus 40
Reset Dht_io_set
Waitus 40
If Dht_get = 1 Then
H = 1
Exit Sub
End If
Waitus 80
If Dht_get = 0 Then
H = 2
Exit Sub
End If
While Dht_get = 1 : Wend
Do
While Dht_get = 0 : Wend
Waitus 30
If Dht_get = 1 Then
Sensor_data = Sensor_data + "1"
While Dht_get = 1 : Wend
Else
Sensor_data = Sensor_data + "0"
End If
Incr Count
Loop Until Count = 40
Set Dht_io_set
Set Dht_put
Tmp_str8 = Left(sensor_data , 8)
H = Binval(tmp_str8)
Dht(1) = Left(sensor_data , 16)
Tmp_str8 = Mid(sensor_data , 17 , 8)
Tmp = Binval(tmp_str8)
Dht(2) = Mid(sensor_data , 17 , 16)
Tmp_str8 = Right(sensor_data , 8)
Crc = Binval(tmp_str8)
Mybyte = Tmp + H
If Mybyte <> Crc Then
H = 3
'Else
'H = Makedec(h)
'Hhex = Str(h)
'H = Hexval(hhex)
' Tmp = Makedec(tmp)
' Tmphex = Str(tmp)
' Tmp = Hexval(tmphex)
End If
'Lcd "Temperature " ; Tmp
'Lcd "Humidity " ; H
End Sub
[/code:1:c71a5b35b2]
↧