Elektronik ve Teknoloji Merkezi Elektrotekno.com
Elektronik ve Teknoloji Merkezi




Click here to go to the original topic

Elektrotekno.com Ana Sayfa Devre ve proje istekleriniz
Yazar Mesaj
sdonart
Tarih: 11.04.2007, 11:59 Mesaj konusu: ds18b20 icin yardım

Arkadaşlar merhaba
Ben ds18b20 kullanark sıcaklık olçümü yapmak istiyorum.1-wire icin gerekli programı yazdım ama duzgun calısmıyor.Oradaki mikro saniyelik gecikmelerin pic-c ile yazıldıgı taktirde duzgun olmayacagını dusunmye basladım. Cunki pıc de bir instruction 1 mikro saniye suruyor ama biz pic-c de bir if yazdıgımıza mesela o komutun kac instructiona tekabul edecegini asm kodunu kurcalamaz isek bulmamiz biraaz zor gibi.Acaba ben mi yanlış dusunuyorum?Bu konuda yapılmıs bir suru proje olduguna gore tecrubeli arkadaslardan yardımlarını bekliyorum
Bir ricam da proteus da simule edebilmem icin ds18b20 nin gerekli dosyalarını gonderebilecek bir hayırsever olursa cok sevinirim bendeki versiyonu 6.2 kırek edilmis oldugu icin yeni versiyon indirmek istemiyorum.zaten yeni versiyonunda da 18b20 yok sanırım
tesekkurler
yakup1890
Tarih: 11.04.2007, 16:21 Mesaj konusu: ds18b20 yardımı

merhaba arkadasım bıldıgım kadarıyla komutların calısma hızı 2mıcro sanıye yalnızca kesmeler 1 mıcro sanıye (4mhz ıcın)
bence bırde buna gore duzenle programını bırde 6.9 sp3 versıyonunu alttakı lıunten ındırebılırsın sana kolay gelsın.

bende bu programı kullanıyorum ıcınde ds18b20 entegresı mevcut.

dowland:
http://rapidshare.com/files/25433664/Pr..._.9.03.rar
xenitis
Tarih: 10.05.2007, 00:50 Mesaj konusu:

selamlar
buyrun benim de kullandığım c kodları
okumanın yapılması için biraz düzeltme yapmanız gerekecek ancak fonksiyonlar çalışıyor onları değiştirmeyin
bir de aklınızda olsun bu zamanlamalar 4MHz çalışma frekansı için başka bir frekans için zamanlamaları tekrar ayarlamanız gerekir umarım işinize yarar kolay gelsin
Kod:
/************************************************************************/
// Routines for one-wire protocol (DS18B20)
// Rel. 1.0 Nov 2006
// Eduardo Barajas P.
// TRIS_DQ --> DDRCbits.RC2   // TRIS for DQ
// DQ  --> PORTCbits.RC2   // DATA pin for DQ
#define TRIS_DQ  DDRCbits.RC2   // TRIS for DQ of DS18B20
#define DQ  PORTCbits.RC2  // DATA pin for DQ of DS18B20
// #define TRIS_DQ DDRCbits.RC1   // TRIS for DQ of DS18B20
// #define DQ  PORTCbits.RC1  // DATA pin for DQ of DS18B20

unsigned char reset_ow(void)  //Reset and detect DS8B20
{
 unsigned char presence;
 TRIS_DQ = 1;  // Start with line high
 DQ = 0;   
 TRIS_DQ = 0; // Make DQ low
 Delay100TCYx(5); // Drive low for 500us
 TRIS_DQ = 1; 
 Delay10TCYx(7); // Release line and wait 70us
 presence = DQ;
 Delay10TCYx(43); // wait 430us after presence pulse
 return presence;  // 0=presence; 1=No Part connected
  }
