Technical Support

C51: CONSTANT ARRAYS LARGER THAN 64KB


Information in this article applies to:

  • C51 Version 7 or higher

QUESTION

I want to create a constant array larger than 64KB using the following construct:

#pragma ROM(D512K)

unsigned char const far array[] = {
 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,
  :
}

Since the data is more than 64KB, I receive the error message:

*** ERROR C249: 'array': ALLOCATION EXCEEDS 64K

Is there a way to create a constant array larger than 64KB?

ANSWER

Yes. You may use an assembly program to define such an large array. Your example would translate into:

PUBLIC array

?HC?ARRAY SEGMENT HCONST
RSEG ?HC?ARRAY
array:
DB  1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
  :

END

The AX51 assembler has no limitations on the size of an array.

In C51 you may address this array as shown below:

#pragma ROM(D512K)

extern unsigned char const far array[];

unsigned char test (long l)  {
  unsigned char c;

  c = array[l];
  return c;
}

Note that the array index l is defined as unsigned long to allow 24-bit address arithmetic.

MORE INFORMATION

  • Refer to far in the Cx51 User's Guide.

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Monday, October 10, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure