Basic understanding of direct port manipulation code

Pedro,
Instead of using DDRx command, I just use pinMode as would normally be done, and then commands like

PORTD = PORTD & B11110111; // clear bit 3
PORTD = PORTD | B00001000; // set bit 3

and your comands work normally.

I use the above with SPI for fast transfers to shift registers, for example sending out bytes from an array:

PORTD = PORTD & B11110111;  // clear bit 3, used for slave select/latch
SPI.transfer(dataArray[x]);
SPI.transfer(dataArray[x+1]);
SPI.transfer(dataArray[x+2]);
SPI.transfer(dataArray[x+3]);
PORTD = PORTD | B00001000;  // set bit 3, used for slave select/latch

Lose some portability from '328 to '1284 ot '2560 this way, but I'm usually coding for a specific chip for a specific project so I don't worry about that.