i want defining macros for set pin direction and level.their argumans must be port name and pin number.i dont want use TRIS Register or LAT register name,only port name(PORTA e.g).i do this with pointer and bit mask like:
set pin dir:
#define SET_PIN_DIR_IN(port,pin) *(&port+0x80)|=1<<pin
set pin level:
#define SET_PIN_HIGH(port,pin) port|=1<<pin
read pin state:
#define READ_PIN_LEVEL(port,pin) (((*(&port+0x100)>>pin)&0x01)==0x01)
but i know above code is not optimum. Q1:can i write my macro with "(((unsigned)&(REGISTER_NAME))*8) + BIT_NUM" Optimally? Q2:for all PIC MCU,is order of I\O register same?