Go Down

Topic: Direct Port Manipulation Through a variable - help (Read 775 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
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

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.


Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

dhenry


DuaneB

Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

WizenedEE

Code: [Select]
volatile uint8_t& thePort = PORTB;
thePort ^= 0x08

Go Up