# storing two-byte value in eeprom

#### quantumlab

Joined Dec 4, 2008
19
Hi Im trying to store a 10-bit value in my eeprom of the 16f887. To write it to the eeprom it needs to be broken up into two bytes. i have used the following code but there are a few errors. could you help with the code please

char i, j;
void main() {
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
PORTB = 0; // Initial PORTB value
TRISB = 0; // Set PORTB as output
PORTC = 0;
TRISC = 0;

j = 257;
for (i = 0; i < 1; i++)

void EEPROMWriteInt(int i, long j) // error is here***
{
byte Byte1 = ((j >> 0) & 0xFF);
byte Byte2 = ((j >> 8) & 0xFF);

EEPROM.write(i, Byte1);
EEPROM.write(i + 1, Byte2);
}
Delay_ms(50);
for (i = 0; i < 1; i++) {
Delay_ms(500);
}
}

#### AlexR

Joined Jan 16, 2008
732
At the start of your program you define i and j as global variables of type character but in the process EEPROMWrite you try to redefine i and j as int and long respectfully.
Either remove the global define or rename the variables i and J in EEPROMWrite to something else.
Also if j is a character it can't be assigned a value of 257, the maximum value a character can have is 255.

#### quantumlab

Joined Dec 4, 2008
19
thanks for your help. However errors are still occuring. the problem is the line:

EEPROMWriteInt(int i, long j)

it is saying it is undeclared.

I may need to include EEPROM.h

when i do this it cannot open the file.

Where do i find this header file or is it necessary?

Thanks

#### AlexR

Joined Jan 16, 2008
732
That error message is saying that you have not declared the EEPROMWriteint function prior to using it. As EEPROMWriteInt is a function that you have written and not a library function you will have to declare it before your program can use it.
Add the line of code below to declare the EEPROMWriteint function and put it just before main()
Rich (BB code):
void EEPROMWriteInt(int, long);
You most likely will have to add an include to the EEPROM.h header file to use the eeprom library functions and also any other headers the your C (if it is indeed C) program needs but where they reside I can't say since I have no idea what program you are using.

#### quantumlab

Joined Dec 4, 2008
19
Hi thanks again for your help. We are using MikroC. The following line is now giving me an error:

byte Byte1 = ((p_value >> 0) & 0xFF)

Any idea why?

The error is:

';' expected but Byte1 found

#### AlexR

Joined Jan 16, 2008
732
I don't know if byte is a valid data type in MikroC but its not part of ANSI C. Try using char instead and see if that works.