Will this mess up RX and TX pins?

The following sketch uses all port D to toggle 8 LEDs. However, it uses pin 0 and 1 which receive and transmit data. Will using pin 0 and 1 mess up uploading the sketch or uploading will be unaffected??. Thanks in advance. AA

void setup() {
  DDRD = B11111111; // set PORTD (digital 7~0) to outputs
}
void loop(){
  PORTD = B11110000; // digital 4~7 HIGH, digital 3~0 LOW
  delay(1000);
  PORTD = B00001111; // digital 4~7 LOW, digital 3~0 HIGH
  delay(1000);
}

It should work but for safety, disconnect pins 0 and 1 to upload the code.

You can use the ICSP pins to load a hex file, same as bootloading.

Thing is that since I don't, I'm very foggy on the steps how.

I used the posted sketch a number of times and worked fine. But at one point it started refusing the upload. So, I stopped using RX and TX and used D8 and D9 (changed loop as well). This removed the uploading issue. What I can't figure out is why it let me upload a good number of times and after it refused it.

The interference with uploading will come from the circuit you have connected to the pins, not from the program that is running on the UNO R3 board.

The reason the program running on the board won't interfere with the upload is that the ATmega328P is reset via a special circuit at the initiation of the upload and this causes the bootloader to run. So the sketch program is not even running on the ATmega328P when the upload process occurs.

Thanks.

I was able to reproduce the error when using D0 and D1

Sketch uses 880 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Failed uploading: uploading error: exit status 1

If you use the ICSP pins to load the chip, you won't need to leave RX and TX alone. But again, I haven't done that in years so I'd need a cookbook to do it myself.

Did you have anything connected to those pins when you encountered the upload failure? Or does it occur even when you are only running the sketch program on the board without any external circuitry connected to it?

There was circuitry connected to the 8 pins, see photo. Why would the interference come from the circuit connected to the pins?? Again, it worked fine for a few uploads and after it throws avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

Drained power from the pins?

Without hooking an Oscope and examining the waveform you won't know for sure why but we can make some educated guesses.
However the bottom line is that anything connected to pins 0 and 1 may interfere with uploads.

What is the Vf of the LED and the value of the resistor?
What is the upload baudrate?

The RX pin is configured as INPUT when uploading. And the output of the USB/UART converter is connected via a 1KOhm resistor to that pin. So if the pin is connected to some external load ( e.g. a LED ) the voltage drops and may not be sufficent to be recognized by the processor. Depending on the load it may or may not work.

[EDIT] Connecting something to the TX pin may be even worse. If you use it as INPUT in your sketch and connect it to the ouput of an external IC, two OUTPUTS work against each other when uploading. That may destroy one or even both.

Thanks, much appreciated

I'm using 4 different colors, so I'm just guessing some voltage averages: Reds: 1.8V, Blue: 3V, Green: 2.8V, Yellow: 2.1V. Baud: 9600.

Do you have it connected like this?

If yes, what is the value of R

To be more specific, the resistor is on the GND side of the LED and measured R is about 218 Ohm. The anode (+) of the LEDs connected to the Arduino digital pins.