ARM Technical Support Knowledge Articles

OFFSETS WITH FAR MEMORY ACCESS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

I need to manage an EEPROM on an Atmel device and I am using the 'far' memory type as explained in KeilC51EXAMPLESFarMemoryE2PROM on 80C51RD2. Within the EEPROM, I store offsets to other elements using WORD variables. However, when I try to access these objects, the code fails.

My access code looks like:

unsigned int far offset;    // an offset in EEPROM that points to other elements
unsigned char far *p, c;
  :
  p = (unsigned char far *) offset;
  c = *p;                        // this access fails

It seems to be impossible to access EEPROM space by just using an offset. Do you have a solution to that problem?

ANSWER

Yes, there is a solution. You can use the FARRAY macros to define an EEPROM memory. The following example shows you how to do that.

#include <absacc.h>

unsigned int far i[3];

unsigned char far *p;
unsigned char uc;

// macro that allows easy EEPROM access
#define EEPROM FARRAY (unsigned char, 0x20000)

void test (void)  {
// construct without macro
  p = (unsigned char far *) &(FARRAY (unsigned char, 0x20000)[i[0]]);

// using macros
  p  = &EEPROM [5];
  uc =  EEPROM [i[3]];
  p  = &EEPROM [uc];
}

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-07-15 10:02:28

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential