256 VALUE IN ARRAY SHOWS AS 0, WHY?

I'm working with one array who has values multiples values, when one value it's bigger than 255 the count start form 0 again, example 256=0.

I thouhg it can be the flash memmory so I began to use the EEPROM but I still have the same problem, here is the code,

include <EEPROM.h>
 
const int tablaGC[]={50,100,150,200,250,255,255,256,257,258,259,50,100,150,200,250,255,255,256,257,258,259,260};  //0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,110,115,120,125,130,135Arreglo con los valores segun la tabla de grados centigrados segun tabla tipo k

int const *p;
int total=27;
void setup()
{
   int direc=0,valor; 
   Serial.begin(9600);
  /* Clear the memory ofth EEPROM of Arduino*/
  for (int i = 0; i < 512; i++)
   {
     EEPROM.write(i, 0);
   }
    delay(100);
   
   Serial.println("Inicia el guardado en EEPROM");
   for(int i =0; i<=sizeof(tablaGC);i++)
  {
     valor=*(p+direc);
    EEPROM.write(direc, tablaGC[direc]);
    direc=direc +1;    
    delay(10);   
     //if(direc == 255){direc=0;}
  }  
  delay(2000);
}

void loop()
{    
  Serial.println("Lectura de la EEPROM");
  for(int i=0; i<total; i++)
  {
    Serial.println(EEPROM.read(i));
    delay(1000);
  }
}

The values 256,257,258 and 259 shows as 0,1,2,3,4

Hope anyone can help me, I don't know what's the problem

Thanks

davidkurt:

include <EEPROM.h>

Serial.println(EEPROM.read(i));

http://arduino.cc/en/Reference/EEPROMRead

read()
Reads a byte from the EEPROM. Locations that have never been written to have the value of 255.

You are reading a byte (8-bit unsigned) value, and this has a value 0..255.

As stated, a byte has a value from 0 to 255. Once it goes beyond that, it overlaps. e.g. 256 is 0, 257 is 1, etc..

int is 2 bytes. You need to write lowbyte() and highbyte() and read them back to/from EEPROM.

http://arduino.cc/en/Reference/LowByte

the word(h.l) function will let you put them back in order.

You may need to cast the result as type int to get it to compile.

untested example:

int x = 1234;
byte low8bits = lowbyte( x );
byte high8bits = highbyte( x );

int y = (int) word( high8bits, low8bits ); // the (int) makes sure the result is a signed 16 bit value