Electronic – Why do people use (1 << PA0) when setting port


In AVR Tutorials I often see:

DDRA |= (1 << PA0);
PORTA |= (1 << PA0);

used instead of:

DDRA |= PA0;

What is the purpose of this?

Best Answer

PA0 will be defined as 0 so the following line:

DDRA |= (1 << PA0);

Equates to shifting 1 left by zero bits, leaving an OR with the value 1 to set the first bit. Whereas the following line:

 DDRA |= PA0;

Is doing an OR with zero so won't change the registers at all.