Go Down

Topic: Direct Port Manipulation Through a variable - help (Read 854 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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy