پاسخ : مشکل با سنسور DHT11
احمد جان من موندم چرا با لینکا مشکل داری :mrgreen:
برات فرستادم
نوشته اصلی توسط ahmad6870
برات فرستادم
$regfile = "m8def.dat" $crystal = 8000000 Declare Sub Get_th(t As Byte , H As Byte) Config Single = Scientific , Digits = 1 Dht_put Alias Portc.0 Dht_get Alias Pinc.0 Dht_io_set Alias Ddrc.0 Config Portc.2 = Output Config Portc.3 = Output Config Portc.4 = Output Config Portc.5 = Output Config Portb = Output Dim T As Byte Dim H As Byte Dim Crc As Byte Dim Mybyte As Byte Dim Sensor_data As String * 40 Dim Tmp_str8 As String * 8 Dim Count As Byte Dim T_ As Single Dim T_1 As Byte Dim H_ As Single Dim H_1 As Byte Dim T_2 As Single Dim T_3 As Byte Dim H_2 As Single Dim H_3 As Byte Enable Interrupts Set Dht_io_set Set Dht_put '******************************************************************************* T = 25 H = 54 '******************************************************************************* Cls Do '############################################################################### 'Call Get_th(t , H) '############################################################################### T_ = T / 10 T_1 = Int(t_) H_ = H / 10 H_1 = Int(h_) T_2 = Frac(t_) T_2 = T_2 * 10 T_3 = Int(t_2) H_2 = Frac(h_) H_2 = H_2 * 10 H_3 = Int(h_2) Portc = &B1111011 Portb = Lookup(t_1 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 5 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B11110111 Portb = Lookup(t_3 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 5 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B1101111 Portb = Lookup(h_1 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 5 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B1011111 Portb = Lookup(h_3 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 5 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Loop Sub Get_th(t As Byte , H 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) Tmp_str8 = Mid(sensor_data , 17 , 8) T = Binval(tmp_str8) Tmp_str8 = Right(sensor_data , 8) Crc = Binval(tmp_str8) Mybyte = T + H If Mybyte <> Crc Then H = 3 End If End Sub Temp_humidity: Data &H3F , &H06 , &H5B , &H4F , &H66 , &H6D , &H7D , &H07 , &H7F , &H6F
$regfile = "m8def.dat" $crystal = 8000000 Declare Sub Get_th(t As Byte , H As Byte) Config Single = Scientific , Digits = 1 Dht_put Alias Portc.0 Dht_get Alias Pinc.0 Dht_io_set Alias Ddrc.0 Config Portc.2 = Output Config Portc.3 = Output Config Portc.4 = Output Config Portc.5 = Output Config Portb = Output Dim T As Byte Dim H As Byte Dim Crc As Byte Dim Mybyte As Byte Dim Sensor_data As String * 40 Dim Tmp_str8 As String * 8 Dim Count As Byte Dim T_ As Single Dim T_1 As Byte Dim H_ As Single Dim H_1 As Byte Dim T_2 As Single Dim T_3 As Byte Dim H_2 As Single Dim H_3 As Byte Enable Interrupts Set Dht_io_set Set Dht_put '******************************************************************************* T = 25 H = 54 '******************************************************************************* Cls Do '############################################################################### 'Call Get_th(t , H) '############################################################################### T_ = T / 10 T_1 = Int(t_) H_ = H / 10 H_1 = Int(h_) T_2 = Frac(t_) T_2 = T_2 * 10 T_3 = Int(t_2) H_2 = Frac(h_) H_2 = H_2 * 10 H_3 = Int(h_2) Portc = &B1111011 Portb = Lookup(t_1 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 5 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B11110111 Portb = Lookup(t_3 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 5 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B1101111 Portb = Lookup(h_1 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 5 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B1011111 Portb = Lookup(h_3 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 5 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Loop Sub Get_th(t As Byte , H 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) Tmp_str8 = Mid(sensor_data , 17 , 8) T = Binval(tmp_str8) Tmp_str8 = Right(sensor_data , 8) Crc = Binval(tmp_str8) Mybyte = T + H If Mybyte <> Crc Then H = 3 End If End Sub Temp_humidity: Data &H3F , &H06 , &H5B , &H4F , &H66 , &H6D , &H7D , &H07 , &H7F , &H6F
$regfile = "m8def.dat" $crystal = 8000000 Declare function Get_th(t As Byte , H As Byte) as Byte Config Single = Scientific , Digits = 1 Dht_put Alias Portc.0 Dht_get Alias Pinc.0 Dht_io_set Alias Ddrc.0 Config Portc.2 = Output Config Portc.3 = Output Config Portc.4 = Output Config Portc.5 = Output Config Portb = Output Dim T As Byte Dim H As Byte Dim Crc As Byte Dim Mybyte As Byte Dim Sensor_data As String * 40 Dim Tmp_str8 As String * 8 Dim Count As Byte Dim T_ As Single Dim T_1 As Byte Dim H_ As Single Dim H_1 As Byte Dim T_2 As Single Dim T_3 As Byte Dim H_2 As Single Dim H_3 As Byte Enable Interrupts Set Dht_io_set Set Dht_put '******************************************************************************* T = 25 H = 54 '******************************************************************************* Cls Do '############################################################################### H = Get_th(t , H) '############################################################################### T_ = T / 10 T_1 = Int(t_) H_ = H / 10 H_1 = Int(h_) T_2 = Frac(t_) T_2 = T_2 * 10 T_3 = Int(t_2) H_2 = Frac(h_) H_2 = H_2 * 10 H_3 = Int(h_2) Portc = &B1111011 Portb = Lookup(t_1 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 2 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B11110111 Portb = Lookup(t_3 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 2 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B1101111 Portb = Lookup(h_1 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 2 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B1011111 Portb = Lookup(h_3 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 2 Portc = &B1111111 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Loop Function Get_th(t As Byte , H As Byte) Count = 0 Sensor_data = "" Set Dht_io_set Reset Dht_put Waitms 20 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 Portc = &B1111011 Portb = Lookup(t_1 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 2 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B11110111 Portb = Lookup(t_3 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 2 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B1101111 Portb = Lookup(h_1 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 2 '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Portc = &B1011111 Portb = Lookup(h_3 , Temp_humidity) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Waitms 2 Portc = &B1111111 Tmp_str8 = Left(sensor_data , 8) H = Binval(tmp_str8) Tmp_str8 = Mid(sensor_data , 17 , 8) T = Binval(tmp_str8) Tmp_str8 = Right(sensor_data , 8) Crc = Binval(tmp_str8) Mybyte = T + H If Mybyte <> Crc Then H = 3 End If End Function Temp_humidity: Data &H3F , &H06 , &H5B , &H4F , &H66 , &H6D , &H7D , &H07 , &H7F , &H6F
دیدگاه