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 support@ccsinfo.com

help request about i2c

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







help request about i2c
PostPosted: Thu Oct 13, 2005 10:16 am     Reply with quote

I do not speak english very well, so please, accept my simple explanation.
I have two pics that communicate over i2c
One pic has a variable A that is a 16 bit integer, it must be transmitted to the second pic and written to a variable B that is 16 bit integer
How can I do?
The compiler has a routine for i2c that transmits variables 8 bit integer

Thanks
Ttelmah
Guest







PostPosted: Thu Oct 13, 2005 10:44 am     Reply with quote

You just write the two bytes that 'make up' the integer, and put them back together again at the other end.
There are a lot of code methods to access the bytes, but CCS, has two functions, 'make8', and 'make16', that do this for you. So if you send LSB first, then:
if you have the 16 bit value declared as 'val_to_send',

i2c_write(make8(val_to_send,0);
//Sends the first byte
12c-write(make8(val_to_send,1);
//sends the second.

At the other end, if you receive the two bytes into two 8bit variables called 'low', and 'high', you can re-assemble it with:

val_received=make16(high,low);

Best Wishes
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