Direct Port Manipulation Through a variable - help

Hi,
I am trying to access a port through a variable as in -

thePort = PORTB;

thePort ^= 255;

Whatever I do I cannot get this to work inside a library - I am sure its something daft but I need another pair of eyes to see it

Thanks

Duane B

Hi,

Try this...

static uint8_t volatile * thePort;

thePort = & PORTB;

*thePort ^= 255;

Edit: Forgot the ampersand.

your code makes a copy of the value in the port, you should write it back.

thePort = PORTB;
thePort ^= 255;
PORTB = thePort;

Hi,
Thanks all, mystery solved, it was the forgotten ampersand.

Thanks

Duane B.

Easy:

#define thePort PORTB

thePort ^= 255;

Easy, also pointless.

Duane B

volatile uint8_t& thePort = PORTB;
thePort ^= 0x08