DS18B20 acaba bozuk mu ?

Başlatan ido2323, 06 Ekim 2013, 11:14:22

ido2323

sbit LCD_RS at RB7_bit;
sbit LCD_EN at RB6_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D4 at RB2_bit;

sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB2_bit;

const unsigned short ISI_bitleri = 12;

char cnt;
char *text = "000.0000";
unsigned ISI;

void Display_Temperature(unsigned int temp2write) {
   const unsigned short bit_kaydir = ISI_bitleri - 8;
   char ISI_tam_deger;
   unsigned int ISI_kesirli;

  // Sıcaklık sıfırın altında mı?
   if (temp2write & 0x8000) {
      text[0] = '-';
      temp2write = ~temp2write + 1;
      }

  // ISI_tam_deger elde ediliyor
   ISI_tam_deger = temp2write >> bit_kaydir ;

  // ISI_tam_deger karaktere dönüştürülüyor
   if (ISI_tam_deger/100)
      text[0] = ISI_tam_deger/100  + 48;

   text[1] = (ISI_tam_deger/10)%10 + 48;
   text[2] =  ISI_tam_deger%10     + 48;

  // ISI_kesirli değeri elde ediliyor
   ISI_kesirli  = temp2write << (4-bit_kaydir);
   ISI_kesirli &= 0x000F;
   ISI_kesirli *= 625;

  // ISI_kesirli karaktere dönüştürülüyor
   text[4] =  ISI_kesirli/1000    + 48;
   text[5] = (ISI_kesirli/100)%10 + 48;
   text[6] = (ISI_kesirli/10)%10  + 48;
   text[7] =  ISI_kesirli%10      + 48;

  // Isı LCD 'ye yazdırılıyor
   Lcd_Out(2, 5, text);
}


void main() {
ADCON0 = 0;
ADCON1 |= 0x0F;

TRISA = 0xff;
   LATA = 0;
   PORTA = 0;

trisc.rc0 = 1;
trisc.rc1 = 1;
trisc.rc2 = 1;
trisc.rc3 = 1;
trisd.rd0 = 1;
portc = 0;
portd = 0;

Lcd_Init();
   Lcd_Cmd(_LCD_CLEAR);
   Lcd_Cmd(_LCD_CURSOR_OFF);
   Lcd_Out(1, 1, " DS18B20 ISI :   ");
  // Santigrat derece LCD 'ye yazıdırılıyor
   Lcd_Chr(2,13,223);
   Lcd_Chr(2,14,'C');

  do {
    // Isı DS18B20 sensöründen okunuyor
    Ow_Reset(&PORTA, 2);
    Ow_Write(&PORTA, 2, 0xCC);
    Ow_Write(&PORTA, 2, 0x44);
    Delay_us(120);

    Ow_Reset(&PORTA, 2);
    Ow_Write(&PORTA, 2, 0xCC);
    Ow_Write(&PORTA, 2, 0xBE);

    ISI =  Ow_Read(&PORTA, 2);
    ISI = (Ow_Read(&PORTA, 2) << 8) + ISI;

    // LCD 'ye yazdırmak için Isı değeri ayarlanıyor
    Display_Temperature(ISI);

    Delay_ms(500);
  } while (1);
}

18f452 ile çalışıyorum baka baka kör oldum nerde hata var acaba?

ido2323


selimkoc

ADCON1 |= 0x0F;
satırı ile RA2 pinini analog olarak ayarlamışsın.

ADCON1 |= 0x07;

olmalı