Code keeps locking up and refuses to respond

Hello, I wrote a small sketch that interacts with a 74hc165 shift register. It basically reads the shift register stores the output in an array and then displays the contents to the serial monitor.
However, the serial monitor never displays anything.
I tried turning the led on pin 13 on at the start of the void loop and turning it off before the delay, essentially making it blink as the program would run. But the led wouldn’t blink. This leads me to believe the program is locking up somewhere in the middle, and I nor my colleagues can seem to figure out why.

I used both an Arduino Leonardo and Arduino Uno, and received similar results from both. You don’ t need a shift register for this sketch. Feel free to upload the code to a bare arduino and try to see if you can get at least dummy data to output on the display.

byte piso_load = 4; //piso shift register parallel load pin, active low
byte piso_clock = 7; //piso shift register clock pin, low to high transition
byte piso_out = 8; //piso shift register data output
byte piso_clockenable = 9; //piso shift register clock enable pin, low when shifting out 

int bits[8] = {0,0,0,0,0,0,0,0};

void setup(){
  Serial.begin(9600); 
  while(!Serial); 
  pinMode(piso_load, OUTPUT);
  pinMode(piso_clock, OUTPUT);
  pinMode(piso_out, INPUT);
  pinMode(piso_clockenable, OUTPUT);
  
  //set to high
  digitalWrite(piso_load, HIGH);
  digitalWrite(piso_clockenable, HIGH);
}

void loop(){
  
  //load in data
  digitalWrite(piso_load, LOW);
  digitalWrite(piso_load, HIGH);
  
  //allow data to be shifted out
  digitalWrite(piso_clockenable, LOW);
  
  for(byte ctr=7; ctr>=0; ctr--){
    //send a clock pulse to shift out current bit
    digitalWrite(piso_clock, LOW);
    digitalWrite(piso_clock, HIGH);  
    
    bits[ctr] = digitalRead(piso_out);
  }
  
  //disable clock pin
  digitalWrite(piso_clockenable, HIGH);
  
  for(byte ctr=0; ctr<8; ctr++){
    Serial.print(bits[ctr]);
  }
  
  delay(100);
  
}

Thanks, any help would be appreciated!

byte is an unsigned value and will never go below zero, it wraps around to its maximum value, so your loop is endless:

  for(byte ctr=7; ctr>=0; ctr--){
    //send a clock pulse to shift out current bit
    digitalWrite(piso_clock, LOW);
    digitalWrite(piso_clock, HIGH);  
    
    bits[ctr] = digitalRead(piso_out);
  }

use char instead!

Oh wow! Thank you so much

No worries, its a very common error, which I have run into many times when modifying code to maybe reverse a loop.

If you ever get in a real need to count down unsigned values to zero then there is the do-while() loop that checks at the end of the loop instead of the start. Sure, the count must be loaded ahead.