Go Down

Topic: Direct Port Manipulation Through a variable - help (Read 723 times) previous topic - next topic

DuaneB

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

Code: [Select]

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

Coding Badly

#1
Oct 28, 2012, 08:55 am Last Edit: Oct 28, 2012, 08:59 am by Coding Badly Reason: 1
Hi,

Try this...

Code: [Select]
static uint8_t volatile * thePort;

thePort = & PORTB;

*thePort ^= 255;



Edit: Forgot the ampersand.

robtillaart


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

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

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

DuaneB

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

Thanks

Duane B.



dhenry


Go Up