I'm trying to interface a PIC with the DHT11 sensor and it's not working. I feel I have tried everything. Below is a stripped down version of my code which should at least make the sensor send a response message.
Basically a LED should turn on as soon as I get a HIGH value from the sensor. But I'm not getting anything..
If someone could help to solve this it would be really great. I'm also attaching a picture of my set-up.
Thanks a lot!
#include <stdio.h>
#include <stdlib.h>
#include <delays.h>
// PIC18F4620 Configuration Bit Settings
#include <p18F4620.h>
#pragma config OSC = HSPLL // Oscillator Selection bits (HS oscillator, PLL enabled (Clock Frequency = 4 x FOSC1))
#pragma config WDT = OFF
#pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bits (Brown-out Reset disabled in #pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#define DHT11_TRIS TRISDbits.RD1
#define DHT11_IO PORTDbits.RD1 //READ USING THIS
#define LED0_TRIS TRISDbits.RD0
#define LED0_IO PORTDbits.RD0
int my_flag = 0,bit_counter=39,t1=0,t2=0;
int response[]={0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0};
void high_isr(void);
void low_isr(void);
#pragma code InterruptVectorHigh = 0x08
void interrupt_at_high_vector(void)
{
_asm GOTO high_isr _endasm
}
#pragma code low_vector=0x18
void interrupt_at_low_vector(void)
{
_asm GOTO low_isr _endasm
}
#pragma code /* return to the default code section */
#pragma interrupt high_isr
void high_isr(void)
{
// return from high priority interrupt
}
#pragma interruptlow low_isr
void low_isr (void)
{
// return from low priority interrupt
}
#define GetSystemClock() (32000000ul)
#define GetInstructionClock() (GetSystemClock()/4)
void Delay10us(int us) {
Delay10TCYx(((GetInstructionClock()/1000000)*(us)));
}
void DelayMs(int ms){
unsigned int _iTemp = (ms);
while(_iTemp--)
Delay1KTCYx((GetInstructionClock()+999999)/1000000);
}
void main(void){
int c=0;
CMCON = 7;
DHT11_TRIS = 0; //Set DATA OUTPUT
DHT11_IO = 0;
LED0_TRIS = 0; //Set LED as OUTPUT
LED0_IO=0;
DHT11_IO = 1;
DelayMs(1000);
DHT11_IO = 0; //Pull Low
DelayMs(20); //For 20ms
DHT11_IO = 1; //Set HIGH
Delay10us(3);// For 30us
DHT11_IO = 0;
DHT11_TRIS = 1; //Set as input
while (DHT11_IO !=1){}
LED0_IO = 1;
DelayMs(5000);
}
Edit: I would post my set-up but I'm not allowed due to rep points!