unsigned char read_bit_ow(void)  // Read single bit of DS18B20
{
 DQ = 0;   
 TRIS_DQ = 0; // Make DQ low
 _asm NOP _endasm  // Wait 1 uS
 TRIS_DQ = 1; // Make DQ high
 Delay10TCYx(1); // Delay 10 uS from start of timeslot
 _asm NOP _endasm  // Wait 1 uS
 _asm NOP _endasm  // Wait 1 uS
 _asm NOP _endasm  // Wait 1 uS
 _asm NOP _endasm  // Wait 1 uS
 return DQ; //Return value of DQ line
}
unsigned char read_byte_ow(void)  //Read one byte from the one-wire bus (18B20)
{
 unsigned char i;
 unsigned char value = 0;
 for( i=0; i<8; i++)
  {
   if(read_bit_ow()) value |= (0x01<<i);  // Reads byte in, one bit at time and then shifts it left
   Delay10TCYx(12); // Delay 120uS for rest of timeslot 
  }
 return value;
}   
void write_bit_ow(char bitval)  // Writes a bit to the one-wire bus (18B20) passed in bitval.
{
 DQ = 0;   
 TRIS_DQ = 0; // Make DQ low to start timeslot
 _asm NOP _endasm  // Wait 1 uS
 if(bitval == 1) TRIS_DQ = 1; // return DQ high if write 1
 Delay10TCYx(10); // Delay 100uS for rest of timeslot 
  TRIS_DQ = 1; // return DQ high
}
void write_byte_ow(char val)  // Writes a byte to the one-wire bus
{
 unsigned char i;
 unsigned char temp;
 for( i=0; i<8; i++)  // Writes byte, one bit at a time
  {
   temp = val>>i;  // Shifts val right 'i' spaces
   temp &= 0x01;  // Copy that bit to temp
   write_bit_ow(temp);  //Write bit in temp into one-wire bus
  }
 Delay10TCYx(10); // Delay 100uS for rest of timeslot 
}
/************************************************************************/
/************************************************************************/
// Read SCRATCHPAD and return temperature for DS18B20 ONLY!!!
unsigned int read_temperature_ow_18B20(char *ID)
{
 unsigned int temperature;
 unsigned char dat[9], i;
    reset_ow();
 write_byte_ow(0x55); //Match Rom
 for(i=0; i<8; i++) write_byte_ow(ID);
 write_byte_ow(0x44);  // Start conversion
 while(read_bit_ow()==0); // Wait for end of conversion
    reset_ow();
 write_byte_ow(0x55); //Match Rom
 for(i=0; i<8; i++) write_byte_ow(ID);
 write_byte_ow(0xBE); //Read Scratch
 for(i=0; i<9; i++) dat=read_byte_ow();
 temperature = dat[0] + dat[1] * 256;
 return temperature;
}
/************************************************************************/



Just create a new header file named one_wire.h and copy all them to the file and include your header your program as follow:

#include <one_wire.h>

And you can use them in this way:

unsigned char DS18B20_A[]={0x28, 0x1D, 0xC6, 0x30, 0x00, 0x00, 0x00, 0xF9, NULL}; // 
unsigned char DS18B20_B[]={0x28, 0xD0, 0x22, 0x31, 0x00, 0x00, 0x00, 0x66, NULL};  // With the routines you need to get the ID of your 18B20
// These two ID's are for my 18B20's.

unsigned char tmp;
int conv;

   tmp = reset_ow();
if( tmp ==1){ LCD_ROM(" DS18B20 NOT detected !!!!", 0, 0); Delay10KTCYx(200);}
 if( tmp ==0) {
  LCD_ROM(" DS18B20 detected 24 !!!!", 0, 0);
     XLCDClear();
  LCD_ROM("T: ", 0, 0);
  i=0;
  while(1){ 
    conv = read_temperature_ow_18B20(DS18B20_A);
    watts = conv * 0.0625;
    ftoa (watts, buf, 1, 'f');
    LCD_ROM("     ", 10, 0);
    LCD_RAM(buf, 10, 0);
    conv = read_temperature_ow_18B20(DS18B20_B);
    watts = conv * 0.0625;
    ftoa (watts, buf, 1, 'f');
    LCD_ROM("     ", 10, 1);
 LCD_RAM(buf, 10, 1);

bayfly
Tarih: 28.04.2008, 00:02 Mesaj konusu:

arkadaşım bende bu entegreyle uğraşıyorum proteus 7.0 ve üzeri versiyonlarda ds18b20 var şu anlda zaten 7.2 piyasada geziyo c dilinde çok acemiyim arkadaş biraz yardımcı olmaya çalışmış ama hiç birşey anlamadım entegre hakkında biraz bilgisi olan açıklama yapıp ısının nsıl okunacağına dair basir bir program verirse çok sevinirim ingilizcem olmsına rağmen pdf sinden hiçbirşey anlamadım herkeze kolay gelsin
cagdas35
Tarih: 03.05.2008, 23:41 Mesaj konusu:

ds18b20ye sıcaklık okuta bilmen için 2 komut göndermen gerekiyor 1. komut sıcaklığı algılayıp rama yazar 2. komut ram daki 16 bitlik sıcaklık değerini seri olarak göndermesini sağlar. bağlantısını düzgün yapman gerekiyor.ekte şemanın bir bölümü var özellikle direnç çok önemli.
bayfly
Tarih: 04.05.2008, 03:23 Mesaj konusu:

cağdaş35 arkadaşım ek nerde ben bulamadım bide ds18b20 entegresiyle 3haftadır uğraşıyorum c dilinde acemiyim bi ilerleme kaydedemedim forumuda araştırdım vaktin varsa msnden yardımda bulunabilirmisin bana
Elektrotekno.com Ana Sayfa Devre ve proje istekleriniz
1. sayfa (Toplam 1 sayfa)

ds18b20 icin yardım

Gizlilik Politikası

PLC programming