1-wire

Başlatan mcan, 18 Haziran 2005, 00:59:16

mcan

ccs de 1-wire ile ilgili bir driver varmı,mesela ds18b20 ile nasıl iletişim kurarız appnotlarında yazmış ama assembly olarak acaba bunları c ye bir driver olarak çevirmek mümkün mü?

ahmetu

CCS forumu search'den arat 2-3 örnek kod geliyor.

mcan

bastırdım datasheet i yazıcımdan, bir kaç örneğede baktım ama hepsi picbasic ile alakalıydı,akış şemasına göre bişiler yazmaya başladım C (ccs) için tabi, yardımınız da gerekiyor, şimdilik şu kadar yazdım
oku(){
int1 a=0;
int i=0;
byte data[2];
reset:{output_low(dq);delay_us(500);output_high(dq);goto presence;}
presence:{IF(input(dq)==1)goto presence;else goto skip;}
skip:{for(i=0;i<8;++i){output_bit(DQ,shift_right(0xcc,1,0));delay_us(65);}i=0;goto if(a)goto read;else goto convert;} //rom_command
convert:{for(i=0;i<8;++i){output_bit(DQ,shift_right(0x44,1,0));delay_us(65);}i=0;bekle:{delay_u(65);if( input(dq) ){a=1;goto reset;}else goto bekle;}}
read:{for(i=0;i<8;++i){output_bit(DQ,shift_right(0xbe,1,0));delay_us(65);}for(i=0; i<=72; ++i){shift_left(data,2,input(dq));delay_us(60);}}
}
bu işe yararmı ?şu hatayı aldım shift_xx komutu ile ilgili illa pointermi kullanacaz halbuki benim gönderdiklerim sabit şeyler boşa neden ram yesinlerki ,

mcan

yazdığım sıcaklık okuma programıyla ds1820 den sıcaklığı okudum,fakat doğru ölçüyormu diye normal alkollü termometreyle kıyasladım 4-5 derece daha sıcak ölçüyor ,buzlu suya daldırdığımda alkollü derece -4,-5 derece göterirken bu ise +3 ,+4 derece gösteriyor buzlu suyun içindeki buzun içine sokunca ozaman 0 derece gösteriyor,doğru ölçüp ölçmediğini nasıl öğrenirim,elinin altında hazır düzeneği olan varsa 1820 yi buzlu suya batırın bakalım kaç derece ölçüyor,acaba buzlu suyun +4 derece olması imkanı varmı ankarada?

şunuda ekleyeyim isisde tam doğru ölçüyor program hiç hata yok isisdeyken

mhk

Kaynar suda ölçmeyi dene  ;)
"Ya olduğun gibi görün, Ya da göründüğün gibi ol..." Mevlana

mcan

Alıntı yapılan: "mhk"Kaynar suda ölçmeyi dene  ;)
kaynar suda ölçmek zor olur ,hem suyun kaynamasında yüksekliğin büyük önemi olduğu için ankarada 100 derecede kaynar diyemem,

bu arada multimetremdeki ısı ölçen kısımla kıyasladım,iki birbirine çok yakın hatta aynı,hala şüpeliyim acaba buzlu u karışımım gerçekden +3/+4 derecemi? termo elektrik çift çok hızlı ölçüyor 1820 ise biraz ağır ağır ölçüyor acaba kılıfının ısı sığası biraz fazlamı kalmış acaba buna metal bi oğutucu gibi bişeymi bağlamalıyım

eproje

// onewire library, for dallas onewire devices
// currently includes:
//   - generic onewire functions (init, readbyte, sendbyte, crc, etc.)
//   - ds1822 dallas-semi econo-thermometer

// (C) copyright 2003 j.d.sandoz / jds-pic !at! losdos.dyndns.org

// released under the GNU GENERAL PUBLIC LICENSE (GPL)
// refer to http://www.gnu.org/licenses/gpl.txt

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

//#define ONE_WIRE_PIN PIN_A1
// ds1822 scratchpad registers
#define DS1822_SP_TLSB  0
#define DS1822_SP_TMSB  1
#define DS1822_SP_HLIM  2
#define DS1822_SP_LLIM  3
#define DS1822_SP_CFG   4
#define DS1822_SP_RES0  5
#define DS1822_SP_RES1  6
#define DS1822_SP_RES2  7
#define DS1822_SP_CRC   8

