View previous topic :: View next topic |
Author |
Message |
Edi Guest
|
Writing 10 bits to a splite I/O ports |
Posted: Sun Dec 21, 2003 7:49 am |
|
|
I'm using the 16F819, and I want to write 10 bits to I/O's.
The bits are split and mix between port A and port B.
Is there a nice way of doing it.
Thanks,
Edi |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Dec 21, 2003 9:45 am |
|
|
Depends on how the IO is split. If the 2 MSB are on A1 & A0 and the lower 8bits are on port B then it is very simple. You can use the make8() function to assign the upper byte to portA and the lower byte to portB. However, if there are other outputs on portA then instead of assigning the value to portA, you will need to AND 0xFC and then OR the upper byte. This might not be the best way (AND/OR) as the output might go low for a couple of instruction cycles after the AND. A lot depends on what you are trying to do. You can also create a union and overlay that onto portA and portB since their addresses are sequential. Give a little more detail and what you are writing this 10bit value to. |
|
|
Edi Guest
|
|
Posted: Sun Dec 21, 2003 1:52 pm |
|
|
I want to light a 7 segment but I have only 4 I/O free in port A and 6 in port B.
Can you please post a samples, how it can be done without a bit logic AND/OR to activate the 7 segment.
The bits are not in order.
What is make8()?
Edi |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Dec 21, 2003 5:15 pm |
|
|
In that case, the simplest is bit_test and output_high/output_low
Code: |
long var_10bit;
if (bit_test(var_10bit,0))
output_high(PIN_A0);
else
output_low(PIN_A0);
.
. other bit tests go here.
.
if (bit_test(var_10bit,9))
output_high(PIN_B3);
else
output_low(PIN_B3);
|
|
|
|
Edi Guest
|
|
Posted: Mon Dec 22, 2003 8:53 am |
|
|
Thanks for your answer.
Isn't there a way to write it in one line, like: struct10bit = value;
and each bit will ge it's value.
Thanks,
Edi |
|
|
|