Re:k8055

can anyone please help me see. i dont understand why when i load this program, i set all digital, everything will be lighted and when i try to off it, the led tends to jump around. is it due to the x in this program? the X is as followed 1,2,4,8,16,32,64,128 for the 8 outputs.

private void button9_Click_1(object sender, EventArgs e)

    {

        if (button9.Text == "OFF")
        {
            button9.Text = "ON";
            button9.BackColor = Color.LimeGreen;
            x += 1;
           


        }
        else
        {
            button9.Text = "OFF";
            button9.BackColor = Color.Red;
            x -= 1;

        }
        WriteAllDigital(x);
    }
    private void button10_Click_1(object sender, EventArgs e)
      {

          if (button10.Text == "OFF")
          {
              button10.Text = "ON";
              button10.BackColor = Color.LimeGreen;
              x += 2;


          }
          else
          {
              button10.Text = "OFF";
              button10.BackColor = Color.Red;
              x -= 2;

          }
          WriteAllDigital(x);
      }