Setting PIC Outputs Simultaneously

Thread Starter

jwilk13

Joined Jun 15, 2011
228
Hi all,

I'm playing with a PIC18F45K20 using MPLAB IDE and Sourceboost C compiler, and would like to set multiple outputs (from different registers) simultaneously, if possible. I am using the following as outputs:

RD0, RD1, RD2, RD3
RC4, RC5, RC6, RC7

As an example, I would like to set RD0, RD1 and RC5 to output high at the same time. I know I can do it individually with very minimal delay:

set_bit(latd,0);
set_bit(latd,1);
set_bit(latc,5);

Or have the contents of one register set and then the other:

latd = 0b00000011;
latc = 0b00100000;

But I would like to have them all set high at the same time if possible. Can it be done?
 

t06afre

Joined May 11, 2009
5,934
I wrote a thread with this quite recently. I do not remember which to whom i gave the answer. But try google and bit manipulation c. It should give you some hints. Then setting more than one bit. Bit manipulation using logical AND, OR, or XOR will be strongly advised
 

MrChips

Joined Oct 2, 2009
30,824
You can do this if the bits are on the same port.
If they are on different ports that's a bit more difficult. You will have to do it with external hardware.
 

ErnieM

Joined Apr 24, 2011
8,377
...I would like to have them all set high at the same time if possible. Can it be done?
No it can't. The port access instruction opperates on (up to) 8 bits of each port at a time. To do any access over 2 ports requires a minimum of 2 instructions, possibly more.

If you go up to the larger word cores you can do that. in fact there is a parallel master port that can do 16 (or 24?) pins at the same time, plus automatically handle some control line things too.

That is the PMP module if you wish to look further.
 

t06afre

Joined May 11, 2009
5,934
You can do this if the bits are on the same port.
If they are on different ports that's a bit more difficult. You will have to do it with external hardware.
Oh my bad. I was thinking the OP wanted to set some bits. At the same time on the same port. Of course setting bits simultaneously outside the boundary of a port. Can not be done on a 18F PIC. Perhaps you can rearrange the use of ports instead.
 
Top