This is more a question of style than anything else and might strike some as a bad thing to do. If I have a serial port pin on RC4, say, I can make some defines to help out:
#define TXSER_PIN LATC, RC4
What I realise then is that you can do this:
banksel LATC
bsf TXSER_PIN
banksel ANSELC
bcf TXSER_PIN
banksel TRISC
bcf TXSER_PIN
banksel INLVLC
bsf TXSER_PIN
I'm using the same define all the way down even though, theoretically, I suppose it's wrong to do so. The point is that I can change LATC, RC4
to LATB, RB7
and (after also changing APFCON0 to move the TX function) that's all that changes.
On this PIC I'm using, TRISA = 0x8C
and LATA = 0x10C
. But only the BANKSEL causes them to be distinguishable - TRISA, LATA, ANSELA, WPUA are really all the same 0x0C offset from the start of the bank and, as compiling the instruction implicitly does an "operand & 0xFF", they can be used interchangeably.
(In fact, that can be quite annoying if you use pairs of operands incorrectly. Something like bsf EEADRL, RC5
will not flag an error even though the compiler could easily do so. I wrote some awk to catch this...)
Can I run into trouble doing this or is it just bad form? Sure makes for less #defines though.