Por si las dudas alguien quiere darte una mano.. Aca dejo el codigo identado y para el creador del post, identar hace mas facil la lectura, y tambien no deberias incluir .c en el main.c, para eso estan los archivos .h
dht.c
#define dht22 PIN_A2
#bit dht_io = 0xf92.2
byte dht22_dat[5];
byte leer_datos_dht();
Void dht_init (void)
{
dht_io=0;
delay_ms(1);
output_high(dht22);
}
byte leer_datos_dht()
{
byte i = 0;
byte result=0;
for (i=0; i< 8; i++)
{
//We enter this during the first start bit (low for 50uS) of the byte
//Next: wait until pin goes high
while(input(dht22)==0);
delay_us(30);
if (input(dht22)==1)
{
result |=(1<<(7-i));
}
while (input(dht22)==1);
}//end of "for.."
return result;
}
Void leer_dht22 (float &dhthum,float &dthtemp)
{
byte dht22_in, i, dht22_checksum;
int16 temperatura, humedad;
float temp,hum;
dht_io=0; // configurar el pin como salida
output_high(dht22);
delay_us(20);
output_low(dht22);
delay_ms(18);
output_high(dht22);
delay_us(22);
dht_io=1;// configurar el pin como entrada
delay_us(5);
dht22_in=input(dht22);
if(dht22_in)
{
printf("\r\ndht condicion 1 de inicio no encontrada"); return;
}
delay_us(80);
dht22_in=input(dht22);
if(!dht22_in)
{
printf("\r\ndht condicion 2 de inicio no encontrada"); return;
}
delay_us(80);
for (i=0; i<5; i++)
{
dht22_dat[ i ] = leer_datos_dht(); // capturando datos
}
dht_io=0;
delay_us(10);
output_high(dht22);
dht22_checksum = dht22_dat[0]+dht22_dat[1]+dht22_dat[2]+dht22_dat[3];
if(dht22_dat[4]!=dht22_checksum)
{
printf("\r\nDHT checksum error"); }
humedad = make16(dht22_dat[0],dht22_dat[1]);
temperatura = make16(dht22_dat[2],dht22_dat[3]);
hum = humedad;
temp = temperatura;
dhthum = (hum)/10;
dthtemp = (temp)/10;
}//Fin Driver
main.c
#include <18f4550.h>
#device adc=10 //Usa resolución de 10 bits
#fuses HS,NOWDT,NOPUT,NOLVP,NOBROWNOUT,NOWRT,NOPROTECT
#use delay(clock=8000000)
#include "lcd420.C" // cambiar comillas
#include "dht.C" // cambiar comillas
void main()
{
float dhthum, dthtemp;
delay_ms(300);
while(true)
{
leer_dht22(dhthum, dthtemp);
delay_ms(10);
printf(lcd_putc
,"\fHum= %f %%",dhthum
); printf(lcd_putc
,"\nTemp= %f %cC", dthtemp
,223); delay_ms(2000);
}
}
Una cosa mas,, probaste ponelo en FAST_IO(A) ?, los pines estan en digital?, por que le puertoA viene analogico en el reset.
Si no sabes como pasarlo a analogico podrias usar un pin del puerto B que no posee la opcion de analogico.
Le pusiste la resistencia del Pull-up en el pin ?, asi mirando rapido el codigo solo veo un error de concepto que es esto:
dht_io=0;
delay_us(10);
output_high(dht22);
Y que se deberia quitar. Pero no creo que te afecte tanto.