Question with writing to Port x

Hello and thank you for your time,

Quick question, I have this code from a LCD screen I am using:

void comm_out(unsigned char c)
{
  digitalWrite(RS, LOW);      //A0 = L = command
  PORTA = c;
  digitalWrite(WR, LOW);
  digitalWrite(WR, HIGH);
}

In this code, c is passed as a hex in the (0xff) form.

Now I am trying to transfer this code from a mega 2560 to an atmega 328P. I have not experimented with this yet, but would writing to port d have the same effect? Likewise, I may be using the RX and TX pins on the mega 328. These pins are on port D; see: https://www.arduino.cc/en/Hacking/PinMapping168. Is there a conventional way of writing to 8 digital pins? I would assume a string of if statements with minus 128, 64, 32, etc... would work. I am just asking if there is a more efficient approach.

Thanks again :slight_smile: ,

Joseph Samo

Is there a conventional way of writing to 8 digital pins?

On which port on which Arduino?

You need to be aware that you should not change all the pins on ANY of the ports on an Uno or on some of the ports on a Mega.

...R