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

PIC16F877 & DS1620 Temperature Sensor

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







PIC16F877 & DS1620 Temperature Sensor
PostPosted: Wed Mar 01, 2006 8:03 am     Reply with quote

Hello everyone,

I am having difficultly Confused in developing a fucntion to read the temperature from the DS1620 using the PIC16F877. At the minute my display will either be the 7-seg or LCD Display on the Bluebird PIC Millenium Board. If anyone can offer any assistance plaese reply or send to colly_316@hotmail.com.

Cheers. Cool

Colly.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 01, 2006 6:01 pm     Reply with quote

Quote:
I am having difficultly in developing a fucntion to read the
temperature from the DS1620 using the PIC16F877

To find a CCS driver, use http://www.google.com
For the search string, put in the name of the chip and then put in
some keywords that are used only by CCS. Example:
(Make sure you use the quotes)

ds1620 "#use delay"

With that search string, the very first hit in Google shows a schematic
and source code in CCS.
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: PIC16F877 & DS1620 Temperature Sensor
PostPosted: Thu Mar 02, 2006 4:41 pm     Reply with quote

Colly McKenna wrote:
Hello everyone,
I am having difficultly in developing a fucntion to read the temperature from the DS1620 using the PIC16F877.


colly,
post the code you are having difficulty with.

jds-pic (not holding breath)

ps:
http://www.ccsinfo.com/forum/viewtopic.php?t=19520
King Virus



Joined: 02 Mar 2006
Posts: 14
Location: Italy

View user's profile Send private message Send e-mail Visit poster's website

Temp reading from DS1621
PostPosted: Fri Mar 03, 2006 12:08 pm     Reply with quote

Hi Colly McKenna !

Try to use the DS1621. For this component I´ve made a simple driver to use CCS !

If you are interested I could post it !? It works fine...it is to do some counting stuff on the PC side, but it should not be a problem to do it. Cool
_________________
*** A good forum is a forum where people respect eatch other ! ***
Colly McKenna
Guest







Millieuim Board
PostPosted: Mon Mar 06, 2006 7:33 am     Reply with quote

HI Guys,

See below the code i have developed do far - i dont think the actual problem is with getting the DS1620 to read a temperature - the part i am havinf difficulty with is getting some code to display this data - at the moment i am using a simple PIC Bluebird Millieuim Development Board.

Many Thanks,

Colly

/**************************************************************************
* Project: Simple Test Program for Greenhouse Thermometer *
* File: test.c *
* Date: Feb 06 *
* Processor: PIC16F877 *
* Developed by: Colin McKenna (12077102) *
* *
* This project measures the temperature with a DS1620 type integrated *
* circuit (IC) sensor. The temperature is then displayed on a Millenium *
* Board every second in the format " nn C". *
* *
***************************************************************************/

#include <p16f877.h>
#include <displays.h>
#include <delays.h>
#include <datalib.h>
#include <strings.h>
#byte PORTD = 8
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP


/* Port Definitions */
#define RST PA..B0
#define CLK PA.B1
#define DQ PA.B2
#define DIG_H PA.B3
#define DIG_L PA.B4

/* DS1620 Functions */
char write_config = 0x0c;
char start_conv = 0xee;
char read_temp = 0xaa;

/* This function sends a data bit to the DS1620 Thermometer IC */

void write_ds1620_bit(char a)
{
DQ = a;
CLK =0;
CLK =1;
DQ =1;
}

/* This function reads a data bit from the DS1620 Thermometer IC */

char read_ds1620_bit()
{
char a;
CLK = 0;
a = DQ;
CLK=1;
return(a);
}

/* This function writes data/configuration to the DS1620 */

void write_to_ds1620(char ds1620_function, char ds1620_data, char bit_count)
{
char i, a_bit;
RST=1;
for (i=0; i<8; i++)
{
a_bit = ds1620_function >> i;
a_bit = a_bit & 0x01;
write_ds1620_bit(a_bit);
}
for (i=0; i<bit_count; i++)
{
a_bit = ds1620_data >> i;
a_bit = a_bit & 0x01;
write_ds1620_bit(a_bit);
}
RST=0;
}

/* This function reads data/configuration from the DS1620 */

int read_from_ds1620(char ds1620_function, char bit_count)
{
char i, a_bit;
int ds1620_data;

ds1620_data = 0;
RST=1;
for(i=0; i<8; i++)
{
a_bit = ds1620_function >>i;
a_bit = a_bit & 0x01;
write_ds1620_bit(a_bit);
}
for(i=0; i<bit_count; i++)
{
ds1620_data = ds1620_data | read_ds1620_bit() <<i;
}
RST=0;
return(ds1620_data);
}

/* Start of MAIN */

void main()
{
int left_digit, right_digit, temp=0;
TRISA = 0; /* Initialize Micro */
TRISD = 0;

/* Configure DS1620 for coninous operation */

write_to_ds1620(write_config,2,8);

/* Start conversion */

write_to_ds1620(start_conv,0,0);

while(1) /* DO FOREVER */

{

temp = read_from_ds1620(read_temp,9);
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Mon Mar 06, 2006 7:44 am     Reply with quote

A search of this board and the examples directory of the compiler will reveal many, many examples of LCD driver code.
_________________
The difference between genius and stupidity is that genius has its limits...
servera



Joined: 15 Dec 2010
Posts: 2

View user's profile Send private message Visit poster's website

DS1620 working driver
PostPosted: Sat Jan 01, 2011 11:50 am     Reply with quote

This is a DS1620 working and tested driver, use it as you like.

Code:


#define DS1620_dq    PIN_A0 // DS1620 DQ
#define DS1620_clk   PIN_A1 // DS1620 CLK
#define DS1620_rst   PIN_A2 // DS1620 RST

#define PortAConfig   0b00000000

#USE STANDARD_IO( All )

//
//  DS1620 Commands
//
#define CONF_REG           0x0C     // WRITE COMMAND
#define READ_TEMP          0xAA     // READ COMMAND
#define START_CONVERT      0xEE
#define STOP_CONVERT       0x22
#define CONTINUOUS_CONV    0x00

//
// Function Declarations
//
void main( void );
void Setup( void );
void InitDS1620( void );
void write_commandDS1620( int Command );
unsigned int ReadDS1620( void );


//
//.............................................................................
//
void main( void )
{
   int16 Temp;
   int8 Centigrades;

   Setup();

   InitDS1620();

   //
   // Main loop
   //
   for( ; ; )
   {
      Temp = ReadDS1620();

      Centigrades = (int8)Temp / 2;

      delay_ms( 500 );
   }
}



//
//..............................................................................
//
// Setup the hardware.
//
void Setup( void )
{
   //
   // Port configuration. 1 = Inputs, 0 = Outputs. MSB first
   //
   set_tris_a( PortAConfig );

   //
   // Set to iddle mode all the outputs
   //
   output_high( DS1620_clk );
   output_low( DS1620_rst );
}



//
//.............................................................................
//
void InitDS1620( void )
{
   output_low( DS1620_rst );                    // idle
   output_high( DS1620_clk );

   output_high( DS1620_rst );                   // DS1620_rst hight enable communication
   write_commandDS1620( CONF_REG );
   write_commandDS1620( CONTINUOUS_CONV );
   output_low( DS1620_rst );                    // DS1620_rst low disable communication

   output_high( DS1620_rst );                   // DS1620_rst hight enable communication
   write_commandDS1620( START_CONVERT );
   output_low( DS1620_rst );                    // DS1620_rst low disable communication
}



//
//.............................................................................
//
// Sends 8 bit command on to DS1620, least significant bit first
//
void write_commandDS1620( int Command )
{
   int8 n;

   for( n = 0 ; n < 8 ; n++ )
   {
      //
      // When writing to the DS1620, output the data before the clk pulse
      // or at least before the rising edge of the clk pulse, see the datasheet
      //
      output_bit( DS1620_dq , shift_right( &Command , 1 , 0 ) );

      output_low( DS1620_clk );
      output_high( DS1620_clk );
   }
}



//
//.............................................................................
//
unsigned int ReadDS1620( void )
{
   int16 n, raw_data = 0;
   short int _bit;

   output_high( DS1620_rst );       // DS1620_rst hight enable communication

   write_commandDS1620( READ_TEMP );

   //
   // Read 9 bits from the DS1620, least significant bit first
   //
   for( n = 0 ; n < 9 ; n++ )
   {
      output_low( DS1620_clk );

      //
      // When reading from the DS1620, this IC outputs the data at the falling
      // edge of clk and remains valid until the rising edge of clk
      //
      _bit = input( DS1620_dq );    // CCS automatically makes DS1620_dq an input here

      output_high( DS1620_clk );

      raw_data = raw_data | ( _bit <<  n );
   }

   output_low( DS1620_rst );        // DS1620_rst low disable communication

   //
   // raw_data contains the temperature in 0.5ºC increments,
   // per example raw_data = 30 equals to 15ºC
   //
   return raw_data;
}


atai21



Joined: 30 Dec 2010
Posts: 31

View user's profile Send private message

PostPosted: Fri Mar 04, 2011 3:58 am     Reply with quote

Good day,
I want to ask something about ds1621. Can I have two ds1621 connected to 1 PIC (18f4550) ? They share the same pin (pin 33 and 34). For the code I have plan to use delay so that the data did not crash.

TQ
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 04, 2011 1:25 pm     Reply with quote

Yes, the ds1621 chip has three address pins. You can use these to set
a different i2c address for the 2nd chip. Then you can have two ds1621
chips on the same i2c bus. The driver software must specify the correct
address for each chip, when it talks to each chip.
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