Connect with us

pic32

Discussion in 'Microcontrollers, Programming and IoT' started by juantravel, Nov 11, 2010.

Scroll to continue with content
  1. juantravel

    juantravel

    41
    0
    May 14, 2010
    Im working with a pic32 starter kit and i ran into some code i dont understand.

    Code:
    mPORTDSetPinsDigitalOut(BIT_0 | BIT_1 | BIT_2);
    The | operator is a "or" bitwise operator correct? How does it work in this statement?
     
  2. rob_croxford

    rob_croxford

    262
    0
    Aug 3, 2010
    it sets bit_0, bit_1 and bit_2 as digital outputs
     
  3. juantravel

    juantravel

    41
    0
    May 14, 2010
    The | is bitwise "or" Correct? Im not sure how "or" fits in the statement. The question is how does the | affect the statement?

    bitwise example :

    0101
    or 0011
    =======
    0111
     
    Last edited: Nov 12, 2010
  4. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,363
    2,758
    Jan 21, 2010
    That's correct.

    0 or 0 = 0
    0 or 1 = 1
    1 or 0 = 1
    1 or 1 = 1
     
  5. juantravel

    juantravel

    41
    0
    May 14, 2010
    How does it work in the statement?

     
  6. rob_croxford

    rob_croxford

    262
    0
    Aug 3, 2010
    The OR operator compares two bits and generates a result of 1 if the bits are complementary; otherwise, it returns 0. Are you sure this is the whole statement and that it is not reliable on something else??
     
  7. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,363
    2,758
    Jan 21, 2010
    I would presume that mPORTDSetPinsDigitalOut is a function that takes a parameter that is type compatible with BIT_x (which I also presume are constants).

    Given that BIT_0, BIT_1, and BIT_2 will have some numeric representation (possibly 0x0000001, 0x00000010, and 0x00000100) the compiler will generate (for constants) or calculate at runtime (for variables) the logical OR of the bit patterns.

    If we presume the constants are as I suggested (and they may not be) then the three values are:

    00000001
    00000010
    00000100

    which OR together as

    00000111

    That last value is passed to the function which performs the implemented function, presumably setting the 3 low order bits of Port D as digital outputs.

    In this case the actual value passed is not really interesting. We presume that BIT_0 defines the value representing bit 0, and so on for bits 1 and 2 and we know that the OR operation performs the correct "summing" operation so that the value passed (whatever it is) represents all three bits.
     
    Last edited: Nov 12, 2010
  8. juantravel

    juantravel

    41
    0
    May 14, 2010
    Thank you

    Thanks Steve your awesome :) You have been very helpful.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
Loading...
Electronics Point Logo
Continue to site
Quote of the day

-