Guys thanks for your continued input.
using the #hum/100 gives 87% as the value, which to me seems rather humid, especially when the indoor humidity according to my maplins weather station says it's 51%. As a comparison I tried the following code which uses the pause and pulsein statements to read the chip
This gives 174c in our living room, with the humidity fluctuating between three values of 24%, 144% and 152%. Clearly there is something wrong with the hardware. I'm using a new solderless breadboard so I'll look at hard wiring the sensor and see if that helps, even though the connections between the Easypic board and sensor are next to each otherCode:ASM __CONFIG _CONFIG1H, _OSC_HS_1H __CONFIG _CONFIG2L, _PWRT_ON_2L __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H __CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L ENDASM '******************************************************************************* ' LCD (20 x 4) set up '******************************************************************************* DEFINE LCD_DREG PORTB ' LCD Data port DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4) DEFINE LCD_EREG PORTB ' LCD Enable port DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD) DEFINE LCD_RSREG PORTB ' LCD Register Select port DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD) DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits) DEFINE LCD_LINES 4 ' number of lines on LCD DEFINE LCD_COMMANDUS 2000 ' Command delay time in us DEFINE LCD_DATAUS 50 ' Data delay time in us '******************************************************************************* ' Defines Statements '******************************************************************************* DEFINE OSC 20 ' 18F4520 / 18F2520, 20mhz crystal ADCON1 = $0F clear '******************************************************************************* 'Analog and Comparator settings '******************************************************************************* ADCON0 = %00000000 'AD converter module disabled ADCON1 = %00001111 'All Digital ADCON2 = %00000000 CMCON = 7 'Disable Comparators '******************************************************************************* 'Port and Register settings (interrupts) '******************************************************************************* TRISA = %00010111 TRISB = %00000011 T0CON = %11000111 T1CON = %00000001 ; free-running, 1:1 prescaler TMR1H = %11111111 TMR1L = %11111011 '******************************************************************************* LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 ' Initialize LCD '******************************************************************************* dht var byte[32] humidite var byte haut var byte bas var byte temp var byte x var byte dht11 var portA.1 '******************************************************************************* start: TRISA.1 = 0 ' high dht11 pause 2000 ' wait 2 sec low dht11 : pause 18' send 20ms low high dht11 : pauseus 30 ' send 40us hi TRISA.1 = 0 PulsIn PORTA.1, 1, haut if haut < 15 then goto start 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 humidite=dht[31]*128+dht[30]*64+dht[29]*32+dht[28]*16+dht[27]*8+dht[26]*4+dht[25]*2+dht[24]*1 temp=dht[15]*128+ dht[14]*64+dht[13]*32+dht[12]*16+dht[11]*8+dht[10]*4+dht[9]*2+dht[8]*1 lcdout $FE,1 lcdout $FE,$C0,"Humidite = ",#humidite,"% " lcdout $FE,$80,"Temperature = ",#temp,$DF,"C" goto start




Bookmarks