In the ongoing process of simplifying my code, I am trying to avoid defining al the relevant PIN/PORT/DDR and just pass them to the header file at compile time.
I see in AVR header files that (Using PORT A as an example) [I checked Mega32 and Mega128]PORTA is deined as:
#define PINA _SFR_IO8(0x19) #define DDRA _SFR_IO8(0x1A) #define PORTA _SFR_IO8(0x1B)
My question is would it be valid to define just the port in my calling program and have the header file "calculate the rest" so...
#define myPORT PORTA
and my header.h has the following..
#ifndef myPORT #error" You have not specified a port!! " #endif #define myDDR myPORT-1 #define myPIN myPORT-2
Is this valid? (will try anyway) is there a more elegant way?