hi i am trying to write an array with 4 elements each holding an int16 value to a 24lc256. i have managed to get the eeprom connected to the pic 16f877 and am able to write and read an int value using the ccs 24256.c driver. can anyone point me in the right direction to solving this problem as i am a bit stuck.
many thanks for any help given
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
Posted: Sat Mar 04, 2006 2:44 pm
Think about your array as being 8 int8's. That's nothing more than 8 single byte writes.
King Virus
Joined: 02 Mar 2006 Posts: 14 Location: Italy
Posted: Sun Mar 05, 2006 3:38 am
Mark wrote:
Think about your array as being 8 int8's. That's nothing more than 8 single byte writes.
If you really need int16 then you should work with shifting...
Let me explain:
Code:
Write_Ext_Eeprom(5, h>>8); // Write 1. Byte of variable "h"(declared as long or int16) to EEPROM position 5
Write_Ext_Eeprom(6, h); // Write 2. Byte of variable "h"(declared as long or int16) to EEPROM position 6
As you can see, the first instruction will shift the MSB of "h" to the LSB of "h":
Letīs suppose that the value of "h" is:
Code:
MSB LSB
h = 10101010 00000000
then it will be after shifting (h>>8):
Code:
MSB LSB
h = 00000000 10101010
Now the write instruction (it is a 8bit write instruction) will handle yust the LSB of "h". So if you write it now into the EEPROM yust the LSB will be saved !
Thats all ! Now YOU have to combine it with some other code to handle 4 variables of type int16 ! _________________ *** A good forum is a forum where people respect eatch other ! ***
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Sun Mar 05, 2006 5:57 pm
Quote:
I am trying to write an array with 4 elements each holding an int16 value
to a 24lc256. Can anyone point me in the right direction to solving this
problem as I am a bit stuck.
Also look at the make8() function in the CCS manual. It provides an
easy way to extract the desired byte from an int16 or int32 variable.
It's provided for this purpose.
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