Haberler:

Forum kuralları güncellendi LÜTFEN  okuyunuz:  https://bit.ly/2IjR3ME

Ana Menü

dht22

Başlatan Eyt1, 11 Temmuz 2016, 02:04:36

Eyt1

Merhaba arkadaşlar dht22 sensorum 16F84a işlemci ile çalışıyor.Fakat 16F716 ile derlediğimde sensor hatası alıyorum yardımcı olurmusunuz?

#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_ENABLE_PIN PIN_B2
#define LCD_DATA4 PIN_B3
#define LCD_DATA5 PIN_B4
#define LCD_DATA6 PIN_B5
#define LCD_DATA7 PIN_B6
//End LCD module connections

#include <16F716.h>
#FUSES NOWDT                    //No Watch Dog Ti 8 P
#FUSES HS                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
//#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPUT                    //No Power Up Timer
//#FUSES NOCPD                    //No EE protection
//#FUSES STVREN                   //Stack full/underflow will cause reset
//#FUSES NODEBUG                  //No Debug mode for ICD
//#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
//#FUSES NOWRT                    //Program memory not write protected
//#FUSES IESO                     //Internal External Switch Over mode enabled
//#FUSES FCMEN                    //Fail-safe clock monitor enabled
//#FUSES MCLR                     //Master Clear pin enabled

#use delay(CLOCK=8000000)

#include <lcd.c>
#use fast_io(A)
// Connection pin between PIC16F84A and DHT22 sensor
#BIT Data_Pin = 0x05.0                      // Pin mapped to PORTA.0
#BIT Data_Pin_Direction = 0x85.0             // Pin direction mapped to TRISA.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 ;
unsigned int16 Temp, RH;

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(){

  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)){
        RH = RH_byte1;
        RH = (RH << 8) | RH_byte2;
        Temp = T_byte1;
        Temp = (Temp << 8) | T_byte2;
        if (Temp > 0x8000){
         message1[6] = '-';
         Temp = Temp & 0x7FFF; }
        else
         message1[6] = ' ';
        message1[7]  = (Temp / 100) % 10  + 48;
        message1[8]  = (Temp / 10) % 10  + 48;
        message1[10] = Temp % 10  + 48;
        message2[7]  = (RH / 100) % 10 + 48;
        message2[8]  = (RH / 10) % 10 + 48;
        message2[10] = RH % 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");
    }
  }
  
}



sadogan

 #use fast_io(A) bu satırın altına
bunu ilave ederek denermisin
setup_adc_ports(NO_ANALOGS);

Eyt1

Denedim usta fakat olmadı.

sadogan

Yeri yanlış olmuş,
o satır
void main(){
altında olacaktı.

Eyt1

#4
Alıntı yapılan: sadogan - 11 Temmuz 2016, 16:05:38
Yeri yanlış olmuş,
o satır
void main(){
altında olacaktı.


void main(){
altına da ekledim ama olmuyor 16f84a işlemciye göre derlediğimde çalışıyor fakat işlemcide adc var ise çalışmıyor işlemci sensor ile bağlantı kurma hatası alıyorum.

Burada tam olarak nediyor ustam pin girişlerini belirtmiş ama 0x05 0x85 ne anlama geliyor

#BIT Data_Pin =0x05.0                     // Pin mapped to PORTA.0
#BIT Data_Pin_Direction = 0x85.0          // Pin direction mapped to TRISA.0


görkem

pic in register adresleri onlar 0x05 porta nın adresi 0x85 ise trisa nın adresi

0x05.0 demesi  porta nın 0.bitini data_pin  adlı değişkene atıyo


anolog ayarlarında büyük ihtimal sıkıntı var

void main in altına aşağıdaki  satırları ekle düzelmesi lazım
setup_adc(ADC_OFF);
setup_adc_ports(NO_ANALOGS );