سلام دوستان من یه برنامه راه اندازی سنسور رطوبت dhtt22 دارم که کامل جواب میده اما یک مشکلی هست تویه یک قسمت برنامه که با رنگ قرمز مشخص کرئم میاد فاصله زمانی قطع و وصل شدن پینی که سنسور بهش وصله اندازه میگیره و این فاصله رو با تایمر 0 میکرو اندازه میگیره , حالا راهی است که بشه از تایمر استفاده نکرد؟؟؟ من با pulsein امتحان کردم جواب نگرفتم!!!! خیلی کارم گیره دوستان یه کمکی برسونید
$regfile = "m16adef.dat"
$crystal = 8000000 'Const Min_time = 48
'$crystal = 16000000 'Const Min_time = 95
'$crystal = 11059200 'Const Min_time = 66
'-------------------------------------------------------------------------------
Config Pind.0 = Input 'DHT22 Data
Config Timer0 = Timer , Prescale = 8
'.-------------------------------------------------------------------------------
'Const Min_time = 95
Const Min_time = 48
'Const Min_time = 66
'-------------------------------------------------------------------------------
Dim Count As Byte
Dim Signaltime(43) As Byte
Dim Humidityw As Word
Dim Temperaturew As Word
Dim Humsens_chksum As Byte
Dim Humiditys As String * 16
Dim Temperatures As String * 16
Dim Strstring As String * 14
Dim Ib As Byte
'-------------------------------------------------------------------------------
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Pina.2 , Db5 = Pina.3 , Db6 = Pina.4 , Db7 = Pina.5 , E = Pina.1 , Rs = Pina.0
Cursor Off
Cls
Cls
Deflcdchar 0 , 14 , 10 , 14 , 32 , 32 , 32 , 32 , 32 ' replace ? with number (0-7)
'-------------------------------------------------------------------------------
Declare Sub Read_timings
Declare Sub Humtemp_values
Declare Function Compare_chksum(byval Hsens_humidity As Word , _
Byval Hsens_temperature As Word , Byval Hsens_chksum As Byte) As Byte
'-------------------------------------------------------------------------------
Do
Call Humtemp_values
Humiditys = Str(humidityw)
Temperatures = Str(temperaturew)
Locate 1 , 1
Lcd "Humidity:" ; Format(humiditys , "0.0"
; " % "
Lowerline
Lcd "Temp:" ; Format(temperatures , "0.0"
: Lcd " " : Lcd Chr(0) : Lcd "C"
Waitms 100
Loop
End
'-------------------------------------------------------------------------------
Sub Read_timings
Wait 3
Count = 1
Config Pind.0 = Output : Portd.0 = 0 ' request data
Waitms 20 ' wait 20 ms
Config Pind.0 = Input ' wait for data, receive data
While Count < 43 'collect 42 timings / signals
Bitwait Pind.0 , Set 'signal goes high > start timer
Start Timer0
Bitwait Pind.0 , Reset 'signal goes low > stop timer
Stop Timer0
Signaltime(count) = Tcnt0 / 7 'store number of ticks per signal in Signaltime byte
Tcnt0 = 0
Incr Count
Wend
End Sub
'############################################ ## Humidity and temperature values
Sub Humtemp_values
Local X As Byte
Humidityw = 0
Temperaturew = 0
Humsens_chksum = 0
Call Read_timings
For Count = 3 To 42 ' skip first two
Select Case Count
Case 3 To 18
X = 18 - Count
If Signaltime(count) > Min_time Then Toggle Humidityw.x
Case 19 To 34
X = 34 - Count
If Signaltime(count) > Min_time Then Toggle Temperaturew.x
Case 34 To 42
X = 42 - Count
If Signaltime(count) > Min_time Then Toggle Humsens_chksum.x
End Select
Next
End Sub
'######################### Calculate Checksum and compare with trasnmitted value
Function Compare_chksum(byval Hsens_humidity As Word , Byval Hsens_temperature As Word , Byval Hsens_chksum As Byte) As Byte
Local Chksum As Byte
Chksum = Low(hsens_humidity ) + High(hsens_humidity )
Chksum = Chksum + Low(hsens_temperature)
Chksum = Chksum + High(hsens_temperature)
If Chksum = Hsens_chksum Then
Compare_chksum = 1
Else
Compare_chksum = 0
End If
End Function
$regfile = "m16adef.dat"
$crystal = 8000000 'Const Min_time = 48
'$crystal = 16000000 'Const Min_time = 95
'$crystal = 11059200 'Const Min_time = 66
'-------------------------------------------------------------------------------
Config Pind.0 = Input 'DHT22 Data
Config Timer0 = Timer , Prescale = 8
'.-------------------------------------------------------------------------------
'Const Min_time = 95
Const Min_time = 48
'Const Min_time = 66
'-------------------------------------------------------------------------------
Dim Count As Byte
Dim Signaltime(43) As Byte
Dim Humidityw As Word
Dim Temperaturew As Word
Dim Humsens_chksum As Byte
Dim Humiditys As String * 16
Dim Temperatures As String * 16
Dim Strstring As String * 14
Dim Ib As Byte
'-------------------------------------------------------------------------------
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Pina.2 , Db5 = Pina.3 , Db6 = Pina.4 , Db7 = Pina.5 , E = Pina.1 , Rs = Pina.0
Cursor Off
Cls
Cls
Deflcdchar 0 , 14 , 10 , 14 , 32 , 32 , 32 , 32 , 32 ' replace ? with number (0-7)
'-------------------------------------------------------------------------------
Declare Sub Read_timings
Declare Sub Humtemp_values
Declare Function Compare_chksum(byval Hsens_humidity As Word , _
Byval Hsens_temperature As Word , Byval Hsens_chksum As Byte) As Byte
'-------------------------------------------------------------------------------
Do
Call Humtemp_values
Humiditys = Str(humidityw)
Temperatures = Str(temperaturew)
Locate 1 , 1
Lcd "Humidity:" ; Format(humiditys , "0.0"

Lowerline
Lcd "Temp:" ; Format(temperatures , "0.0"

Waitms 100
Loop
End
'-------------------------------------------------------------------------------
Sub Read_timings
Wait 3
Count = 1
Config Pind.0 = Output : Portd.0 = 0 ' request data
Waitms 20 ' wait 20 ms
Config Pind.0 = Input ' wait for data, receive data
While Count < 43 'collect 42 timings / signals
Bitwait Pind.0 , Set 'signal goes high > start timer
Start Timer0
Bitwait Pind.0 , Reset 'signal goes low > stop timer
Stop Timer0
Signaltime(count) = Tcnt0 / 7 'store number of ticks per signal in Signaltime byte
Tcnt0 = 0
Incr Count
Wend
End Sub
'############################################ ## Humidity and temperature values
Sub Humtemp_values
Local X As Byte
Humidityw = 0
Temperaturew = 0
Humsens_chksum = 0
Call Read_timings
For Count = 3 To 42 ' skip first two
Select Case Count
Case 3 To 18
X = 18 - Count
If Signaltime(count) > Min_time Then Toggle Humidityw.x
Case 19 To 34
X = 34 - Count
If Signaltime(count) > Min_time Then Toggle Temperaturew.x
Case 34 To 42
X = 42 - Count
If Signaltime(count) > Min_time Then Toggle Humsens_chksum.x
End Select
Next
End Sub
'######################### Calculate Checksum and compare with trasnmitted value
Function Compare_chksum(byval Hsens_humidity As Word , Byval Hsens_temperature As Word , Byval Hsens_chksum As Byte) As Byte
Local Chksum As Byte
Chksum = Low(hsens_humidity ) + High(hsens_humidity )
Chksum = Chksum + Low(hsens_temperature)
Chksum = Chksum + High(hsens_temperature)
If Chksum = Hsens_chksum Then
Compare_chksum = 1
Else
Compare_chksum = 0
End If
End Function
دیدگاه