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 CCS Technical Support

ds18s20 & pic 18f4580

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jeremy57350



Joined: 11 Jan 2012
Posts: 14

View user's profile Send private message

ds18s20 & pic 18f4580
PostPosted: Sun Jan 22, 2012 1:06 pm     Reply with quote

Hello,

I received a research project, collect information from two sensor (DS1820) via the one wire bus making a difference in their temperature and to send results via the module MRF89XA

For now I am a study of a sensor and the temperature display on an LCD screen, for this I am using the codes given in the forums

the concern that I have produced a simulation program, but I always had a temperature of 4095 ° C

you help me with my project?


main program:

Code:


/*///////////////////////////////////
main.c

////////////////////////////////////*/

#include <18F4580.h>

#FUSES  NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NOMCLR

#use   delay(clock=4000000)
#define use_portb_lcd True

#include <lcd picdem2.c>
#include "ds1820.c"


void main(void)
{
   float temperature;
   lcd_init();
     printf(lcd_putc,"test");
     
   while(1)
   {
      temperature = ds1820_read();
      printf(lcd_putc,"\f%3.1f%cC", temperature, 223);
delay_ms(500);
   }

}


ds1820 program:

Code:


#define DS1820_WIRE_PIN                PIN_A5   //ds1820 data bacağı
//sensör için  sabitler
#define DS1820_SKIP_ROM                0xCC
#define DS1820_READ_SCRATCHPAD         0xBE
#define DS1820_CONVERT_T               0x44


static char g_shiftBit, g_dataOut;
static long g_temperature, g_dataInput;


void resetDS1820(void)
{
   output_low(DS1820_WIRE_PIN);     //1-wire resetleme için sıfıra çekilir
   delay_us(500);                   // sensörün hazırlanması için beklenir.
   output_float(DS1820_WIRE_PIN);   //1-wire bir yapılır
   delay_us(500);                   // sensörün hazırlanması için beklenir.

}

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

void readDS1820(void)
{
   g_dataInput = 0;
   for ( g_shiftBit = 1; g_shiftBit <= 16; ++g_shiftBit )
   {
      output_low(DS1820_WIRE_PIN);                                   //Sensörden okuma işlemi içinl 1-wire sıfıra çekilir.
      delay_us(2);                                                   
      output_float(DS1820_WIRE_PIN);                                //1-wire(data) bir yapılır,
      delay_us(8);                                                  // Sensörün kendine gelmesi beklenir,
      shift_right ( &g_dataInput, 2, input ( DS1820_WIRE_PIN ));   // sonuc bilgisi alınır
      delay_us(120);                                              //Okuma işlemi zamanı doldurulur.
   }
 
}
void waitForConversion (void)             
{
    while(TRUE)
    {
       output_low(DS1820_WIRE_PIN);
       delay_us(5);
       output_float(DS1820_WIRE_PIN);
       delay_us(5);
       if (input(DS1820_WIRE_PIN) == 1)   
       {
           break;
       }
       delay_us(55);
     }
}


long ds1820_read()
{
   
    resetDS1820();
    g_dataOut = DS1820_SKIP_ROM;
    writeDS1820();
    g_dataOut = DS1820_CONVERT_T;
    writeDS1820();
    waitForConversion();

    resetDS1820();
    g_dataOut = DS1820_SKIP_ROM;
    writeDS1820();
    g_dataOut = DS1820_READ_SCRATCHPAD;
    writeDS1820();
    readDS1820();
    g_temperature = g_dataInput / 16; //ds18s20 için bu değer 2 olacaktır

   
   return g_temperature;
}
temtronic



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

View user's profile Send private message

PostPosted: Sun Jan 22, 2012 2:34 pm     Reply with quote

Which sensors are you using ?

Your topic says DS18S20, some of your code is for the DS1820 and some of the code is for the DS18B20. They are all different with respect to actual code(driver) required to interace to the devices !!

You say 'simulation' so I can't help you fix Proteus or whatever 'simulator' you're using.As we all KNOW Proteus is full of bugs,errors, faulty DRCs and isn't worht the disk space it takes up.

Also you make 'temperature' a float,yet you try to 'stuff' an int16 into it(g_temperature). Pretty sure that will not work,you'll have to 'cast' it.

CCS does have a DS1820 driver in the drivers folder, and there is a B version 'somewhere' ( that's the one I use), maybe the code library ?
jeremy57350



Joined: 11 Jan 2012
Posts: 14

View user's profile Send private message

PostPosted: Sun Jan 22, 2012 4:24 pm     Reply with quote

My code was developed for a DS18S20. Where should I change something? What is necessary ? Can you help me please.

I understand if I change the code ds1820?

Thank you.
temtronic



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

View user's profile Send private message

PostPosted: Mon Jan 23, 2012 7:46 am     Reply with quote

Sorry but I only use the DS18B20( the parasitic powered units) and can't test code for the DS1820(don't have any).

I do not use 'simulators' as NONE of them, esp. Proteus, will simulate the real world.I use white 'breadboards' and real chips.

I'd suggest using the CCS supplied driver,others may have used it and can help though I suspect it works fine.CCS examples have always worked for me in the past 15-20 years.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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