Haberler:

Eposta uyarılarını yanıtlamayınız ( ! ) https://bit.ly/2J7yi0d

Ana Menü

PIC18F452 ILE DS18B20

Başlatan tyfrydn, 28 Nisan 2020, 21:05:43

tyfrydn

Merhaba Arkadaşlar.

PIC16F877A ile yaptığım projeyi PIC18F452 ile değiştirdim. Herseyi uyarladım fakat sıcaklık bilgisi düzeltemedim.  0 olarak geliyor.

Kodu aşağıda paylaşıyorum.

Kıymetli Yorumlarınızı bekliyorum.

Main.h
#include <18f452.h>
#include <18f452.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4000000)
#include <flex_lcd.c>
#include <ds18b20.c> 
float sicaklik;
void main() 
{
   lcd_init();
   while(1)
   {
     sicaklik=ds1820_read();
     lcd_gotoxy(1,1);printf(lcd_putc,"Sicaklik:%5.1f",sicaklik);      
   }
}

ds18b20.c
#define ONE_WIRE_PIN PIN_D0

void onewire_reset() 
{
   output_low(ONE_WIRE_PIN);
   delay_us(500);
   output_float(ONE_WIRE_PIN);
   delay_us(500); 
   output_float(ONE_WIRE_PIN);
} 

void onewire_write(int data)
{
   int count;
   for (count=0; count<8; ++count)
   {
      output_low(ONE_WIRE_PIN);
      delay_us(2);
      output_bit(ONE_WIRE_PIN, shift_right(&data,1,0)); 
      delay_us(60);
      output_float(ONE_WIRE_PIN); 
      delay_us(2); 
   }
} 

int onewire_read()
{
   int count, data;
   for (count=0; count<8; ++count)
   {
      output_low(ONE_WIRE_PIN);
      delay_us(2);
      output_float(ONE_WIRE_PIN);
      delay_us(8);
      shift_right(&data,1,input(ONE_WIRE_PIN)); 
      delay_us(120);
   }
   return(data);
} 

float ds1820_read()
{
   static int1 ds_flag=0;
   int8 busy=0, temp1, temp2; 
   signed int16 temp3; 
   static float result; 
   
   if(ds_flag==0)
   {
      onewire_reset(); 
      onewire_write(0xCC); 
      onewire_write(0x44); 
      ds_flag=1;
   }
   
   else
   {
      busy = onewire_read(); 
      if(busy==0)return result;
   }
   
   ds_flag=0;
   onewire_reset(); 
   onewire_write(0xCC); 
   onewire_write(0xBE); 
   temp1 = onewire_read(); 
   temp2 = onewire_read(); 
   temp3 = make16(temp2, temp1); 
   
   result = (float) temp3 / 16.0;
   
   return(result); 
}

sifirzero

sifirzero.blogspot.com [email]sifirrzero@gmail.com[/email] iman hem nurdur hem kuvvettir

sadogan


SB7

18f452.h 2 kez tanımlammış. Bundan olabilir mi?
-SB7

RaMu

10 gün öncenin konusu çözmüştür herhalde.
Sorularınıza hızlı cevap alın: http://www.picproje.org/index.php/topic,57135.0.html