I'm writing firmware for a PIC16F877A in assembler, and I want to set some constants at the top of my source code to indicate which port is used for what, so that if needed I can easily change all the i/o pins around by changing the constant values and recompiling.
Like this:
O_LEDS EQU PORTA
CONSTANT O_RED = RA1
CONSTANT O_GREEN = RA2
CONSTANT O_BLUE = RA3
In my code, I need a bitmask to represent the ports I'm using. My question is, how can I write an expression using assembler directives to calculate the bitmask?
Using my example above:
O_RED = 1
O_GREEN = 2
O_BLUE = 3
and the bitmask I want is:
movlw b'00001110'
If there was a to the power of operator, I could do something like this:
movlw (2 ^ O_RED) | (2 ^ O_GREEN) | (2 ^ O_BLUE)
but ^
in MPASM is a Bitwise exclusive OR, not to the power of.
Can anyone think of another way to do this?