View previous topic :: View next topic |
Author |
Message |
mtsoule
Joined: 19 Oct 2011 Posts: 31
|
Set multiple pins on single instruction |
Posted: Sun Nov 04, 2012 6:25 am |
|
|
My brain must be asleep, this seems like an easy task but i just can't grasp it this morning.
Device PIC16F1827
Compiler 4.137
if i were to have:
Code: |
char my_var = 0x55;
output_b(my_var);
|
Then all pins in port B would be 0x55 at the same time. But i need some of the bits in the byte to go to different pins. Here is my define:
Code: |
// DEFINE PORT 'A' I/O FUNCTIONS
#define Out_3 pin_A0 // Output - Output 3
#define Out_6 pin_A1 // Output - Output 6
#define PinA2 pin_A2 // Output - NC
#define PinA3 pin_A3 // Output - NC
#define PinA4 pin_A4 // Output - NC
#define PinA5 pin_A5 // Output - Programming Vpp
#define PinA6 pin_A6 // Output - NC
#define PinA7 pin_A7 // Output - NC
// ***** PORT 'B' *****
// DEFINE PORT 'B' I/O FUNCTIONS
#define Out_1 pin_B0 // Output - Output 1
#define Out_2 pin_B1 // Output - Output 2
#define Serial_RX pin_B2 // Input - Serial Data Input
#define Out_4 pin_B3 // Output - Output 4
#define Out_5 pin_B4 // Output - Output 5
#define Serial_TX pin_B5 // Output - Serial Data Output
#define Out_7 pin_B6 // Output - Output 7
#define Out_8 pin_B7 // Output - Output 8
|
What I need is for my_var to set the Output 1-8 at the same time.
I hope I have explained my question well enough, I am sure it is elementary but what am I forgetting?
Thanks! |
|
|
mtsoule
Joined: 19 Oct 2011 Posts: 31
|
I dont think its possible... |
Posted: Sun Nov 04, 2012 7:37 am |
|
|
the more i think about this, i was thinking about my assembly days and how i would do this in assembly (dream sequence starting...)
and i dont think this is going to be possible in a single instruction because i am working with two different ports at the same time...
any one confirm i am thinking correctly.. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Sun Nov 04, 2012 9:35 am |
|
|
You are correct.
You can reduce the total instructions involved though, in the case of the port B pins.
Read the port. OR with 0b11011011. Write value out to the port.
If using fast_io, takes three instructions, whereas using the bit operations takes 6.
You need to be using fast_io to do this, otherwise the output will change the TRIS on the serial port pins, which you won't want.
On port A, you can't reduce the total, since reading, setting, and writing will take one more instruction than just the two bit output instructions.
Best Wishes |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Nov 04, 2012 11:21 am |
|
|
SYNCHRONOUS updates are only possible with ONE port at a time.
To get a LOT of i/o lines to change synchronously otherwise,
you need to use some form of external latches or SPI latches Like the HC595 or even denser i/o combos of ganged HC595 's
or I2C expanders with 16 or more pins that can change in sync.
It was not clear if your application depends on SYNC I/O updates or if you are trying to paper over the way an existing circuit is wired to your pic. |
|
|
|