Setting PIC Outputs Simultaneously

Discussion in 'Programmer's Corner' started by jwilk13, Apr 20, 2012.

  1. jwilk13

    Thread Starter Member

    Jun 15, 2011
    228
    12
    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?
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    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.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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.
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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.
     
  6. jwilk13

    Thread Starter Member

    Jun 15, 2011
    228
    12
    My thoughts have been confirmed.

    Thanks!
     
Loading...