CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

write/read int32 to internal eeprom

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jaime



Joined: 25 Nov 2005
Posts: 56
Location: Porto - Portugal

View user's profile Send private message Visit poster's website

write/read int32 to internal eeprom
PostPosted: Wed Mar 18, 2009 8:42 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 18, 2009 9:02 pm     Reply with quote

That code is old, and does not work with the modern compiler (starting
with vs. 4.021). You need to cast the pointer to an int8*, as shown
in the FAQ:
http://www.ccsinfo.com/faq.php?page=write_eeprom_not_byte
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group