سلام دوستان
یه دماسنج با مگا8 وdht22 دارم که مقدار دما توسط hmt hmrبه یه مگا32 منتقل میشه ونمایش داده میشه،مشکل اینجاست که برنامه حدودا 1.5ثانیه طول میکشه تا به خط انتقال کد وانتقال مقدار دما برسه وچون طی این مدت فرستنده غیر فعاله ،گیرنده نویزی میشه
به نظرتون برای حل مشکل چکار باید کرد
زبان: بیسیک وبسکام
کد دماسن وفرستنده:
$regfile = "m8def.dat"
'$crystal = 8000000 'Const Min_time = 48
'$crystal = 16000000 'Const Min_time = 95
$crystal = 11059200 'Const Min_time = 66
'-------------------------------------------------------------------------------
Config Portb.0 = Input 'DHT22 Data
Config Timer0 = Timer , Prescale = 8
'.-------------------------------------------------------------------------------
'Const Min_time = 95
'Const Min_time = 48
Const Min_time = 61
'-------------------------------------------------------------------------------
Dim F1 As Eram Single
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 F As String * 4
Dim Code As Byte
Dim Strstring As String * 14
Dim Ib As Byte
Dim S As Byte
'-------------------------------------------------------------------------------
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Pinc.3 , Db5 = Pinc.2 , Db6 = Pinc.1 , Db7 = Pinc.0 , E = Pinc.4 , Rs = Pinc.5
Cursor Off
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
Code = 250
S = 0
'-------------------------------------------------------------------------------
Do
Call Humtemp_values
Humiditys = Str(humidityw)
Temperatures = Str(temperaturew)
F = Format(temperatures , "0.0"
Printbin Code
Printbin Code
Printbin Code
Printbin Code
Printbin Code
Printbin Code
Printbin Code
Printbin Code
Printbin F
Loop
End
'-------------------------------------------------------------------------------
Sub Read_timings
Wait 1
Count = 1
Config Pinb.0 = Output : Portb.0 = 0 ' request data
Waitms 20 ' wait 20 ms
Config Pinb.0 = Input ' wait for data, receive data
While Count < 43 'collect 42 timings / signals
Bitwait Pinb.0 , Set 'signal goes high > start timer
Start Timer0
Bitwait Pinb.0 , Reset 'signal goes low > stop timer
Stop Timer0
Signaltime(count) = Tcnt0 '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 = "m32def.dat"
$crystal = 11059200
$baud = 9600
Config Timer0 = Timer , Prescale = 8
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Pinc.3 , Db5 = Pinc.2 , Db6 = Pinc.1 , Db7 = Pinc.0 , E = Pinc.4 , Rs = Pinc.5
Cursor Off
Deflcdchar 0 , 14 , 10 , 14 , 32 , 32 , 32 , 32 , 32
Dim F As String * 4
Dim T As Single
Dim Code As Byte
Cls
Lcd "no data"
Do
Code = Waitkey()
If Code = 250 Then
Inputbin F
Cls
Lcd "Temp:"
Lcd F
Lcd Chr(0)
Lcd "C"
End If
Loop
End
یه دماسنج با مگا8 وdht22 دارم که مقدار دما توسط hmt hmrبه یه مگا32 منتقل میشه ونمایش داده میشه،مشکل اینجاست که برنامه حدودا 1.5ثانیه طول میکشه تا به خط انتقال کد وانتقال مقدار دما برسه وچون طی این مدت فرستنده غیر فعاله ،گیرنده نویزی میشه
به نظرتون برای حل مشکل چکار باید کرد
زبان: بیسیک وبسکام
کد دماسن وفرستنده:
$regfile = "m8def.dat"
'$crystal = 8000000 'Const Min_time = 48
'$crystal = 16000000 'Const Min_time = 95
$crystal = 11059200 'Const Min_time = 66
'-------------------------------------------------------------------------------
Config Portb.0 = Input 'DHT22 Data
Config Timer0 = Timer , Prescale = 8
'.-------------------------------------------------------------------------------
'Const Min_time = 95
'Const Min_time = 48
Const Min_time = 61
'-------------------------------------------------------------------------------
Dim F1 As Eram Single
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 F As String * 4
Dim Code As Byte
Dim Strstring As String * 14
Dim Ib As Byte
Dim S As Byte
'-------------------------------------------------------------------------------
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Pinc.3 , Db5 = Pinc.2 , Db6 = Pinc.1 , Db7 = Pinc.0 , E = Pinc.4 , Rs = Pinc.5
Cursor Off
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
Code = 250
S = 0
'-------------------------------------------------------------------------------
Do
Call Humtemp_values
Humiditys = Str(humidityw)
Temperatures = Str(temperaturew)
F = Format(temperatures , "0.0"

Printbin Code
Printbin Code
Printbin Code
Printbin Code
Printbin Code
Printbin Code
Printbin Code
Printbin Code
Printbin F
Loop
End
'-------------------------------------------------------------------------------
Sub Read_timings
Wait 1
Count = 1
Config Pinb.0 = Output : Portb.0 = 0 ' request data
Waitms 20 ' wait 20 ms
Config Pinb.0 = Input ' wait for data, receive data
While Count < 43 'collect 42 timings / signals
Bitwait Pinb.0 , Set 'signal goes high > start timer
Start Timer0
Bitwait Pinb.0 , Reset 'signal goes low > stop timer
Stop Timer0
Signaltime(count) = Tcnt0 '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 = "m32def.dat"
$crystal = 11059200
$baud = 9600
Config Timer0 = Timer , Prescale = 8
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Pinc.3 , Db5 = Pinc.2 , Db6 = Pinc.1 , Db7 = Pinc.0 , E = Pinc.4 , Rs = Pinc.5
Cursor Off
Deflcdchar 0 , 14 , 10 , 14 , 32 , 32 , 32 , 32 , 32
Dim F As String * 4
Dim T As Single
Dim Code As Byte
Cls
Lcd "no data"
Do
Code = Waitkey()
If Code = 250 Then
Inputbin F
Cls
Lcd "Temp:"
Lcd F
Lcd Chr(0)
Lcd "C"
End If
Loop
End
دیدگاه