// ds1822 rom registers
#define DS1822_ROM_DEVTYPE  0
#define DS1822_ROM_SERIAL1  1
#define DS1822_ROM_SERIAL2  2
#define DS1822_ROM_SERIAL3  3
#define DS1822_ROM_SERIAL4  4
#define DS1822_ROM_SERIAL5  5
#define DS1822_ROM_SERIAL6  6
#define DS1822_ROM_CRC      7

// ds1822 command set
#define DS1822_CMD_READROM           0x33
#define DS1822_CMD_SKIPROM           0xCC
#define DS1822_CMD_CONVERTTEMP       0x44
#define DS1822_CMD_WRITESCRATCHPAD   0x4E
#define DS1822_CMD_READSCRATCHPAD    0xBE
#define DS1822_CMD_COPYSCRATCHPAD    0x48


// note that not all applications need to disable interrupts when
// performing onewire transactions.  but, if unmasked interrupts
// cause onewire timing violations, returned data will be suspect
// or there may be other, hard-to-reproduce problems.

void onewire_disable_interrupts(int disable) {
   if (disable)
     disable_interrupts(GLOBAL);
   else
     enable_interrupts(GLOBAL);
}


short int onewire_init_with_error_check() {
   onewire_disable_interrupts(TRUE);
   output_low(ONE_WIRE_PIN);
   delay_us( 500 ); // pull 1-wire low for reset pulse
   output_float(ONE_WIRE_PIN); // float 1-wire high
   delay_us( 5 );   // allow pin to stabilize
   if (!input(ONE_WIRE_PIN)) {
      onewire_disable_interrupts(FALSE);
      return ( FALSE ); // error (1-wire leads shorted)
      }
   delay_us( 80 ); // wait for presence pulse, allowing for device variation
   if (input(ONE_WIRE_PIN)) {
      onewire_disable_interrupts(FALSE);
      return ( FALSE ); // error (no 1-wire devices present)
      }
   delay_us( 420 ); // wait-out remaining initialisation window.
   output_float(ONE_WIRE_PIN);
   //printf(debug_putc,"<>ok >onewire_init\n\r");
   onewire_disable_interrupts(FALSE);
   return ( TRUE ); // device(s) present and initialised.
}


void onewire_init() { // OK if just using a single permanently connected device
   onewire_disable_interrupts(TRUE);
   output_low(ONE_WIRE_PIN);
   delay_us( 500 ); // pull 1-wire low for reset pulse
   output_float(ONE_WIRE_PIN); // float 1-wire high
   delay_us( 80 ); // wait for presence pulse, allowing for device variation
   delay_us( 420 ); // wait-out remaining initialisation window.
   output_float(ONE_WIRE_PIN);
   onewire_disable_interrupts(FALSE);
}


void onewire_sendbyte(int data) {
   int count;
   //static int debugS;
   //printf(debug_putc,"0x%x >onewire_sendbyte(%u)\n\r",data,debugS++);
   onewire_disable_interrupts(TRUE);
   for (count=0; count<8; ++count) {
      output_low(ONE_WIRE_PIN);
      delay_us( 2 ); // pull 1-wire low to initiate write time-slot.
      output_bit(ONE_WIRE_PIN, shift_right(&data,1,0)); // set output bit on 1-wire
      delay_us( 60 ); // wait until end of write slot.
      output_float(ONE_WIRE_PIN); // set 1-wire high again,
      delay_us( 2 ); // for more than 1us minimum.
      }
   onewire_disable_interrupts(FALSE);
}


int onewire_readbyte() {
   int count, data;
   //static int debugR;
   onewire_disable_interrupts(TRUE);
   for (count=0; count<8; ++count) {
      output_low(ONE_WIRE_PIN);
      delay_us( 2 ); // pull 1-wire low to initiate read time-slot.
      output_float(ONE_WIRE_PIN); // now let 1-wire float high,
      delay_us( 8 ); // let device state stabilise,
      shift_right(&data,1,input(ONE_WIRE_PIN)); // and load result.
      delay_us( 120 ); //44 olabiliyormus// wait until end of read slot.
      }
   //printf(debug_putc,"0x%x >onewire_readbyte(%u)\n\r",data,debugR++);
   onewire_disable_interrupts(FALSE);
   return( data );
}


