port settings?

I have a nano. I don't understand how to never change the initial values or output values for the pins I should never change (RX, TX, A6, A7, and crystal pins). All the other pins are set to output and HIGH in this example. I want to make sure I'm starting right and never changing RX, TX, A6, A7, and crystal pins.

Please help.

DDRD = DDRD | B11111111;

DDRB = DDRB | B11111111;

DDRC = DDRC | B00111111;

PORTD = B11111100;

PORTB = B11111111;
PORTC = ?

When you use a bitwise OR the only pins that are changed are those which have a 0 in the original and a 1 in the new value - in other words an OR can only make pins go from 0 to 1

When you use a bitwise AND the only pins that change are those with a 1 in the original and a 0 in the new value - in other words an AND can only make pins go from 1 to 0.

If you need to set some pins and clear some pins while leaving other pins unchanged then you need two port writes. If you need to change the values at the same instant then you could make a copy of the whole port byte, change the pins in the copy and then write the updated value back to the port.

...R

Its more complicated than that if you are using any interrupt handlers. Depending on the
values involved the compiler may map an instruction like

  PORTB |= mask;

into one or several instructions. If its more than one instruction, then if the interrupt routine
runs in the gap between them and happens to use the same register (directly or indirectly via
digitalWrite), your code will break.

So the way to guarantee this always works is:

  noInterrupts();
  PORTB |= mask;
  interrupts();

(or if you want your code to run inside an interrupt handler itself, you'll need:

  byte oldSREG = SREG;
  cli();
  PORTB |= mask;
  SREG = oldSREG;

which is the sort of thing digitalWrite() has to do.)