Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Apr 06, 2010 7:31 am |
|
|
I think he is asking about splitting a byte onto two ports.
If so, not simply.
Different answers according to the actual pin layouts involved, how many pins are on each port, etc..
Simplest, test each bit in turn, and output the required bit based on the test. So:
Code: |
output_bit(PIN_A4,bit_test(val,0));
output_bit(PIN_A6,bit_test(val,1));
output_bit(PIN_A7,bit_test(val,2));
//etc..
|
This will work for any bit order, does not require the bits to be consecutive, and allows you to still use 'standard_io' mode. It is surprisingly quick to execute.
Other answer, rotate and mask (if required).
Code: |
output_b(val/16); //Put top fout bits of 'val' out on the low four
//bits of port B.
output_a((val*16)+(input_a() & 0xF)); //Put the bottom four bits of
//val, onto the top four bits of port A, at the same time keeping the
//bottom 4 bits of port A unchanged
|
Obviously, if the low bits here are used as inputs, provided you use 'fast_io' mode, you can set TRIS so only the top four bits are changed by the output, and don't have to mask.
A search here will find a number of answers to this, in particular in relation to LCD's split across ports.
Best Wishes |
|