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

read/write int16 value in eeprom

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



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

read/write int16 value in eeprom
PostPosted: Fri Dec 11, 2009 11:34 pm     Reply with quote

Hi,
I want to read/write int16 value in/from eeprom.
int16 takes two bytes.
Can I read/write in the same way as we treat floating numbers or is there another way ?
For example:
Code:

void  write_on_time(long int on=0,int16 high_time);//write function
int16 read_on_time(long int on=0);//read function

int16 high_time=456;//value to be write,this values also be entered from keypad
int16 ee_high_time;
int on=0;//location in eeprom

void main()
{
 ....
 write_on_time(on,high_time);//write
 ....
 ....
 ee_high_time=read_on_time(on);//read
 ....
}


void write_on_time(long int on=0,int16 high_time)
{
 int j;
 for(j=0;j<2;j++)
 write_eeprom(j+on,*(&high_time+j));
}

int16 read_on_time (long int on=0)
{
 int i;
 int16 high_time;
 for(i=0;i<2;i++)
  *(&high_time+i)=read_eeprom(i+on);
  return(high_time);
}

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Dec 12, 2009 12:14 am     Reply with quote

Look in the following CCS driver file:
Quote:
c:\program files\picc\drivers\internal_eeprom.c


It has these two functions to read/write an 'int16' to internal eeprom:
Code:

write_int16_eeprom()
read_int16_eeprom()


Look in this file. It shows how to call them.
Quote:
c:\program files\picc\drivers\compass.c
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

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

PostPosted: Sat Dec 12, 2009 12:15 am     Reply with quote

you can try these:

by using a macro instead of a function, we can eliminate the int8 or int16 defines for address

Code:

// a few internal eeprom macro wrappers

#define mReadByte(addr)         read_eeprom(addr)
#define mWriteByte(addr,data)   write_eeprom(addr,data)


// little endian
#define mReadWord(addr)         make16( read_eeprom(addr + 1), read_eeprom(addr) )
#define mWriteWord(addr, data)  { write_eeprom(addr, make8(data,0) ); write_eeprom(addr + 1, make8(data,1) };

_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
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