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

How do I #locate a 2-D array

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



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

How do I #locate a 2-D array
PostPosted: Wed Nov 10, 2004 5:52 pm     Reply with quote

Compiler 3.212
16F877 @ 16MhZ
i want to #locate the different parts of a 2-d array.
can this be done?

Code:
int8 table[4][25];
#locate table[0]=0x110
#locate table[1]=0x129
#locate table[2]=0x190
#locate table[3]=0x1A9


so that each of the four is able to fit in the ram page.

Thanks in advace for any help.
tjr
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed Nov 10, 2004 5:59 pm     Reply with quote

No you can't break an array like that. And too be sure I tried it and the compiler returns an error.

One way to do this is to define 4 separate arrays, and then write wrapper functions (with two parameters) for accessing them.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 11, 2004 8:44 am     Reply with quote

I understand the 4 arrays. But how are the wrapper functions made. What are they suppose to do? Are they to FAKE out program, to make it look like i'm using a 2-d array?


Code:
int8 table0[24];
int8 table1[24];
int8 table2[24];
int8 table3[24];
// and #locate if need be.

FAKEOUT(param1,param2)
{
  //
  //
  //
}


I was thinking that with the 4 arrays, I could have an array of pointers to them. Then I could pass these to the function. Is that where you were going. In effect a 4 ellement array of pointers to 4 arrays.

THANKS FOR THE RESPONSE
tjr
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 11, 2004 12:40 pm     Reply with quote

Here is one example that I did in the past. It possibly could be
re-written in a more efficient way, but this example will give you
the main idea.
Code:

// bigarray.c
// This program shows how to make "wrapper" functions
// to allow access to an array larger than one ram bank.

//------------------------------------------------------
// INCLUDE FILES

#include "16F877.h"
#device *=16

//-------------------------------------------------------
// COMPILER AND CHIP CONFIGURATION DIRECTIVES

#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(Clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#zero_ram

//-------------------------------------------------------
// DEFINITIONS

#define ARRAY_1_SIZE  80
#define ARRAY_2_SIZE  80

#define TOTAL_ARRAY_SIZE (ARRAY_1_SIZE + ARRAY_2_SIZE)

//-------------------------------------------------------
// GLOBALS

char array_1[ARRAY_1_SIZE];
char array_2[ARRAY_2_SIZE];

//-------------------------------------------------------
// FUNCTION PROTOTYPES

char read_big_array(char index);
void write_big_array(char index, char value);


//================================
main()
{
char i;
char temp;

printf("Start test\n\r");

// To test the functions, we will fill the big array
// with numbers equal to the index.

for(i = 0; i < TOTAL_ARRAY_SIZE; i++)
   {
    write_big_array(i, i);
   }

//----------------------------
// Now read them back and check the results.

for(i = 0; i < TOTAL_ARRAY_SIZE; i++)
   {
    temp = read_big_array(i);

    if(temp != i)
       printf("Error:  Address %02x, Wrote %02x, Read %02x\n\r", i, i, temp);
   }

//----------------------------


printf("Test done");

while(1);
}

//=================================
// This function reads a byte from the specified index.

char read_big_array(char index)
{
char retval;

if(index < ARRAY_1_SIZE)   // Is index within 1st array ?
  {
   retval = array_1[index]; 
  }     
else if(index < TOTAL_ARRAY_SIZE)  // Is index within 2nd array ?
  {
   index -= ARRAY_1_SIZE;  // Then adjust index so it's within array 2.
   retval = array_2[index];
  }
else  // If not in either array, then return zero.  (We have to return something).
  {
   retval = 0;
  }

return(retval);
}

//------------------------------------------
// This function writes a byte to the specified index.

void write_big_array(char index, char value)
{

if(index >= TOTAL_ARRAY_SIZE)  // Don't allow writing outside of the array limits
   return;

if(index < ARRAY_1_SIZE)    // Is the index within array 1 ?
   {
   array_1[index] = value;
  }     
else         // If not, it must be within array 2. 
  {
   index -= ARRAY_1_SIZE;   // Adjust the index so it's within array 2.
   array_2[index] = value;
  }

}
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