conditional loop ends way too soon, cannot see why

for some reason my code ends exactly 1 bit too soon,

byte Value;

void setup() {
  DDRA = 0xFF;
  DDRC = 0xFF;
  DDRL = 0x00;
  Serial.begin(19200);
  pinMode(2, INPUT);

}

void loop() {
  while (digitalRead(2) == LOW) {}
  for (word i = 0x0; i != 0xFFFF; i++) {
    PORTA = lowByte(i);
    PORTC = highByte(i);
    Value = PINL;
    delayMicroseconds(2);
    if (Value < 0x10 ) {
      Serial.print(0);
    }
    Serial.println(Value, HEX);
    delayMicroseconds(2);
  }
  exit(0);
}

this is to read out EPROMs, it goes from Address $0000 to $FFFE, even tho i stated in the loop it is only supposed to end when it reaches $FFFF, i tried to use an "if" statement plus a "goto", also tried "while" statement. all of those loops ended 1 bit too early.

and when i try to display the current number by rewriting the Serial.println to display "i" it stops way too early. the Serial monitor looks something like this near the end:

FFEC
FFED
FFEE
FFEF
FFF0
FFF1
FFF2
FFF3
FFF

then it just ends. the LEDs on my breadboard show FFFE, but the monitor only FFF- (cut off). btw each of the other types of loops had the same Serial Monitor result.

A:
<some code>
++x;
if (x = <whatever>) {
  goto B
}
goto A
B:
exit(0);
while (x != <whatever>){
<some code>
++x;
}
exit(0);

what is going on with my code?

I suspect that at the moment that you exit(0), everything dies; this includes the remainder of the serial prints,

Try a Serial.flush() before the exit(0) or replace exit(0) by for(;;) {}

void loop()
{
  ...
  ...
 
  Serial.flush();
  exit(0);
}

Or

void loop()
{
  ...
  ...
 
  for(;;);
}
  for (word i = 0x0; i != 0xFFFF; i++)

I read this as :

initialise i to 0x00
while i does not equal 0xFFFF
do stuff
then increment i

So the while loop ends when i becomes 0xFFFF and the code is not executed for that value of i, hence it stops at 0xFFFE

Try

  for (word i = 0x0; i <= 0xFFFF; i++)

UKHeliBob:
Try

  for (word i = 0x0; i <= 0xFFFF; i++)

That loop will never end because the condition is always true (a 16-bit value will never be greater than 0xFFFF).

You are quite right, but this will work

  for (unsigned long i = 0x0; i <= 0xFFFF; i++)

Yes, using something longer than a word worked.

now i get all 64kB.

thanks!

say is there any way to read data from an external File (.TXT or .BIN or something) and then use whatever is in the file and load that into the EPROM/EEPROM?

something like using the file as an Array to draw Bytes from.

The file on an SD card? Or what? Reading data from an SD card is easy.

is there any way to read data from an external File

You can read data from a file on an SD card if you have the right hardware or you could send it over the Serial link from the PC but you will need software to send the file from the PC and a sketch on the Arduino to read it and save it.

can i not just skip the SD card and directly read from the PC and use that?

otherwise i would need to buy something that can hold an SD card, and also somehow put raw binary data onto it.

1Proxy0:
can i not just skip the SD card and directly read from the PC and use that?

otherwise i would need to buy something that can hold an SD card, and also somehow put raw binary data onto it.

The Arduino isn't part of the PC so it can't read the hard drive on it or anything.

You could write code to go on the PC to read a file and send the data to Arduino over serial and then write code on the Arduino to read from the serial line and do whatever with it.

It can be done with a

word

size variable using a do/while loop structure.

// increment word from zero to zero

void setup() {
  Serial.begin(230400);
  unsigned long counter = 0;
  word i = 0;
  do {
    counter += 1;
    i += 1;
  } while (i != 0);
  Serial.print("counter incremented ");
  Serial.print(counter);
   Serial.print(" times");
}

void loop() {
  // put your main code here, to run repeatedly:

}

To send a file from the PC you need something different to the Arduino Serial Monitor. RealTerm or a hundred other terminal programs will allow you to select a file and blurt it out to Serial.

christop:
That loop will never end because the condition is always true (a 16-bit value will never be greater than 0xFFFF).

Yup. ONe way to address this is with a do-while loop

word i = 0;
do {
  print i;
  i++;
}
while(i != 0);