jaime
Joined: 25 Nov 2005 Posts: 56 Location: Porto - Portugal
|
write/read int32 to internal eeprom |
Posted: Wed Mar 18, 2009 8:42 pm |
|
|
Hello
I find a piece of code for read/write int32 to the internal eeprom but I'm getting some errors.
I'm doing something wrong?
Code: | #include<18F2550.H>
#use delay (clock=16000000)
#use rs232(baud=57600, xmit=pin_b6, rcv=pin_b7)
#fuses HS, NOLVP, NOWDT, PUT, NOBROWNOUT
////////////////////////////
void ee_write32(char base_address ,int32 data)
{
char i;
for(i=0; i<4; i++)
write_eeprom(base_address+i,*(&data+i));
}
////////////////////////////
int32 ee_read32(char base_address)
{
char i;
int32 data_read;
for(i=0; i<4; i++)
*(&data_read+i) = read_eeprom(base_address+i);
return (data_read);
}
////////////////////////////
void main()
{
int32 data, data1;
int f, data2;
data = 0xA5A5A5A5;
ee_write32(0x00, data); //write data to EEPROM loc 0x00 to 0x03
data1 = 0x12345678;
ee_write32(0x04, data1); //write data to EEPROM loc 0x04 to 0x07
data2 = 0x34;
write_eeprom(0x08,data2); //write data to EEPROM loc 0x08
data = ee_read32(0x00); //read data from EEPROM loc 0x00
data1 = ee_read32(0x04); //read data from EEPROM loc 0x04
data2 = read_eeprom(0x08); //read data from EEPROM loc 0x08
printf("\n\rData lx = %lx",data);
printf("\n\rData1 lx = %lx",data1);
printf("\n\rData2 x = %x",data2);
printf("\n\r");
for(f=0;f<=8;f++)
printf("%x ",read_eeprom(f));
while(1){}; //infinite loop
}
//////////////////////////// |
and in the terminal
Code: | Data lx = 000000a5
Data1 lx = 00000078
Data2 x = 34
a5 01 01 06 78 01 01 06 34 |
Any help? thanks _________________ www.jagsilva.com |
|