DHT11 simulator in Proteus

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
Bonca
Posts: 319
Joined: 18 Mar 2009 07:55

DHT11 simulator in Proteus

#1 Post by Bonca » 17 Mar 2014 08:57

Hi,

many of us need an emulation opportunity in Proteus. This is done by a 12F683 with two analog input, that represents the humidity and temperature.

Code: Select all

/*******************************************************************************

 DHT11
 ____             ____      ____                                       ___
     |___________|    |____|    |.....................................|
     |   18ms    |    |80us|80us|               5x8 bit               |
     |    PIC    |    |                  DHT11 response               |   end
     |  request  |    |  2x80us, intRH, decRH, intT, decT, checksum   | of frame

 ____          ________
     |________|        |...                        0 bit
      <-50us-> <-27us->

 ____          _________________________
     |________|                         |...       1 bit
      <-50us-> <---------70us---------->


*******************************************************************************/

unsigned short int Packet[5];
char BitCounter, ByteCounter, Request;

void SendByte(unsigned short int DataByte) {
    for(BitCounter=0; BitCounter<8; BitCounter++) {
        if((DataByte & 0b00000001)==0) {                                        // if bit is 0...
            GPIO.F2 = 0;
            delay_us(50);
            GPIO.F2 = 1;
            delay_us(27);
        }
        else {                                                                  // if bit is 1...
            GPIO.F2 = 0;
            delay_us(50);
            GPIO.F2 = 1;
            delay_us(70);
        }
        DataByte = DataByte >> 1;
    }
}

void main() {
    OSCCON = 0b01110001;                                                        // pdf 22.
    ANSEL  = 0b00000011;                                                        // GP0, GP1 analog inputs, pdf 35.
    CMCON0 = 0b00000111;                                                        // comparator disabled
    WPU    = 0b00001100;                                                        // pdf 36.
    TRISIO = 0b00001111;                                                        // GP3 always input
    GPIO   = 0;
    
    ADC_Init();
    delay_ms(100);

    while(1) {

        while(GPIO.F2);
        while(!GPIO.F2) {
            delay_ms(2);
            Request++;
        }

        // This packet compilation takes 600 us at 8 MHz internal clock.
        // A real DHT11 takes only 20...40 us!!!
        Packet[0] = ADC_Read(0) / 10;                                           // humidity  integer
        Packet[1] = 0;                                                          // humidity fraction
        Packet[2] = ADC_Read(1) / 10;                                           // temperature integer
        Packet[3] = 0;                                                          // temperature fraction
        Packet[4] = Packet[0] + Packet[1] + Packet[2] + Packet[3];              // CRC

        if(Request==9) {                                                        // 18ms request
            
            Request = 0;
            TRISIO.F2 = 0;                                                      // switch input to output

            GPIO.F2 = 0;                                                        // 2x80us sensor present signal
            delay_us(80);
            GPIO.F2 = 1;
            delay_us(68);                                                       // additional operations take 12 us

            for(ByteCounter=0; ByteCounter<5; ByteCounter++) {
                SendByte(Packet[ByteCounter]);
            }

            TRISIO.F2 = 1;                                                      // switch output to input
        }
    }
}
dht11_emulator_schematics.jpg
dht11_emulator_schematics.jpg (48.85 KiB) Viewed 36739 times
digital_pattern_generator_properties.jpg
digital_pattern_generator_properties.jpg (64.52 KiB) Viewed 36739 times
scope.jpg
scope.jpg (131.99 KiB) Viewed 36739 times
Bonca
Last edited by Bonca on 17 Mar 2014 16:43, edited 13 times in total.

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

Re: DHT11 simulator in Proteus

#2 Post by p.erasmus » 17 Mar 2014 09:15

@Bonca

Nice work !!! :D
Why dont you post all your Proteus simulation projects which you post in the forum alos in libstock this way it will be available to more people
in the forum this post gets lost over time

Regards
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

tiagohm
Posts: 38
Joined: 09 Aug 2013 22:39
Location: Brasil
Contact:

Re: DHT11 simulator in Proteus

#3 Post by tiagohm » 17 Mar 2014 23:13

Proteus 8 has this component:
Image
Attachments
DHT11.rar
(35.44 KiB) Downloaded 21795 times
Best regards, Tiago

Bonca
Posts: 319
Joined: 18 Mar 2009 07:55

Re: DHT11 simulator in Proteus

#4 Post by Bonca » 18 Mar 2014 07:51

Hello tiagohm,

I spent many ours to find it without success. Thank you, this solution is much comfortable, than mine :)

Bonca

Maheswari V
Posts: 2
Joined: 12 Nov 2014 11:40

Re: DHT11 simulator in Proteus

#5 Post by Maheswari V » 14 Nov 2014 08:18

Hi ,

I have used DHTxx library and model dll files in proteus 7. But while simulating am getting error DHTXX.MDF file is not found

Bonca
Posts: 319
Joined: 18 Mar 2009 07:55

Re: DHT11 simulator in Proteus

#6 Post by Bonca » 14 Nov 2014 14:05

As far as I know, Proteus 7 doesn't support this DHT11 model. Proteus 8 is supporting it.

Bonca

Maheswari V
Posts: 2
Joined: 12 Nov 2014 11:40

Re: DHT11 simulator in Proteus

#7 Post by Maheswari V » 14 Nov 2014 14:50

[quote="Bonca"]

Thank you

helmi
Posts: 1
Joined: 08 Feb 2015 11:09

Re: DHT11 simulator in Proteus

#8 Post by helmi » 08 Feb 2015 11:17

hello everybody
i was using dht11 on proteus 8 but i still have a trouble wiht that

ruba777
Posts: 3
Joined: 19 Feb 2012 11:08

Re: DHT11 simulator in Proteus

#9 Post by ruba777 » 22 Dec 2015 17:05

Attachments
c_dht11.zip
(197.93 KiB) Downloaded 10028 times

Post Reply

Return to “mikroC PRO for PIC General”