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 CCS Technical Support

how to write int16 into eeprom?

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



Joined: 02 Oct 2009
Posts: 123
Location: Denmark

View user's profile Send private message

how to write int16 into eeprom?
PostPosted: Fri May 30, 2014 8:23 am     Reply with quote

To my understanding of the manual write_eeprom (address, value) only accepts int8 as value. Then how do I save an int16 in eeprom??

I guess that to read it I can do something like
Code:

int8 hi, lo;
int16 x;
lo=read_eeprom(0);
hi=rad_eeprom(1);
x = make16(hi,lo);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 30, 2014 8:28 am     Reply with quote

See the CCS faq (link at the top of this forum page):
http://www.ccsinfo.com/faq.php?page=write_eeprom_not_byte

See this CCS driver file included with your compiler:
Quote:
c:\program files\picc\drivers\external_eeprom.c
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

Re: how to write int16 into eeprom?
PostPosted: Fri May 30, 2014 8:41 am     Reply with quote

webgiorgio wrote:
To my understanding of the manual write_eeprom (address, value) only accepts int8 as value.


Just a note. The basis for the 'only accepts int8 as value' is rooted in the fact that EEPROM memory is organized in 8 bit bytes in the PIC architecture. This is true at least for the PIC16 & PIC18 parts.

John
Ttelmah



Joined: 11 Mar 2010
Posts: 19559

View user's profile Send private message

PostPosted: Fri May 30, 2014 9:12 am     Reply with quote

As a slightly more general version, I use:
Code:

#define to_eeprom(address, val) write_eeprom_block(address, &val, sizeof(val))
#define from_eeprom(address,val) read_eeprom_block(address, &val,sizeof(val))

void write_eeprom_block(int16 address, int8 *data, int16 count)
{
   while (count--)
      write_eeprom(address++,*data++);
}

void read_eeprom_block(int16 address, int8 *data, int16 count)
{
   while (count--)
      *data++ = read_eeprom(address++);
}


//Then to use
    int16 fred;
    float dick;
    to_eeprom(0,fred); //writes fred to address 0 in the eeprom
    to_eeprom(16,dick); //writes dick to address 16

    from_eeprom(0,fred); //reads fred from address 0
    from_eeprom(16,dick); //reads dick from address 16


Obviously you can vary these to work with internal or external EEPROM, and the macros write/read any size variable - even structures etc..
You have to manage the addresses to use - I usually #define these.

Best Wishes
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