while loop does not move to next line

Hi

I am trying to read data from a Prom by waiting for the address selector to switch to 0x00.

Then read the data and wait for address 0x01.

In my code the while loop never move on to the next line.

I even hard wire the address inputs on my arduino to ground to simulate the first 0x00.

The Serial.print only prints a never ending loop of zeros but does not exit the while loop.

Something wrong with my while loop.

uint8_t randNumber = 0;
uint8_t data = 0;
const unsigned int numReadings = 8;
unsigned int myArray[numReadings];

int PE = 17;//A3
int ME = 18;//A4
int WORD1 = 0;
int WORD2 = 0;
int WORD3 = 0;
int WORD4 = 0;
int WORD5 = 0;
int WORD6 = 0;
int WORD7 = 0;
int WORD8 = 0;
int val = 0;
int counter = 0;
int a = 30;
int CHANNEL = 0X05;//anything but zero
long startUs;
long endUs;
long elapsed;


void printdata()
{

  Serial.println(WORD1);
  Serial.println(WORD2);
  Serial.println(WORD3);
  Serial.println(WORD4);
  Serial.println(WORD5);
  Serial.println(WORD6);
  Serial.println(WORD7);
  Serial.println(WORD8);
}

void setup()
{
  pinMode (PE, OUTPUT);
  pinMode (ME, INPUT);

  pinMode (14, INPUT);
  pinMode (15, INPUT);
  pinMode (16, INPUT);
  pinMode (8, INPUT);
  pinMode (9, INPUT);
  pinMode (10, INPUT);
  pinMode (11, INPUT);
  
  Serial.begin (9600);

  //Serial.println("NJ8820");
  //delay(1000);
}

void loop()
{
  while (digitalRead(18) == HIGH) //Memory Enable -  wait for low pulse
  {
  }
  delayMicroseconds(52);//(13uS X 4) clock cycles

  while ( CHANNEL != 0X00)
  {
    byte CHANNEL = PINC;//
    CHANNEL = CHANNEL & B00000111;//MASK OFF UPPER BITS
    Serial.println(CHANNEL);
  }

  byte WORD1 = PINB;//
  WORD1 = WORD1 & B00001111;//mask off upper 4 bits
  //----------------------
  while ( CHANNEL != 0X01)
  {
    byte CHANNEL = PINC;//
    CHANNEL = CHANNEL & B00000111;//MASK OFF UPPER BITS
  }

  byte WORD2 = PINB;//
  WORD2 = WORD2 & B00001111;//mask off upper 4 bits
  //----------------------
  while ( CHANNEL != 0X02)
  {
    byte CHANNEL = PINC;//
    CHANNEL = CHANNEL & B00000111;//MASK OFF UPPER BITS
  }

  byte WORD3 = PINB;//
  WORD3 = WORD3 & B00001111;//mask off upper 4 bits
  //----------------------
  while ( CHANNEL != 0X03)
  {
    byte CHANNEL = PINC;//
    CHANNEL = CHANNEL & B00000111;//MASK OFF UPPER BITS
  }

  byte WORD4 = PINB;//
  WORD4 = WORD4 & B00001111;//mask off upper 4 bits
  //----------------------
  while ( CHANNEL != 0X04)
  {
    byte CHANNEL = PINC;//
    CHANNEL = CHANNEL & B00000111;//MASK OFF UPPER BITS
  }

  byte WORD5 = PINB;//
  WORD5 = WORD5 & B00001111;//mask off upper 4 bits
  //----------------------
  while ( CHANNEL != 0X05)
  {
    byte CHANNEL = PINC;//
    CHANNEL = CHANNEL & B00000111;//MASK OFF UPPER BITS
  }

  byte WORD6 = PINB;//
  WORD6 = WORD6 & B00001111;//mask off upper 4 bits
  //----------------------

  while ( CHANNEL != 0X06)
  {
    byte CHANNEL = PINC;//
    CHANNEL = CHANNEL & B00000111;//MASK OFF UPPER BITS
  }

  byte WORD7 = PINB;//
  WORD7 = WORD7 & B00001111;//mask off upper 4 bits
  //----------------------
  while ( CHANNEL != 0X07)
  {
    byte CHANNEL = PINC;//
    CHANNEL = CHANNEL & B00000111;//MASK OFF UPPER BITS
  }

  byte WORD8 = PINB;//
  WORD8 = WORD8 & B00001111;//mask off upper 4 bits
  //------------------------------

  Serial.println(WORD1);
  Serial.println(WORD2);
  Serial.println(WORD3);
  Serial.println(WORD4);
  Serial.println(WORD5);
  Serial.println(WORD6);
  Serial.println(WORD7);
  Serial.println(WORD8);

  Serial.println("Done");
  while (1)
  {
  }

}

Thanks.

Do not redefine channel, get rid of the byte in the

    byte CHANNEL = PINC;//

satements.

with a bit more explanation, by using 'byte' within your while in front of the variable name, you were declaring a locally scoped variable within the curly braces of the while loop. As such it was in existence just within that while iteration.

When you were going back to the assess the condition in the while, the global variable was used and of course its value had not change so you were stuck there.

eg

int foo = 5;
void setup()
{
  Serial.begin(115200);
  Serial.println(foo); // will print 5
  { // create a block or "Compound statement" (a brace-enclosed sequences of statements)
    int foo = 6; // declare a locally scoped variable hiding the global one
    Serial.println(foo); // will print 6
  } // here the local variable gets out of scope and disappears
  Serial.println(foo); // the compiler goes back to the global variable will print 5
}

void loop() {}

--> read about variable scope