Maker Pro
Maker Pro

pic32

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?
 
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:
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??
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
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:
Top