PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 21, 2006 12:19 pm |
|
|
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. |
|