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

EEPROM difficulties -18F452 CCS ICD & 3.177

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



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sat Sep 20, 2003 5:34 pm     Reply with quote

See below:

Code:

int address;
long number, finally;
byte topbyte, botbyte, topback, botback;
number = 2280;
// No need and with 0xFF since botbyte ins 8 bits
//botbyte = number & 0xFF;
botbyte = number;
topbyte = number >> 8;
address = 0;
write_eeprom(1l, topbyte);
write_eeprom(2l, botbyte);
address = 1;
topback = read_eeprom(1); // or 0
botback = read_eeprom(2); // or 1

// This is incorrect since topbyte is 8 bits multiplying by 256 will result in 0
//finally = (topback * 256) + botback;
finally = make16(topback, botback);



Here's how I would do it:

Code:

long address;
long number;
  union
  {
    struct
    {
      UINT8 lowbyte;
      UINT8 highbyte;
    };
    UINT16 word;
  }data;

number = 2280;
address = 0;
write_eeprom(address, number>>8);
write_eeprom(address+1, number);

// now to test
data.lowbyte = read_eeprom(address);
data.highbyte = read_eeprom(address+1);
// data.word contain the 16 bit number
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