Pages: [1]   Go Down
Author Topic: Convert Arduino pins to AVR PORTs  (Read 1587 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
Karma: 4
Posts: 93
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to write an interrupt that uses bitSet(), bitClear(), bitRead(), etc., to manipulate the ports for speed, rather than digitalRead() and digitalWrite().  Why do I need that speed?  I don't, actually.  But I want to do it because I want to learn more about the AVR, I want to get my chops up, and because it's there (tm).

But bitSet() has two arguments: The PORT, and the pin in the PORT.  However, I would like my library that includes this interrupt to take the Arduino pin as its argument; I don't want the programmer to have to figure the PORT and pin.

Can anyone explain to me why this works:
uint8_t sPort = digitalPinToPort(13);
bitSet(sPort, 5);

But this does not?
bitSet(digitalPinToPort(13), 5);
...This one says, "error: lvalue required as left operand of assignment".



Seattle, WA USA
Online Online
Brattain Member
Karma: 615
Posts: 49395
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you have a misunderstanding of what bitSet does. The argument names may be port and pin, but the function actually sets the nth bit (pin) of any byte (port).

So, the first argument is the one that you want to modify. You can't modify the output of a function (an lvalue - the left side of an equal sign - needs to be writable). The second one defines which bit to change.

Copenhagen / Denmark
Offline Offline
Edison Member
Karma: 6
Posts: 2360
Do it !
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This Instructable post might be interesting for you to read:

Pages: [1]   Go Up
Jump to: