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

Temperature sensor LM75

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



Joined: 19 Nov 2003
Posts: 22

View user's profile Send private message

Temperature sensor LM75
PostPosted: Wed Sep 22, 2004 5:35 am     Reply with quote

Hi,

I have been reading the datasheet for the temperature sensor LM75 and is said that the temperature value is represented by 9 bits in 2 complement.

If I read two bytes in order to read such value, do I have to program some special case in order to know if the temperature is negative or positive?

Code:

// bytes variables which will store the temp. value
byte temp_high, temp_low

i2c_start()
i2c_write(TEMP_SENSOR | 1);
temp_high= i2c_read();
temp_low= i2c_read();
i2c_stop();

if (temp_low == 0x80) // To find out if the temp is .5 or .0
{
   sprintf(the_temp,"%d.5\n",temp_high);
}
else
{
   sprintf(the_temp,"%d.0\n",temp_high);
}


Doing that, does 'sprintf' know about the 2 complement representation of temp_high?

Thanks for your help,

ibg

P.S: I don't have this chip with me. That's why I can't test it ;-)
godinel claudiu
Guest







lm75 multiple senzors on i2c 2 wire bus
PostPosted: Tue Mar 20, 2007 7:45 pm     Reply with quote

Ok... guys now here is the program that reds more temperature sensors lm75 -cim5 connected to a i2c 2 wire bus.
all you need to do is ad if and Lm75_wite_n and lm75_read_n and change tehe last if....hope you like it..

I will try to make a dallas 1 wire bus now, and make it so send data to the rs232 to output it nice in some plots...
But first i must get some ds1820 or ds18s20 or ds18b20 , and i only found ds18s20+, does anyone know the difference ?


#include <16F870.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,PUT,NOPROTECT,BROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG
#define SDA_PIN PIN_C2 // i2c serial data in/out
#define SCL_PIN PIN_C3 // i2c serial clock
#define p1 PIN_A3
#define LM75_WRITE1 0x90 // 1001 0000
#define LM75_READ1 0x91 // 1001 0001
#define LM75_WRITE2 0x9e // 1001 1110
#define LM75_READ2 0x9f // 1001 1111

#use i2c(master,sda=SDA_PIN, scl=SCL_PIN)
int8 dataH,dataL,temp,senz,x;
int1 flgSign;
char grad;

void i2c_init(void)
{
output_high( SCL_PIN );
output_high( SDA_PIN );
}


void lm75_start(int8 x)
{
i2c_start();
if (x==1) i2c_write(LM75_WRITE1);
else i2c_write(LM75_WRITE2);
i2c_write(0x01); // Pointer Byte
i2c_write(0x00); // Configuration Byte (operating)
i2c_stop();
}

void lm75_setandread(int8 x)
{
i2c_start();
if (x==1) i2c_write(LM75_WRITE1);
else i2c_write(LM75_WRITE2);
i2c_write(0x00); // Pointer Byte
i2c_start();
if (x==1) i2c_write(LM75_READ1);
else i2c_write(LM75_READ2);
dataH = i2c_read(); // with ACK
dataL = i2c_read(0); // with NOACK
i2c_stop();
}

#include <lcdme.c>

main() {

i2c_init();
delay_ms( 10 );
lcd_init();
senz=1;
grad=223;

while(1)
{

lcd_gotoxy(1,1);
printf(lcd_putc,"Senz");
lcd_gotoxy(6,1);
printf(lcd_putc,"%u =",senz);

lm75_start(senz);
delay_ms( 30 );
lm75_setandread(senz);
//lm75_shutdown();
delay_ms( 100 );

// Stabileste valoarea/semnul temperaturii (in 0,5 grade Celsius)
flgSign = 0;
if( bit_test( dataH, 7 ) ){ // semn negativ (bit-ul 7 setat)
flgSign = 1;
dataH = ( 0xFF - dataH + 1 );
}
dataH = ( dataH << 1 );
if( bit_test( dataL, 7 ) ) // 0,5 grade (bit-ul 7 setat)
dataH |= 0x01;

// Ajusteaza valoarea temperaturii (cu +2 grade) (4 unitati de 0,5 grade)
if (senz==1) dataH -= 25 ;
if (senz==2) dataH -= 33 ;
dataL += 128 ;
temp=dataH;

lcd_gotoxy(1,2);
printf(lcd_putc,"Tmp");
lcd_gotoxy(5,2);
printf(lcd_putc,"%u" ,dataH);
lcd_gotoxy(7,2);
printf(lcd_putc,"%cC",grad);
if (!input(p1)) {senz=senz+1; if(senz==3) senz=1;}
delay_ms(100);
}}
// made by Godinel Claudiu
// made by Godinel Claudiu
// made by Godinel Claudiu
//mess id claudiu_godinel for further questions
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Mar 20, 2007 10:28 pm     Reply with quote

Quote:

But first i must get some ds1820 or ds18s20 or ds18b20 , and i only found ds18s20+, does anyone know the difference ?


Architecture:
The DS18S20 uses a bandgap temperature sensing architecture
The DS1820 uses the dual-oscillator architecture.
This architectural difference is invisible to the user.

Specification Differences:
The primary specification difference between the two parts is the temperature conversion time:
DS1820 = 500ms (max)
DS18S20 = 750ms (max).

Software Compatibility:
The DS1820 DS18S20 Digital Thermometer provides 9 bit centigrade temperature measurements
and are software compatible in most applications.

The DS18B20 Digital Thermometer provides 9 to 12–bit centigrade temperature measurements
and has an alarm function with nonvolatile user-programmable upper and lower trigger points.

Hardware Compatibility:
The DS1820 DS18S20 and DS18B20 communicates over a 1-Wire bus that by definition requires
only one data line (and ground) for communication with a central microprocessor.


Humberto
godinel claudiu
Guest







thanks for the specifications about ds1820's
PostPosted: Wed Mar 21, 2007 1:41 am     Reply with quote

hei..Thanks... did'nt know allu sad about them...

But does someone know someting about ds18s20+ ?

I would like to mention that
Ds18b20 is compatible with ds1822 & and can be user on 9 or 12 bits of rezolution.

And Ds18s20 is compatible whit Ds1820 and have 9 bits of rezolution.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Mar 21, 2007 4:51 am     Reply with quote

Quote:

But does someone know someting about ds18s20+ ?

A plus (+) in the part number indicates lead-free, the device keeps its functionalities.


Humberto
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