|
|
View previous topic :: View next topic |
Author |
Message |
Mk Guest
|
Help! two dimensions Array |
Posted: Mon Apr 26, 2004 1:05 am |
|
|
hi! i need help on a two dimensions Array, i am trying to write some data into an eeprom(24lc256) and read the data out, i am using a pic16f877a. i am still new to pic, i tried to search all the possible info from the discussion board for all this weekend, but they were too advance to me, so can someone help me on this problem?
here is a sample code:
int i,j;
const char record[2][7]={"abcdef","123456"}; if i put 1234567 then i got error message "string too long", next problem is:
for (i=0; i<=2; ++i)
{
write_ext_eeprom(?,????) <--- i got stuck here don't know how, because according to write_ext_eeprom only can have one address one byte data, but i have 7 bytes data???? for one address, how can i solve this problem?? help!
}
thank you! |
|
|
Ttelmah Guest
|
Re: Help! two dimensions Array |
Posted: Mon Apr 26, 2004 1:59 am |
|
|
Mk wrote: | hi! i need help on a two dimensions Array, i am trying to write some data into an eeprom(24lc256) and read the data out, i am using a pic16f877a. i am still new to pic, i tried to search all the possible info from the discussion board for all this weekend, but they were too advance to me, so can someone help me on this problem?
here is a sample code:
int i,j;
const char record[2][7]={"abcdef","123456"}; if i put 1234567 then i got error message "string too long", next problem is:
for (i=0; i<=2; ++i)
{
write_ext_eeprom(?,????) <--- i got stuck here don't know how, because according to write_ext_eeprom only can have one address one byte data, but i have 7 bytes data???? for one address, how can i solve this problem?? help!
}
thank you! |
First part, is a general 'C' question. In C, strings have a _null terminator character_. Hence the string "1234567", is actually _eight_ characters long. Hence the 'string too long' message.
Second part. Data in arrays is stored sequentially in memory. So you can use:
Code: |
//Beware here. A loop from 0 to <=2, loops three times.
for (i=0; i<2; ++i)
{
for (c=0;c<7;c++) write_ext_eeprom(i*7+c,record[i][c]);
}
|
Best Wishes |
|
|
Mk Guest
|
Re: Help! two dimensions Array |
Posted: Mon Apr 26, 2004 4:24 pm |
|
|
Hi! Ttelmah,
thanks for the help, i have a question on the address of the write_ext_eeprom (i*7+c,record[i][c]); ( i*7 + C) , so i have to use the upper 4 bits of the address, am i right? if i am right, what are those lower 4 bits for?
thanks!
Quote: |
Second part. Data in arrays is stored sequentially in memory. So you can use:
Code: |
//Beware here. A loop from 0 to <=2, loops three times.
for (i=0; i<2; ++i)
{
for (c=0;c<7;c++) write_ext_eeprom(i*7+c,record[i][c]);
}
|
|
|
|
|
|
|
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
|