This seems to work pretty well with IAR (set optimizations to high)
Unlike #define Button (P1IN & BIT3) this actually returns a boolen value 0 or 1
You can not mix your code with regular P1IN and P1OUT as it complains about overlap.
Could not get #undef to work to actually over write the original P1IN (it uses DEFC() and is there a UNDEFC()?)
Would like to just use PIN and POUT name for all Ports (P1, P2,P3), e.g a 24bit field uses 3 byte destinations that are not back to back (possible?)
optional, you could omit the PIN1 name in the structure (anonymous) and then only directly refer to the bitname REDLED = BUTTON;
__no_init volatile union{
struct{ unsigned char
IN_0 : 1,
IN_1 : 1,
IN_2 : 1,
BUTTON : 1,
IN_4 : 1,
IN_5 : 1,
IN_6 : 1,
IN_7 : 1;
} PIN1; } @ P1IN_;
__no_init volatile union{
struct{ unsigned char
REDLED : 1,
OUT_1 : 1,
OUT_2 : 1,
OUT_3 : 1,
OUT_4 : 1,
OUT_5 : 1,
GREENLED : 1,
OUT_7 : 1;
} POUT1; } @ P1OUT_;
int __low_level_init(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
POUT1.REDLED = PIN1.BUTTON; //<< EXAMPLE
return PIN1.BUTTON ; //<< EXAMPLE
}