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

CCS program syntax question

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



Joined: 16 Apr 2007
Posts: 11

View user's profile Send private message

CCS program syntax question
PostPosted: Mon Apr 14, 2008 9:54 am     Reply with quote

In the file LM75CIM3.c provided with the compliler there is a line i dont understand

It is " data=(signed long)datah*10; "

Why use the "Signed long" in parentheses here? the function is this
Code:
signed long read_full_temp() {
   signed long datah, datal;
   signed long data;

   i2c_start();
   i2c_write(0x90);
   i2c_write(0x00);
   i2c_start();
   i2c_write(0x91);
   datah=i2c_read();
   datal=i2c_read(0);
   i2c_stop();

   data=(signed long)datah*10;

   if(bit_test(datal,7))
   {
      if(data < 0)
      {
          data -= 5;
      }
      else
      {
         data += 5;
      }
   }

   data=(data)*90;
   data=(data/50)+320;

   return(data);
}
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Mon Apr 14, 2008 10:57 am     Reply with quote

Here's a guess:

perhaps since i2c_read() returns an 8-bit int, the code was originally written with datah and datal being 8-bit integers. Then they were changed to unsigned longs and the casting was no longer needed, but never removed.
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