Richard,
need some additional help. The following code compiled, but displayed RH 0.0 and tmr 0 on the LCD. I changed the values for badread and noise as suggested, but still have the same result. As mentioned I'm using a 10 mhz crystal with HS_ppl enabled to run the pic at 40 Mhz. Could you point me in the right direction as to what I'm doing wrong ?
Code:; config settings 18F4580, 10mhz crystal HSPPL ASM __CONFIG _CONFIG1H, _OSC_HSPLL_1H __CONFIG _CONFIG2L, _PWRT_ON_2L __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H __CONFIG _CONFIG3H, _PBADEN_OFF_3H __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L ENDASM DEFINE OSC 40 ADCON1 = $0F clear INCLUDE "alldigital.pbp" CMCON = 7 TRISA = %11001111 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 ASM hum = _dht+3 tempa = _dht+1 ENDASM T1CON = %00000001 ; free-running, 1:1 prescaler dht_data var PORTA.1 dht_dir var TRISA.1 dht var byte[5] tempa var word EXT bits var byte crc var byte hum var word EXT main: gosub read_dht LCDOut $FE,$94,"rh ",#hum/10,".",dec1 hum//10 pause 4000 goto main read_dht: for bits=4 to 0 step-1 dht[bits]=0 next tmr2=0 dht_dir=0 dht_data=0 pauseus 1000 'start it up dht_data=1 pauseus 30 dht_dir=1 pauseus 40 'wait till middle of response pulse window if ( dht_data)then goto badread 'no response then give up while (!dht_data) wend t2con=6 while ( dht_data) wend t2con=0 if ((tmr2 <75)||(tmr2>85))then goto badread ' confirm presence ? for bits =39 to 0 step -1 tmr2=0 while (!dht_data) wend t2con=6 while ( dht_data) wend t2con=0 if ((tmr2>20)&&(tmr2<80)) then ' noise ? if (tmr2 >50 ) then dht.0[bits] = 1 endif else goto badread ' noise ? endif next crc=0 for bits=1 to 4 crc=crc+ dht[bits] next if crc != dht[0] then goto badcrc 'crc return badread: LCDOut $FE,$94 +8,"tmr6 ",#tmr2 for bits=4 to 0 step-1 dht[bits]=0 next return badcrc: for bits=4 to 0 step-1 LCDOut $FE,$94 +16,hex dht[bits],"," next return




Bookmarks