Autor Tema: Se solicita ayuda Interconexion sensor DHT11 al PIC16F877  (Leído 908 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado GAMCH333

  • PIC10
  • *
  • Mensajes: 8
Se solicita ayuda Interconexion sensor DHT11 al PIC16F877
« en: 08 de Diciembre de 2021, 12:42:50 »
Buenos dias!!

Deseandoles el mejor de los exitos en sus actividades diarias!!
La razon del presente mensaje es el de solictar su asesoria en el sentido que tengo la necesidad de conectar el sensor de Temperatura y Humedad DHT11 al micontrolador PIC16F877A, de diverso codigo libre que se puede encontrar en la Internet se intergro el presen te condigo que se muestra a continuacion:

Al momento de compilarlo en el program ccs compiler ver.3.8 se presenta un error identificador indefinido  (Undefined indentifier) en la  presente instruccion:

setup_oscillator(OSC_10MHZ);                // Set internal oscillator to 8MHz

Por lo anterior me permito solicitar su ayuda  para poder conectar dicho sensor DHT11 con el siguiente  programa.



// Interfacing PIC16F877 with DHT11 sensor

#include <16f877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 10000000)

                                    //LCD module connections
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_ENABLE_PIN PIN_D2
#define LCD_DATA4 PIN_D3
#define LCD_DATA5 PIN_D4
#define LCD_DATA6 PIN_D5
#define LCD_DATA7 PIN_D6
                                    //End LCD module connections
#include <lcd.c>

#use fast_io(B)

// Connection pin between PIC16F877 and DHT11(RHT01) sensor
#BIT Data_Pin = 0xF81.0                       // Pin mapped to PORTB.0
#BIT Data_Pin_Direction = 0xF93.0             // Pin direction mapped to TRISB.0

char message1[] = "Temp = 00.0 C";
char message2[] = "RH   = 00.0 %";
short Time_out;
unsigned int8 T_byte1, T_byte2, RH_byte1, RH_byte2, CheckSum ;
void start_signal(){
  Data_Pin_Direction = 0;              // Configure connection pin as output
  Data_Pin = 0;                        // Connection pin output low
  delay_ms(25);
  Data_Pin = 1;                        // Connection pin output high
  delay_us(30);
  Data_Pin_Direction = 1;              // Configure connection pin as input
}
short check_response(){
  delay_us(40);
  if(!Data_Pin){                     // Read and test if connection pin is low
    delay_us(80);
    if(Data_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(!Data_Pin){                          // Wait until pin goes high
      k++;
      if (k > 100) {Time_out = 1; break;}
      delay_us(1);}
    delay_us(30);
    if(!Data_Pin)
      bit_clear(_data, (7 - i));               // Clear bit (7 - i)
    else{
      bit_set(_data, (7 - i));                 // Set bit (7 - i)
      while(Data_Pin){                         // Wait until pin goes low
      k++;
      if (k > 100) {Time_out = 1; break;}
      delay_us(1);}
    }
  }
  return _data;
}
void main(){
 setup_oscillator(OSC_10MHZ);                // Set internal oscillator to 8MHz
  setup_adc_ports(NO_ANALOGS);                // Configure AN pins as digital
  lcd_init();                                 // Initialize LCD module
  lcd_putc('f');                             // LCD clear
  while(TRUE){
    delay_ms(1000);
    Time_out = 0;
    Start_signal();
    if(check_response()){                    // If there is response from sensor
      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_putc('f');                       // LCD clear
        lcd_gotoxy(5, 1);                     // Go to column 5 row 1
        lcd_putc("Time out!");
      }
      else{
       if(CheckSum == ((RH_Byte1 + RH_Byte2 + T_Byte1 + T_Byte2) & 0xFF)){
        message1[7]  = T_Byte1/10  + 48;
        message1[8]  = T_Byte1%10  + 48;
        message1[10] = T_Byte2/10  + 48;
        message2[7]  = RH_Byte1/10 + 48;
        message2[8]  = RH_Byte1%10 + 48;
        message2[10] = RH_Byte2/10 + 48;
        message1[11] = 223;                   // Degree symbol
        lcd_putc('f');                       // LCD clear
        lcd_gotoxy(1, 1);                     // Go to column 1 row 1
        printf(lcd_putc, message1);           // Display message1
        lcd_gotoxy(1, 2);                     // Go to column 1 row 2
        printf(lcd_putc, message2);           // Display message2
       }
        else {
          lcd_putc('f');                     // LCD clear
          lcd_gotoxy(1, 1);                   // Go to column 1 row 1
          lcd_putc("Checksum Error!");
        }
      }
    }
    else {
      lcd_putc('f');             // LCD clear
      lcd_gotoxy(3, 1);           // Go to column 3 row 1
      lcd_putc("No response");
      lcd_gotoxy(1, 2);           // Go to column 1 row 2
      lcd_putc("from the sensor");
    }
  }
}


por su atencion muchas gracias.

Gustavo  A  Martinez.

gamartinezch@yahoo.com



Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
Re:Se solicita ayuda Interconexion sensor DHT11 al PIC16F877
« Respuesta #1 en: 08 de Diciembre de 2021, 12:56:11 »
No te funciona porque ese PIC no tiene oscilador interno.
Puedes verlo en la datasheet:

https://ww1.microchip.com/downloads/en/DeviceDoc/30292c.pdf

Desconectado GAMCH333

  • PIC10
  • *
  • Mensajes: 8
Re:Se solicita ayuda Interconexion sensor DHT11 al PIC16F877
« Respuesta #2 en: 10 de Diciembre de 2021, 15:23:43 »
Reciban ustedes un saludo agradezco mucho su ayuda.

En ese sentido agradeceria si existiera un apoyo para modificar dicho programa o existe alguna modificacion al presente codigo  que haga posible la intercomunicaion del sensor dht11 al microntrolador pic16f877.

Sin mas por el momento reciban ustedes un saludo, agradeciendo  de antemano su apoyo para cumplir con esta tarea.

Un saludo desde mexico. :-/

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
Re:Se solicita ayuda Interconexion sensor DHT11 al PIC16F877
« Respuesta #3 en: 11 de Diciembre de 2021, 03:50:39 »
Prueba quitándole esa línea y, si compila bien, poniéndole un cristal de 10MHz.
No he revisado el programa entero, pero ¿lo has sacado de algún sitio donde funciona?


 

anything