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

write and read eeprom using long int

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



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

write and read eeprom using long int
PostPosted: Sat Mar 11, 2017 4:54 pm     Reply with quote

The best way to write and read int32 data eeprom using pic16F.

example:
Code:

int32 x;

x = 9999;

need save pic eeprom x.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Mar 11, 2017 5:21 pm     Reply with quote

use the CCS supplied functions if appicable..
jpts



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

PostPosted: Sat Mar 11, 2017 5:32 pm     Reply with quote

Functions read_eeprom() and write_eeprom() only works int8...there is other?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 11, 2017 6:41 pm     Reply with quote

Look in the CCS drivers directory for this file:
Quote:

internal_eeprom.c

Also there is another file, external_eeprom.c, that is similar.
It is for 24LC32, etc.

How to use it:
Code:

#include <16F887.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)

#include <internal_eeprom.c>  // Include the file here

//=====================================
void main(void)
{

// Then use any of the functions from internal_eeprom.c here.


while(TRUE);
}
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Sat Mar 11, 2017 6:42 pm     Reply with quote

You will most likely need to do it in a two-step process:

int32 x;
x = 9999;

Your value in decimal is 9999 therefore 270F in hexadecimal.

Isolate both halves:

unsigned int8 HiByte = ( x & 0xFF00 ) >> 8;

The result above will be HiByte = 0x27.

unsigned int8 LoByte = (x & 0x00FF );

The result above will be LoByte = 0x0F.

Then write both bytes to the EEPROM:

write_eeprom( ADDRESS_HIGH, HiByte );
write_eeprom( ADDRESS_LOW, LoByte );



I think that's probably as simple as it can be.... unless I'm wrong or someone has an simpler way.

Benoit
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 11, 2017 7:20 pm     Reply with quote

Yes, there is a simpler way. Call the function in internal_eeprom.c:
Code:
#include <internal_eeprom.c>

void main(void)
{
int8 address;
int32 data;

address = 0x00;      // Start of data eeprom
data = 0x12345678;   // 32-bit value to write

write_int32_eeprom(address, data);

while(TRUE);
}
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