int onewire_ds1822_read_scratchpad(int field) { /* returns config bitfield */
   int data[9];

   onewire_init();
   onewire_sendbyte(DS1822_CMD_SKIPROM);
   onewire_sendbyte(DS1822_CMD_READSCRATCHPAD);

   data[DS1822_SP_TLSB]=onewire_readbyte();    // 0 Tlsb
   data[DS1822_SP_TMSB]=onewire_readbyte();    // 1 Tmsb
   data[DS1822_SP_HLIM]=onewire_readbyte();    // 2 Thlim
   data[DS1822_SP_LLIM]=onewire_readbyte();    // 3 Tllim
   data[DS1822_SP_CFG]=onewire_readbyte();     // 4 Config
   data[DS1822_SP_RES0]=onewire_readbyte();    // 5 RES0
   data[DS1822_SP_RES1]=onewire_readbyte();    // 6 RES1
   data[DS1822_SP_RES2]=onewire_readbyte();    // 7 RES2
   data[DS1822_SP_CRC]=onewire_readbyte();     // 8 CRC

   if (field > 8) {
      //printf(debug_putc,"ERR! >scratchpad field 0x%x out of range (ds1822)\n\r",field);
      return(0);
      }
   else {
      //printf(debug_putc,"0x%x >scratchpad field 0x%x (ds1822)\n\r",data[field],field);
      return(data[field]);
      }
}


int onewire_ds1822_read_rom(int field) { /* rtns ROM info, one byte at a time */
   int data[8];

   if (!onewire_init_with_error_check())
     return (0);
   onewire_sendbyte(DS1822_CMD_READROM);

   data[DS1822_ROM_DEVTYPE]=onewire_readbyte();   // 0 family code
   data[DS1822_ROM_SERIAL1]=onewire_readbyte();   // 1 serial number LSB
   data[DS1822_ROM_SERIAL2]=onewire_readbyte();   // 2 serial number
   data[DS1822_ROM_SERIAL3]=onewire_readbyte();   // 3 serial number
   data[DS1822_ROM_SERIAL4]=onewire_readbyte();   // 4 serial number
   data[DS1822_ROM_SERIAL5]=onewire_readbyte();   // 5 serial number
   data[DS1822_ROM_SERIAL6]=onewire_readbyte();   // 6 serial number MSB
   data[DS1822_ROM_CRC]=onewire_readbyte();       // 7 CRC

   if (field > 7) {
      //printf(debug_putc,"ERR! >rom field 0x%x out of range (ds1822)\n\r",field);
      return(0);
      }
   else {
      //printf(debug_putc,"0x%x >rom field 0x%x (ds1822)\n\r",data[field],field);
      return(data[field]);
      }
}


int onewire_crc(int oldcrc, int newbyte) {
   // see http://pdfserv.maxim-ic.com/arpdf/AppNotes/app27.pdf
   int shift_reg, data_bit, sr_lsb, fb_bit, j;

   shift_reg=oldcrc;
   for(j=0; j<8; j++) {   // for each bit
      data_bit = (newbyte >> j) & 0x01;
      sr_lsb = shift_reg & 0x01;
      fb_bit = (data_bit ^ sr_lsb) & 0x01;
      shift_reg = shift_reg >> 1;
      if (fb_bit)
         shift_reg = shift_reg ^ 0x8c;
      }
   return(shift_reg);
}


int onewire_ds1822_set_temperature_resolution(int resolution) { /* set up for nbit resolution */
   int resolution_cfgfield;

   if ((resolution < 9) || (resolution > 12))
      resolution=9;

   resolution_cfgfield=((resolution-9)<<5);  // see DS1822 datasheet page 7

   if (!onewire_init_with_error_check())
     return (0);
   onewire_sendbyte(DS1822_CMD_SKIPROM);
   onewire_sendbyte(DS1822_CMD_WRITESCRATCHPAD);

   onewire_sendbyte(0b01111101);   // set max TH threshold (125'C)
   onewire_sendbyte(0b11001001);   // set min TL threshold (-55'C)
   onewire_sendbyte(resolution_cfgfield);    // Temp resolution, set to nbit

   onewire_init(); // reset
   onewire_sendbyte(DS1822_CMD_SKIPROM);
   onewire_sendbyte(DS1822_CMD_COPYSCRATCHPAD);
   delay_ms(15); // allow time for flash memory write.

   return( (onewire_ds1822_read_scratchpad(DS1822_SP_CFG) & 0b01100000)>>5 );
}


