CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Multiple DS18B20 in parasite Mode (finally working!!!)
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 10, 2017 5:46 am     Reply with quote

some Qs
1) does your PIC run a '1Hz LED program' correclty ?

2) does that PIC use 'pin_select'?

3) delete the PROTECT fuse ! Search here for why or read the datasheet

4) what's the code for the serial port for? Does it work without the DS code ?

Jay
kanzay



Joined: 23 Jan 2018
Posts: 1

View user's profile Send private message

To use more than one DS18B20 in one Pic with different Pins
PostPosted: Tue Jan 23, 2018 2:31 pm     Reply with quote

To use more than one DS18B20 in one Pic with different Pins.

Ii have more pins free so i found a solution like this.

İ found codes from many different websites so they are not written by me, i just added some code.

You may see original post

Code:
#include <16f876A.h>
#device adc=10
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4000000)
#use fast_io(a)
#define LCD_ENABLE_PIN  PIN_B2
#define LCD_RW_PIN      PIN_B1
#define LCD_RS_PIN      PIN_B0                                                   
#define LCD_DATA4       PIN_B4                               
#define LCD_DATA5       PIN_B5                               
#define LCD_DATA6       PIN_B6                   
#define LCD_DATA7       PIN_B7
#define ONE_WIRE_PIN PIN_C2
#define ONE_WIRE_PIN1 PIN_C3

#define use_portb_lcd TRUE   // LCD B portuna bagli
#include "lcd.c" // LCD kütüphanesinin eklenmesi

float sicaklik,eskisicaklik; // Kullanýlan deðiþkenlerin tanýmlanmasý
int8 sensor=0;

void onewire_reset()
{
if(sensor==0)
{
output_low(ONE_WIRE_PIN);
delay_us( 500 ); //1-wire resetleme için sıfıra çekilir
output_float(ONE_WIRE_PIN); //1-wire bir yapılır
delay_us( 500 ); // sensörün hazırlanması için beklenir.
output_float(ONE_WIRE_PIN);
}
////////
if (sensor==1)
{
output_low(ONE_WIRE_PIN1);
delay_us( 500 ); //1-wire resetleme için sıfıra çekilir
output_float(ONE_WIRE_PIN1); //1-wire bir yapılır
delay_us( 500 ); // sensörün hazırlanması için beklenir.
output_float(ONE_WIRE_PIN1);
}

}
void onewire_write(int data)
{
int count;
if (sensor==0)
{
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN);
delay_us( 2 ); // Sensöre yazma işlemine başlamak için 1-wire sıfıra çekilir.
output_bit(ONE_WIRE_PIN, shift_right(&data,1,0)); // yazılacak bilgi 1-wire'da
delay_us( 60 ); // Yazma işlemi zamanı doldurulur.
output_float(ONE_WIRE_PIN); // 1-wire bir yapılır,
delay_us( 2 ); // 1us'den fazla beklenir.
}
}
if (sensor==1)
{
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN1);
delay_us( 2 ); // Sensöre yazma işlemine başlamak için 1-wire sıfıra çekilir.
output_bit(ONE_WIRE_PIN1, shift_right(&data,1,0)); // yazılacak bilgi 1-wire'da
delay_us( 60 ); // Yazma işlemi zamanı doldurulur.
output_float(ONE_WIRE_PIN1); // 1-wire bir yapılır,
delay_us( 2 ); // 1us'den fazla beklenir.
}
}


}
 
int onewire_read()
{
int count, data;
if (sensor==0)
{
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN);
delay_us( 2 ); //Sensördem okuma işlemi içinl 1-wire sıfıra çekilir.
output_float(ONE_WIRE_PIN); //1-wire bir yapılır,
delay_us( 8 ); // Sensörün kendine gelmesi beklenir,
shift_right(&data,1,input(ONE_WIRE_PIN)); // sonuc bilgisi alınır.
delay_us( 120 ); //Okuma işlemi zamanı doldurulur.
}
}

if (sensor==1)
{
for (count=0; count<8; ++count)
{
output_low(ONE_WIRE_PIN1);
delay_us( 2 ); //Sensördem okuma işlemi içinl 1-wire sıfıra çekilir.
output_float(ONE_WIRE_PIN1); //1-wire bir yapılır,
delay_us( 8 ); // Sensörün kendine gelmesi beklenir,
shift_right(&data,1,input(ONE_WIRE_PIN1)); // sonuc bilgisi alınır.
delay_us( 120 ); //Okuma işlemi zamanı doldurulur.
}
}

return( data );
}
 
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 / 16.0;
delay_ms(200);
return(result);
}





void main()
{


   lcd_init();  // LCD'nin çalýþmasý hazýrlanmasý
   
   printf(lcd_putc,"ODA TERMOSTATI"); // Ekrana belirtilen yazýlarýn gönderilmesi
   printf(lcd_putc,"\nGELISTIRILIYOR"); // Yazýnýn baþýna eklenen \n komutu bir alt satýra geçmesi içindir.
   delay_ms(1000);
   printf(lcd_putc,"\f");
   printf(lcd_putc,"IC SICAKLIK");
   printf(lcd_putc,"\nDIS SICAKLIK");
   delay_ms(1000);

printf(lcd_putc,"\f"); // Ekraný silme komutu

   while (1)
   {
   
    sensor=0;
    sicaklik = ds1820_read(); // ds1820_read() fonksiyonu bize sýcaklýk bilgisini verir bu bilgiyi sicaklik olarak tanýmladýðýmýz deðiþkene atýyoruz
   
    if (eskisicaklik!=sicaklik) { // Ekranýn sadece sýcaklýk deðiþtiðinde yenilenmesi için 2. deðiþken ile karþýlaþtýrýlmasý. Eðer deðiþim var ise ekranýn yenilemesi.
    lcd_gotoxy(1,1); // Ekranýn yazmaya baþlamasý için 1. Satýr 1. Sütuna gitmesine yarayan fonksiyon.
    printf(lcd_putc,"\IC_ISI: %4.2fC", sicaklik); // Okunan Sýcaklýk bilgisi ekrana yazdýrýlýyor.
    eskisicaklik=sicaklik; // Ekranýn sadece sýcaklýk deðiþtiðinde yenilenmesi için 2. bir deðiþkene atýyoruz.
    }
    delay_ms(4000);
    sensor=1;
    sicaklik = ds1820_read(); // ds1820_read() fonksiyonu bize sýcaklýk bilgisini verir bu bilgiyi sicaklik olarak tanýmladýðýmýz deðiþkene atýyoruz
   
    if (eskisicaklik!=sicaklik) { // Ekranýn sadece sýcaklýk deðiþtiðinde yenilenmesi için 2. deðiþken ile karþýlaþtýrýlmasý. Eðer deðiþim var ise ekranýn yenilemesi.
    lcd_gotoxy(1,2); // Ekranýn yazmaya baþlamasý için 1. Satýr 1. Sütuna gitmesine yarayan fonksiyon.
    printf(lcd_putc,"DIS_ISI: %4.2fC", sicaklik); // Okunan Sýcaklýk bilgisi ekrana yazdýrýlýyor.
    eskisicaklik=sicaklik; // Ekranýn sadece sýcaklýk deðiþtiðinde yenilenmesi için 2. bir deðiþkene atýyoruz.
    }
    delay_ms(250);
   
   }

}
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 23, 2018 6:05 pm     Reply with quote

What is being done is copying and editing the driver for as many sensors as required. This is the easy way and works very well. I did this 5-6 years ago. While it does require more code space it ensures the correct timing for the devices

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group