Convert Arduino pins to AVR PORTs

Hi,
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".

Thanks.

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.

This Instructable post might be interesting for you to read: