PIC microcontrollers have 3 basic registers to set GPIO (General Purpose I/O) pin status. These are: TRIS (Tri-status, the direction register. Sets the pin as in or out) PORT (The input buffer) LAT (Latch, the output burffer).
Ports can be A, B, C... etc. So the TRIS register for the port A is TRISA.
Then finally there is the pin number. For example, TRISA1.
TRISA1 is defined as:
// TRISA<TRISA1>
extern volatile __bit TRISA1 __at(0x461); // @ (0x8C * 8 + 1)
#define TRISA1_bit BANKMASK(TRISA), 1
I would like to define a macro to easily name the pins as:
#define _DATA_OUTPUT A2
So I can do code like:
LAT_DATA_OUTPUT = 1;
PORT_DATA_OUTPUT = 0;
and have it converted by the preprocessor to:
LATA2 = 1;
PORTA2 = 0;
so I can later expand to other pin registers such as ANSEL, WPU, etc, without rewriting the macros or add special cases.
Is this possible? Or what's the closest thing I can do to emulate this?