int onewire_ds1822_read_temp_c_lite() { /* 0 to 125'C byte rtnd, nonparasitic mode */
   int temperatureLSB, temperatureMSB, config, delaymult;

   config=((onewire_ds1822_read_scratchpad(DS1822_SP_CFG) && 0b01100000)>>5);
      // each addn'l resolution bit needs twice the base conversion time!
   if (!onewire_init_with_error_check())
     return (0);
   onewire_sendbyte(DS1822_CMD_SKIPROM);
   onewire_sendbyte(DS1822_CMD_CONVERTTEMP);

   delaymult=1<<config;
      //printf(debug_putc,"0x%x >delay_mult (ds1822)\n\r",delaymult);

   while (delaymult--)
      delay_ms(100); // allow worst case time for temp. conversion.

   temperatureLSB = onewire_ds1822_read_scratchpad(DS1822_SP_TLSB);
   temperatureMSB = onewire_ds1822_read_scratchpad(DS1822_SP_TMSB);

   if (temperatureMSB & 0b11111000) // if temp is negative rtn 0
      return(0);
   else {                           // else rtn the positive temp
      temperatureLSB=((temperatureLSB & 0b11110000)>>4);
      temperatureMSB=((temperatureMSB & 0b00000111)<<4);
      }
   return(temperatureMSB | temperatureLSB);  // OR msb&lsb
}

tevfik_kadi

Hocam su donmuş olsa bile suyun en dibi her zaman +4 derecedir diye biliyorum ben yoksa canlı yaşayamazdı donan sularda bu da doğanın bir kanunu  :)  ;)

zafzaf82

ben de örnek bi kod vereyim.
DS 1820.C
#BYTE TRISA=0x85
#BYTE PORTA=0x5
#BYTE STATUS=0x3
#define RP0  5
#define C 0


// The following are standard 1-Wire routines.
void make_ds1820_high_pin(int sensor)
{
   TRISA = 0xff;
}

void make_ds1820_low_pin(int sensor)
{
   PORTA = 0x00;
   TRISA = 0xff & (~(0x01 << sensor));
}


// delay routines
void delay_10us(int t)
{
#asm
            BCF STATUS, RP0
 DELAY_10US_X:
            CLRWDT
            NOP
            NOP
            NOP
            NOP
            NOP
            NOP
            DECFSZ t, F
            GOTO DELAY_10US_X
#endasm
}

void delay_ms(long t)	// delays t millisecs
{
   do
   {
     delay_10us(100);
   } while(--t);
}

void init_ds1820(int sensor)
{
   make_ds1820_high_pin(sensor);
   make_ds1820_low_pin(sensor);
   delay_10us(50);

   make_ds1820_high_pin(sensor);
   delay_10us(50);
}

int read_ds1820_one_byte(int sensor)
{
   int n, i_byte, temp, mask;
   mask = 0xff & (~(0x01<<sensor));
   for (n=0; n<8; n++)
   {
      PORTA=0x00;
      TRISA=mask;
      TRISA=0xff;
#asm
      CLRWDT
      NOP
      NOP
#endasm
      temp=PORTA;
      if (temp & ~mask)
      {
        i_byte=(i_byte>>1) | 0x80;	// least sig bit first
      }
      else
      {
        i_byte=i_byte >> 1;
      }
      delay_10us(6);
   }
   return(i_byte);
}

void write_ds1820_one_byte(int d, int sensor)
{
   int n, mask;
   mask = 0xff & (~(0x01<<sensor));
   for(n=0; n<8; n++)
   {
      if (d&0x01)
      {
         PORTA=0;
         TRISA=mask;		// momentary low
         TRISA=0xff;
         delay_10us(6);
      }

      else
      {
          PORTA=0;
          TRISA=mask;
	  delay_10us(6);
          TRISA=0xff;
      }
      d=d>>1;
   }
}


