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

DS1820 temperature

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



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

DS1820 temperature
PostPosted: Fri Jun 25, 2004 2:10 pm     Reply with quote

I am trying to use the DS1820 temperature sensor to measure temperature provided with the easy2 package. Does anyone has sample programs. I want to read the temperature and show the results on the LCD.

Thanks in advance
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri Jun 25, 2004 4:20 pm     Reply with quote

I used this several years ago. It should give you a starting point at least.

Code:

Int8 shiftbit,data;
Int16 Temperature,Address;
/*-------------------------------------------------------------------
Pull Reading From Temp Probe
-------------------------------------------------------------------*/

resetDallas();                // Transmit reset
data = 0xCC;
writeDallas();                // Transmit rom command "skip"
data = 0xBE;
writeDallas();                // Transmit memory command "read"
ReadDallas();
resetDallas();                // Transmit reset
data = 0xCC;
writeDallas();                // Transmit rom command "skip"
data = 0x44;
writeDallas();                // Transmit memory command "aquire Temp"
Temperature = Address;



/********************************************************************
* Reset Dallas Temperature Sensor *
********************************************************************/
void resetDallas()
{  output_high(PIN_B2);          //Low pulse for 600 uS
   delay_us(600);             //time as stated
   output_low(PIN_B2);          //High pulse for 600 uS
   delay_us(600);             //time as stated
}
/********************************************************************
* Write Int to Dallas Temperature Sensor *
********************************************************************/
void writeDallas()             // last for about 66 uS per bit
{  for(shiftbit=1;shiftbit<=8;++shiftbit)
   {  output_high(PIN_B2);
      delay_us(8);
      output_bit(PIN_B2,!(shift_right(&Data,1,0)));
      delay_us(57);
      output_low(PIN_B2);
      delay_us(2);
   }
   delay_us(200);
}
/********************************************************************
* Read Long Int from Dallas Temperature Sensor *
********************************************************************/
void ReadDallas()             // last for about 66 uS per bit
{  Address = 0;
   for(shiftbit=1;shiftbit<=16;++shiftbit)
   {  output_high(PIN_B2);
      delay_us(14);
      output_low(PIN_B2);
      delay_us(4);
      shift_right(&Address,2,input(PIN_B0));
      delay_us(55);
   }
}
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: DS1820 temperature
PostPosted: Mon Jun 28, 2004 8:15 am     Reply with quote

young wrote:
I am trying to use the DS1820 temperature sensor to measure temperature provided with the easy2 package. Does anyone has sample programs. I want to read the temperature and show the results on the LCD.

Thanks in advance


the ds1820 and ds1822 work very much the same. thus, check out the code library forum, where i have posted full ccs source code for a ds1822 driver...
http://www.ccsinfo.com/forum/viewtopic.php?t=19520

jds-pic
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Mon Jun 28, 2004 12:35 pm     Reply with quote

Hi neutone and Jds-Pic:

I am totally new on the pic world. and do not know how to handle the problem. regarding to Jds-Pic's prohgram when I compiled it, there is a ONE_WIRE_PIN not fedined error occured, what this ONE_WIRE_PIN refers to, is that the PIN that measure the temperature (middle pin of the DS1820 sensor)? by the way, this is just a .h header file, could you please provide a complete file with main() and LCD display function? I am currently connecting the sensor pin with RE2 (easy2 pic16f877a), and my lcd is connected with portB.

Please help!

Thanks
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

PostPosted: Mon Jun 28, 2004 3:25 pm     Reply with quote

young wrote:
there is a ONE_WIRE_PIN not fedined error occured, what this ONE_WIRE_PIN refers to, is that the PIN that measure the temperature (middle pin of the DS1820 sensor)?


that pin does not "measure the temperature". it is the onewire I/O pin, by which you communicate with the DS1820 device. hence, you'll need a declaration in your source file as such:

#define PIN_C5 31765
#define ONE_WIRE_PIN PIN_C5

note that you will have to determine the correct pin and correct register for the specific PIC you are using. the example above is for the 18F252, port C5. don't forget that you need a pullup (1K should be OK) on the onewire net.

young wrote:
by the way, this is just a .h header file, could you please provide a complete file with main() and LCD display function? I am currently connecting the sensor pin with RE2 (easy2 pic16f877a), and my lcd is connected with portB.

Please help!

Thanks


no problem -- i've gone ahead and completed the code as you described above, and ordered a couple of prototype boards as well. the system documentation will be complete as well when the prototype boards arrive in a few days. moreover, i've also scheduled UL and FCC compliance testing. i'll let you know how initial board bringup and software integration comes along.

jds-pic
Guest








PostPosted: Mon Jun 28, 2004 3:52 pm     Reply with quote

Jds_pic:

Thank you very much for your great help. The board I am using is PIC easyPIC2 from Mikro, with PIC16f877a chip. the DS1820 comes with the microchip packages, and on the board there is already a DS1820 setup position. DS1820 is easily pluged into the three pins, I guess( I also measure the pin voltage after I plug it in) it should be build up with power on the ground and Vqq pins (not the kinds of PARASITE_POWER). DQ pin could be connected to RA5 or RE2 by jumper.

Thanks agagin, and waiting for your response eagerly!
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