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 map 18-bit word to 3 ports?

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







How to map 18-bit word to 3 ports?
PostPosted: Thu Dec 21, 2006 10:15 am     Reply with quote

I need to output a 18-bit word to 3 ports: first 8 bits to portB, second 8 bits to portC and last 2 bits to portD. How to do this?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 21, 2006 12:19 pm     Reply with quote

Where is this 18-bit word stored ? Is it in a 32-bit integer, or in
bytes in a structure ?

The first task is to get individual bytes. If the 18-bit word is in
a 32-bit integer, you can use the CCS function, make8(), to extract
the bytes. Or, you can use the right-shift operator to shift the
bits into the lower byte, before outputting them.

To send the bytes to a port, use the CCS port i/o functions, such
as output_b(), output_c(), etc. If you're not using the upper 6 bits
on Port D, and you don't care if they're changed, then you could just
use output_d() for the last two bits. If you do care about the upper
six bits on Port D, and only want to change the lower 2 bits, then use
the CCS bit_test() function to test the value of bits 16 and 17 in your
18 bit word (bits are numbered 0 to 17). Then use an if() statement
based on the result of the bit_test(), and do an output_low(PIN_D0)
or output_high(PIN_D0) as required. Do the same thing for bit 17
and set PIN_D1 as required.
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