16f84 için uygulaması ise
#include <16F84A.h>
#use delay(clock=4000000)
#fuses NOWDT,XT, NOPUT, NOPROTECT
#include <ds1820.c>
#include <lcd.c>
//=====================================
// main program start here
//=====================================
void main(void)
{
   int buff[9], sensor, n,temp,temp_dec;

   delay_ms(50);
   lcd_init();

   while(true)
   {
      sensor=0;
      init_ds1820(sensor);
      write_ds1820_one_byte(0xcc, sensor);  // skip ROM
      write_ds1820_one_byte(0x44, sensor);  // perform temperature conversion
      while (read_ds1820_one_byte(sensor)==0xff); // wait for conversion complete
      init_ds1820(sensor);
      write_ds1820_one_byte(0xcc, sensor);  // skip ROM
      write_ds1820_one_byte(0xbe, sensor);  // read the result

      for (n=0; n<9; n++)     // read 9 bytes but, use only one byte
      {
         buff[n]=read_ds1820_one_byte(sensor);  // read DS1820
      }
      temp=buff[0]>>1;

      if ((buff[0] & 0x1)==1)
         temp_dec=5;
      else
         temp_dec=0;

      lcd_putc("\f");
      printf(lcd_putc,"Temp   :\n");
      printf(lcd_putc," %u.%u'C",temp,temp_dec);
      delay_ms(1000);
   }
} //enf of main program


Verdiğim kodlar için devre şemasıda bu



Kolay gelsin.....
Mikroişlemci bi araçtır, amaç değil.....

oyhan

Bende aşağısaki kodu çalıştırmaya uğraşıyorum ama hyper terminalde hep 127 sabit değerini alıyorum nerde hata var arkadaşlar bir yardımcı olabilirmisiniz. Kafam karıştı iyice..
#include <12F675.h>
#use delay(clock=4000000)
#fuses NOWDT, XT//,INTRC
#use rs232(baud=9600,xmit=PIN_A2,rcv=PIN_A1, INVERT)
#define Sensor PIN_A0

int Sensor_Reset(void);
int Sensor_Write(int data);
void Sensor_read(void);
int Temp_H[8],Temp_L[8],i;

void main(){
   int temp;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_comparator(NC_NC);
   setup_vref(FALSE);
   printf("\r\nWaiting for a Sensor...\r\n");
   while (TRUE) {
                  while(!Sensor_Reset()) ;
                  Sensor_Write(0xCC);
                  Sensor_Write(0x44);
                  delay_ms(200);


                  if(Sensor_Reset())
                  {
                     Sensor_Write(0xCC);
                     Sensor_Write(0xBE);
                     Sensor_read();

temp=((Temp_H[0]*64)+(Temp_H[1]*32)+(Temp_H[2]*16)+(Temp_H[3]*8)+(Temp_H[4]*4)+(Temp_H[5]*2)+(Temp_H[6]*1)+(Temp_H[7]?0.51:0.01));
printf("\n\rTemp: %d C\n\r",Temp);
// printf("\n\rTemp: %2.1f C%d%d%d%d%d%d%d%d\n\r",(Temp_L[7]?(-1*Temp):Temp),Temp_L[0],Temp_L[0],Temp_L[2],Temp_L[3],Temp_L[4],Temp_L[5],Temp_L[6],Temp_L[7]);
delay_ms(1000);
}
}
}

int Sensor_Reset(void){
int present;
output_low(Sensor);
delay_us(500);
output_float(Sensor);
delay_us(5);
if(!input(Sensor))
return(FALSE);
delay_us(65);
present=!input(Sensor);
delay_us(240);
if(present)
return(TRUE);
else
return(FALSE);
}


int Sensor_Write(int data){
for(i=1;i<=8;++i){
output_low(Sensor);
delay_us(10);
if(shift_right(&data,1,0)){
output_high(Sensor);
delay_us(10);
}
else{
output_low(Sensor);
delay_us(10);
}
delay_us(50);
output_high(Sensor);
delay_us(50);
}
return(TRUE);
}

void Sensor_read(void){
for(i=0;i<8;i++) {
output_low(Sensor);
delay_us(14);
output_float(Sensor);
delay_us(5);
Temp_H[7-i]=input(Sensor);
delay_us(100);
}
}
BİRLİKTEN KUVVET DOĞAR:

zafzaf82

1wire.c
// (C) copyright 2003 j.d.sandoz / jds-pic !at! losdos.dyndns.org

// released under the GNU GENERAL PUBLIC LICENSE (GPL)
// refer to http://www.gnu.org/licenses/gpl.txt

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

