Dht11 - 16f877a


Closed Thread
Results 1 to 15 of 15

Thread: Dht11 - 16f877a

Hybrid View

  1. #1
    Join Date
    Jan 2004
    Location
    Thessaloniki , GREECE
    Posts
    61


    Did you find this post helpful? Yes | No

    Default Re: Dht11 - 16f877a

    @Thanasis ...if you want to keep 20Mhz try to change

    if pulse(x)>=2 and pulse(x)<=4 then p(x)=0 'if pulsewidth between 20 and 40uS then read as '0'
    if pulse(x)>=6 and pulse(x)<=8 then p(x)=1 'if pulsewidth between 60 and 80uS then read as '1'

    to this one

    if pulse(x)>=9 and pulse(x)<=21 then p(x)=0 'if pulsewidth between 20 and 40uS then read as '0'
    if pulse(x)>=29 and pulse(x)<=41 then p(x)=1 'if pulsewidth between 60 and 80uS then read as '1'

    and let me know
    Robotics , aeromodelling r/c , picprogramming , Retro Computer Collector

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Dht11 - 16f877a

    Quote Originally Posted by bitmaniac View Post
    @

    and let me know
    OK an old post I know, but I received a DHT11 today and had a play. This works fine on an 18F2520 running with a 20mhz crystal.

    Code:
    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.5
    
    '*******************************************************************************
    start:
    TRISA.5 = 0 '
    high dht11
    pause 2000 ' wait 2 sec
    low dht11 : pause 18' send 20ms low
    high dht11 : pauseus 30 ' send 40us hi
    TRISA.5 = 0
    PulsIn PORTA.5, 1, haut
    if haut < 15 then goto start
    for x = 31 to 0 step-1
    PulsIn PORTA.5, 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
    I've used Port A, pin 5 as the data line as I used an EasyPIC5 development board, and has the readings displayed on an 4 x 20 LCD rather than serial out.

Similar Threads

  1. DHT11? Code/Schematics?
    By wdmagic in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2013, 09:35
  2. DHT11 Temperature/Humidity sensor
    By mircogomiero in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th January 2013, 12:37
  3. 16F877a - Please Help
    By tarexpanda in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd April 2007, 08:28
  4. 16f877a
    By alaaodeh in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th February 2007, 23:38
  5. I need help with 16F877A
    By valerij in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th December 2006, 17:05

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts