سلام دوستان برنامه پایین کد پروژه رطوبت سنجه که من توی قسمت read_dht_sensor ش مشکل دارم( توی اعدادی که نوشته) اگه کسی بلده کمکککککک کنه بهم بگه چی میگه .....
کد:
$regfile = "m8def.dat"
$crystal = 8000000
$framesize = 128
$swstack = 168
$hwstack = 128
Osccal = 179
Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portc.4 , Rs = Portc.5
Config Lcd = 16 * 2
Deflcdchar 1 , 32 , 4 , 14 , 21 , 4 , 4 , 4 , 32 ' hoch
Deflcdchar 2 , 32 , 4 , 4 , 4 , 21 , 14 , 4 , 32 ' runter
Cursor Off Noblink
Cls
Dim New_lcd_data_flag As Bit
'_______________________________________________________________________________
'TIMER1
'-------------------------------------------------------------------------------
Config Timer1 = Timer , Prescale = 256
On Timer1 Isr_timer1
Enable Timer1
Timer1 = 34286
Start Timer1
Enable Interrupts
Dim Timer1_counter As Byte
Dim Sec_flag As Bit
Dim Mod_return As Byte
'_______________________________________________________________________________
'Softclock
'-------------------------------------------------------------------------------
Dim Sekunde As Word
Dim Minute As Word
Dim Stunde As Word
Dim Sekunde_s As String * 2
Dim Minute_s As String * 2
Dim Stunde_s As String * 2
Dim Double_point_flash As Bit
Dim Double_point As String * 1
Sekunde = 00
Minute = 00
Stunde = 16
'_______________________________________________________________________________
'DHT22 Sensor - PIN
'-------------------------------------------------------------------------------
Config Pinb.5 = Input
Config Timer0 = Timer , Prescale = 8
'-------------------------------------------------------------------------------
Const Min_time = 50 'this has to be changed according
Dim Count As Byte
Dim Timec As Byte
Dim X As Byte
Dim Chksum As Byte
Dim Humidityw As Word
Dim Temperaturew As Word
Dim Tneg As Byte 'indicate if temperature<0
Dim Humsens_chksum As Byte
Dim Humiditys As String * 16
Dim Temperatures As String * 16
Dim Temp1 As String * 5
Dim Temp_dht_offset As Integer
Dim Humidity_dht_offset As Integer
Dim Read_temp_flag As Bit
Dim Dht_error As Bit
Dim Dht_error_counter As Byte
Temp_dht_offset = 00
Humidity_dht_offset = 00
'_______________________________________________________________________________
Gosub Read_dht_sensor
Waitms 300
If Dht_error = 1 Then
Locate 2 , 1
Lcd "Err Sensor DHTxx"
Else
Locate 2 , 1
Lcd "Sensor DHTxx OK "
End If
Wait 1
Cls
Timer1_counter = 5
Do
If Sec_flag = 1 Then
Sec_flag = 0
Gosub Uhrzeit
Mod_return = Timer1_counter Mod 5
If Mod_return = 0 Then
Gosub Read_dht_sensor
End If
End If
If Dht_error = 1 Then Gosub Dht_error_handling
If New_lcd_data_flag = 1 Then Gosub Write_lcd_data
If Timer1_counter > 59 Then Timer1_counter = 0
Loop
End
Dht_error_handling:
Dht_error = 0
Locate 2 , 1
Lcd "wait Sensor "
Return
Write_lcd_data:
New_lcd_data_flag = 0
Locate 2 , 1
Lcd "T=" ; Format(temperatures , "#.#") ; Chr(223) ; "C" ; " "
If Humiditys > "99.9" Then
Locate 1 , 1
Lcd "H=" ; Format(humiditys , "#.#") ; "%"
Else
Locate 1 , 1
Lcd "H=" ; Format(humiditys , "#.#") ; "%"
End If
Return
'_______________________________________________________________________________
Read_dht_sensor:
Humidityw = 0
Temperaturew = 0
Humsens_chksum = 0
Count = 1
Config Pinb.5 = Output : Portb.5 = 0
Waitms 20
Config Pinb.5 = Input
While Count < 43 And Dht_error = 0
While Tcnt0 < 100
If Tcnt0 > 95 Then
Incr Dht_error_counter
Dht_error = 1
Return
End If
If Pinb.5 = 1 And Tcnt0 = 0 Then Start Timer0
If Pinb.5 = 0 And Tcnt0 > 0 Then
Stop Timer0
Timec = Tcnt0
Tcnt0 = 100
End If
Wend
Tcnt0 = 0
Select Case Count
Case 3 To 18
X = 18 - Count
If Timec > Min_time Then Toggle Humidityw.x
Case 19 To 34
X = 34 - Count
If Timec > Min_time Then Toggle Temperaturew.x
Case 34 To 42
X = 42 - Count
If Timec > Min_time Then Toggle Humsens_chksum.x
End Select
Incr Count
Wend
If Dht_error = 0 Then
Chksum = Low(humidityw) + High(humidityw)
Chksum = Chksum + Low(temperaturew)
Chksum = Chksum + High(temperaturew)
If Chksum = Humsens_chksum Then
Temperatures = ""
If Temperaturew.15 = 1 Then
Temperaturew.15 = 0
Temperatures = "-"
End If
Humidityw = Humidityw + Humidity_dht_offset
Humiditys = Str(humidityw)
Temperaturew = Temperaturew + Temp_dht_offset
Temperatures = Temperatures + Str(temperaturew)
Dht_error_counter = 0
New_lcd_data_flag = 1
End If
End If
Return
Uhrzeit:
If Sekunde < 59 Then
Incr Sekunde
Elseif Minute < 59 Then
Incr Minute
Sekunde = 0
Elseif Stunde < 23 Then
Incr Stunde
Sekunde = 0
Minute = 0
Else
Sekunde = 0
Minute = 0
Stunde = 0
End If
Sekunde_s = Str(sekunde)
Minute_s = Str(minute)
Stunde_s = Str(stunde)
Return
Isr_timer1:
Timer1 = 34286
Set Sec_flag
Incr Timer1_counter
Return