Ok, I have something bollixed up, but it looks right to me. "There's nothing wrong with it, it just doesn't work."
#define Button1Bit 0 uint8_t p[3] ; ButtonBits = ButtonCommonPort.IN | 0xc0 ; p[0] = PacketNumber ++ ; p[1] = 42 ; p[2] = 0 ; if (ButtonBits == ~(1<<Button1Bit)) p[2] = 9 ;
Now, I can see with the debugger, ButtonBits is 0xfe, but the if never iffs. Wouldn't ~(1<<Button1Bit) be 0xfe?
Yesterday, this code was:
if ((ButtonBits & (1<<Button1Bit)) != 0)
and was detecting my buttons most beautifully. So today, the silly thing insists on seeing the WRONG button. So I decided to be more picky about the bits. Apparently, I got too picky about the bits.
It's an xMega8E5 and the port pins are all configured
PORTD.PIN0CTRL = (3<<3) ;
Each has a tactile button connected to portd bit 7, which I set low.