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 support@ccsinfo.com

Help! two dimensions Array

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







Help! two dimensions Array
PostPosted: Mon Apr 26, 2004 1:05 am     Reply with quote

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
PostPosted: Mon Apr 26, 2004 1:59 am     Reply with quote

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
PostPosted: Mon Apr 26, 2004 4:24 pm     Reply with quote

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]);
   }


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