/***********************1Wire Class***********************/
/*Description: This class handles all communication */
/* between the processor and the 1wire */
/* sensors.
/*********************************************************/

/*-------1-wire definitions-------*/
#define ONE_WIRE_PIN PIN_A0

/*******************1-wire communication functions********************/

/************onewire_reset*************************************************/
/*This function initiates the 1wire bus */
/* */
/*PARAMETERS: */
/*RETURNS: */
/*********************************************************************/

void onewire_reset()  // OK if just using a single permanently connected device
{
 output_low(ONE_WIRE_PIN);
 delay_us( 500 ); // pull 1-wire low for reset pulse
 output_float(ONE_WIRE_PIN); // float 1-wire high
 delay_us( 500 ); // wait-out remaining initialisation window.
 output_float(ONE_WIRE_PIN);
}

/*********************** onewire_write() ********************************/
/*This function writes a byte to the sensor.*/
/* */
/*Parameters: byte - the byte to be written to the 1-wire */
/*Returns: */
/*********************************************************************/

void onewire_write(int data)
{
 int count;

 for (count=0; count<8; ++count)
 {
  output_low(ONE_WIRE_PIN);
  delay_us( 2 ); // pull 1-wire low to initiate write time-slot.
  output_bit(ONE_WIRE_PIN, shift_right(&data,1,0)); // set output bit on 1-wire
  delay_us( 60 ); // wait until end of write slot.
  output_float(ONE_WIRE_PIN); // set 1-wire high again,
  delay_us( 2 ); // for more than 1us minimum.
 }
}

/*********************** read1wire() *********************************/
/*This function reads the 8 -bit data via the 1-wire sensor. */
/* */
/*Parameters: */
/*Returns: 8-bit (1-byte) data from sensor */
/*********************************************************************/

int onewire_read()
{
 int count, data;

 for (count=0; count<8; ++count)
 {
  output_low(ONE_WIRE_PIN);
  delay_us( 2 ); // pull 1-wire low to initiate read time-slot.
  output_float(ONE_WIRE_PIN); // now let 1-wire float high,
  delay_us( 8 ); // let device state stabilise,
  shift_right(&data,1,input(ONE_WIRE_PIN)); // and load result.
  delay_us( 120 ); // wait until end of read slot.
 }

 return( data );
}


ds1820.c
float ds1820_read()
{
 int8 busy=0, temp1, temp2;
 signed int16 temp3;
 float result;

 onewire_reset();
 onewire_write(0xCC);
 onewire_write(0x44);

 while (busy == 0)
  busy = onewire_read();

 onewire_reset();
 onewire_write(0xCC);
 onewire_write(0xBE);
 temp1 = onewire_read();
 temp2 = onewire_read();
 temp3 = make16(temp2, temp1);
 
 //result = (float) temp3 / 2.0;   //Calculation for DS18S20 with 0.5 deg C resolution
 result = (float) temp3 / 16.0;  //Calculation for DS18B20 with 0.1 deg C resolution
 
 delay_ms(200);
 return(result);
}



main.c
#include <16F877.h>
#device *=16
#device adc=8

#FUSES NOWDT, HS, PUT, NOPROTECT, NODEBUG,BROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)

#include<1wire.c>
#include<flex lcd.c>
#include<ds1820.c>


void main()
{
float temperature;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);


lcd_init();
lcd_putc("\f");

while (true)
{
  temperature = ds1820_read();

  lcd_gotoxy(1,1);
  printf(lcd_putc,"TEMP: %3.1f ", temperature);
  lcd_putc(223);
  lcd_putc("C    ");

  lcd_gotoxy(1,2);
  if(temperature >= 29.0)
   printf(lcd_putc,"Hot!    ");
  else if( temperature >= 20 && temperature < 29.0)
   printf(lcd_putc,"Comfort!");
  else
   printf(lcd_putc,"Cold!   ");
 }

}


Mikroişlemci bi araçtır, amaç değil.....

cifci

hoca bunun hex fileınıda koyabilirmisin sana zahmet pic c le pek aram yokta en azından hex koduyla olayı yapayım bende 1 wire la ilgileniyorumda

Ersin


cifci

zafzaf82 bu kodların hex file ını koyman mümkünmü acaba sana zahmet c le pek aram yokta .hex kodlarını koyarsan çok sevinicem.  :oops:

erhanleon1985