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

how to Split 16bit value into 16 1bit value.

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



Joined: 20 Aug 2013
Posts: 16

View user's profile Send private message

how to Split 16bit value into 16 1bit value.
PostPosted: Tue Aug 27, 2013 5:55 am     Reply with quote

Can anyone point me in the right direction for building a function to split a 16bit value into 16 1bit values then reassembling them again? For instance I have an integer of say 5423 I need to split that into to 1bit values. Im going to then send them through Modbus Reg to another PIC then reassemble the value once recieved. Also Im using C language and CCS copiler for programming the PIC.

Thanks in advance
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: how to Split 16bit value into 16 1bit value.
PostPosted: Tue Aug 27, 2013 6:14 am     Reply with quote

veerabahu wrote:
Can anyone point me in the right direction for building a function to split a 16bit value into 16 1bit values then reassembling them again? For instance I have an integer of say 5423 I need to split that into to 1bit values. Im going to then send them through Modbus Reg to another PIC then reassemble the value once recieved.


You don't have to. MODBUS has registers, so-called "input registers" and "holding registers", which are all 16 bit, as well as single bit "coils".

If you still want to split out each bit of a value then you can shift the bits using >> or << depending on whether you want to transmit the most significant bit first, then send the top bit and use <<, or the least significant bit, in which case send the lowest bit and use >>. Another way is to have a single bit mask that you use to and with the data and then shift the mask left or right as you need.
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