You could possibly do something like this...
Code:
hum var word
j var byte
x var byte
read_dht:
TRISA.1 = 0 '
high dht_data
low dht_data : pause 18' send 18ms low
high dht_data : pauseus 30 ' send 30us hi
TRISA.1 = 0
PulsIn PORTA.1, 1, dht
if dht < 9 then goto badresponse
for x = 31 to 0 step-1
PulsIn PORTA.1, 1, dht[x] ' 1
next x
'For x = 31 to 0 step-1
' if dht(x)>=9 and dht(x)<=21 then dht(x)=0 'if pulsewidth between 20 and 40uS then read as '0'
' if dht(x)>=29 and dht(x)<=41 then dht(x)=1 'if pulsewidth between 60 and 80uS then read as '1'
'next x
'Stuff values into hum word variable based on pulsewidth value in dht byte arrary
j = 15
for x = 31 to 16 step - 1
if dht(x)>=9 and dht(x)<=21 then hum.0[j] = 0
if dht(x)>=29 and dht(x)<=41 then hum.0[j] = 1
j = j-1
next x
Bookmarks