View previous topic :: View next topic |
Author |
Message |
jpts
Joined: 08 Mar 2017 Posts: 40
|
write and read eeprom using long int |
Posted: Sat Mar 11, 2017 4:54 pm |
|
|
The best way to write and read int32 data eeprom using pic16F.
example:
need save pic eeprom x. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Mar 11, 2017 5:21 pm |
|
|
use the CCS supplied functions if appicable.. |
|
|
jpts
Joined: 08 Mar 2017 Posts: 40
|
|
Posted: Sat Mar 11, 2017 5:32 pm |
|
|
Functions read_eeprom() and write_eeprom() only works int8...there is other? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 11, 2017 6:41 pm |
|
|
Look in the CCS drivers directory for this file:
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
|
|
Posted: Sat Mar 11, 2017 6:42 pm |
|
|
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
|
|
Posted: Sat Mar 11, 2017 7:20 pm |
|
|
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);
} |
|
|
|
|