View previous topic :: View next topic |
Author |
Message |
karthickiw
Joined: 09 Aug 2007 Posts: 82 Location: TN, India
|
how to store int16 value into the internal eeprom |
Posted: Sun Aug 19, 2007 10:42 am |
|
|
hai,
how store int16 value into the internal eeprom, please give sample code. |
|
|
valemike Guest
|
write an int16 |
Posted: Sun Aug 19, 2007 1:31 pm |
|
|
This is the code i've been using on a two year old program. I derived it from the FAQ, where they show an example using a float. But now that I look at it, perhaps i shouldn't be using "long int n"??? Maybe i should use int16 or unsigned long. Then again, isn't a long int also 16 bits?? who knows.
Code: |
unsigned long READ_LONG_INT_EEPROM(long int n)
{
int i;
long int data;
for (i = 0; i < 2; i++)
*(&data + i) = read_eeprom(i + n);
return(data);
}
void WRITE_LONG_INT_EEPROM(long int n, long int data)
{
int i;
restart_wdt();
for (i = 0; i < 2; i++)
{
write_eeprom(i + n, *(&data + i) ) ;
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 19, 2007 1:43 pm |
|
|
That FAQ article has been updated. Starting with vs. 4.021, pointer
arithmetic doesn't assume pointers are byte pointers.
From the CCS versions page:
Quote: | 4.021 The & unary operator by default no longer returns a generic (int8 *) |
In the revised FAQ article, notice how they cast the float pointer to an
int8 pointer, when they want to step through each of the 4 bytes in the
float:
http://www.ccsinfo.com/faq.php?page=write_eeprom_not_byte |
|
|
karthickiw
Joined: 09 Aug 2007 Posts: 82 Location: TN, India
|
about eeprom |
Posted: Mon Aug 20, 2007 10:29 am |
|
|
sir,
what is default value of internal eeprom. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 20, 2007 11:40 am |
|
|
When a new chip is received from the Microchip factory, the internal
eeprom value should be 0xFF. But I don't think they guarantee it.
You can make sure that it's set to 0xFF by selecting "Erase Part" from
the Programmer menu. This option is available in the Programmer
menu in MPLAB with the ICD2 programmer. I'm sure the CCS IDE
has a similar menu option. |
|
|
|