TODOPIC
Microcontroladores PIC => * PROYECTOS * => Mensaje iniciado por: Cesareus01 en 13 de Diciembre de 2020, 20:17:01
-
Colegas, tengo armado un termostato con un 16f886 con grabado en eeprom de config y demás en el que tenía un sensor de temperatura 18b20 y le quise adaptar un dht22 porque necesitaba sensar humedad, me tope con varias librerías, una me funcionaba bien en proteus pero no en la protoboard, pensando que se trataba de una tema de manejo de memoria, direcciones de puertos y demás tema que no manejo muy bien, y que creo que no es necesario porque PIC-C IDE el compilador que utilizo ya trae todo definido me puse a hacer mi propia librería en base a la librería que funcionaba y a un proyecto que trae todo incluido en el main, la probe en proteus y funciona bárbaro, en la protoboard nada, probé en ponerle use_fast_io, sin el set_tris_a y directamente el micro no arranco, le puse use_standard,io, con el set_tris_a y sin el set_tris_a y arranca pero me marca T=0.0 y humedad=0.0. Se me quemaron los papeles :?. Paso la librería y si hace falta despues el main.c y main.h. Alguien me puede dar una mano por favor?.
#define DHT22_PIN PIN_A0
short Time_out;
unsigned int8 T_byte1, T_byte2, RH_byte1, RH_byte2, CheckSum;
unsigned int16 Tempo, RH;
void start_signal(){
output_drive(DHT22_PIN); // Configure connection pin as output
output_low(DHT22_PIN); // Connection pin output low
delay_ms(25);
output_high(DHT22_PIN); // Connection pin output high
delay_us(30);
output_float(DHT22_PIN); // Configure connection pin as input
}
short check_response(){
delay_us(40);
if(!input(DHT22_PIN)){ // Read and test if connection pin is low
delay_us(80);
if(input(DHT22_PIN)){ // Read and test if connection pin is high
delay_us(50);
return 1;
}
}
}
unsigned int8 Read_Data(){
unsigned int8 i, k, _data = 0; // k is used to count 1 bit reading duration
if(Time_out)
break;
for(i = 0; i < 8; i++){
k = 0;
while(!input(DHT22_PIN)){ // Wait until DHT22 pin get raised
k++;
if(k > 100){
Time_out = 1;
break;
}
delay_us(1);
}
delay_us(30);
if(!input(DHT22_PIN))
bit_clear(_data, (7 - i)); // Clear bit (7 - i)
else{
bit_set(_data, (7 - i)); // Set bit (7 - i)
while(input(DHT22_PIN)){ // Wait until DHT22 pin goes low
k++;
if(k > 100){
Time_out = 1;
break;
}
delay_us(1);}
}
}
return _data;
}
void get_data(float &dhthum,float &dthtemp){
int16 temperatura, humedad;
float temp,hum;
if(check_response()){
RH_byte1 = Read_Data(); // read RH byte1
RH_byte2 = Read_Data(); // read RH byte2
T_byte1 = Read_Data(); // read T byte1
T_byte2 = Read_Data(); // read T byte2
Checksum = Read_Data(); // read checksum
if(Time_out){ // If reading takes long time
lcd_gotoxy(1, 1); // Go to column 1 row 1
printf(lcd_putc," Time out! ");
lcd_gotoxy(1, 2); // Go to column 1 row 2
printf(lcd_putc," "); // Clear 2nd row
}
else{
if(CheckSum == ((RH_Byte1 + RH_Byte2 + T_Byte1 + T_Byte2) & 0xFF)){
RH = RH_byte1;
RH = (RH << 8) | RH_byte2;
Tempo = T_byte1;
Tempo = (Tempo << 8) | T_byte2;
if (Tempo > 0X8000){
Tempo = Tempo & 0X7FFf; }
else
humedad = make16(RH_Byte1,RH_Byte2);
temperatura = make16(T_Byte1,T_Byte2);
hum = humedad;
temp = temperatura;
dhthum = (hum)/10;
dthtemp = (temp)/10;
}
else {
lcd_gotoxy(1, 1); // Go to column 1 row 1
printf(lcd_putc,"Checksum Error! ");
lcd_gotoxy(1, 2); // Go to column 1 row 2
printf(lcd_putc," "); // Clear 2nd row
}
}
}
else {
lcd_gotoxy(1, 1); // Go to column 1 row 1
printf(lcd_putc," No response ");
lcd_gotoxy(1, 2); // Go to column 1 row 2
printf(lcd_putc,"from the sensor ");
}
return;
}