shift register all outputs high

I am using a 74hc595n with a seven segment display. My code is simply to help me identify which bits are controlling which specific segments, but for some reason when the last segment is to be displayed, they all light up. The byte sent to the register has a value of 128 and yet it acts like 255. Even more bizarre is that it does the same thing for all values over 128. Also, as expected, 127 shows all but the last segment.

Here's my code:

const int dataPin1 = 4;    //pin 14 on chip
const int latchPin = 5;    //pin 12 on chip
const int clockPin = 6;    //pin 11 on chip

int incomingByte;
int i=0;

byte onesDigit = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(dataPin1,OUTPUT);
  pinMode(dataPin2,OUTPUT);
  pinMode(latchPin,OUTPUT);
  pinMode(clockPin,OUTPUT);
  onesDigit=0;
  Serial.println("would you like another iteration?");
}

void loop()
{
  updateRegister1();
  
  if(Serial.available())
  {
    incomingByte = Serial.read();
  }
  
  if (incomingByte==121)
  {
    onesDigit=0;
    bitSet(tensDigit,i);
    updateRegister1();
    Serial.print("i value: ");
    Serial.println(i);
    i++;
    Serial.print("onesDigit value: ");
    Serial.println(tensDigit);
    
    Serial.println("would you like another iteration?");
  }
  incomingByte=1;
  
  if(i>8)
  {
    i=0;
  }
    
}


void updateRegister1()
{
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin1, clockPin, MSBFIRST, onesDigit);
  digitalWrite(latchPin, HIGH);
}

I have no idea what the problem is. Any advice?

Supply decoupling on the shift register. Have you got any?
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Hi, does that compile? I see a variable called tensDigit that I can't see declared for example.

Can you explain what the sketch is meant to do?

Paul

The variable onesDigit should also be different to test each register-output, but it is always 0 using your sketch.