ARM Technical Support Knowledge Articles

BATTERY-BACKED NON-VOLATILE MEMORY

Applies to: C51 C Compiler

Answer

QUESTION

I am using battery-RAM and need to declare a global array, but I do'nt want this RAM to be cleared to 0 each time I turn the equipment on because I use this RAM to save data collected during the day. How can I declare a "non-volatile" array?

ANSWER

Storing variables in battery-backed (non-volatile) XDATA is easy.

1. Declare the array (or variable) so that it resides in XDATA. 2. Locate the variable at a specific location. You may either use the linker controls or you may use the _at_ keyword in the compiler. 3. Modify the startup code constants (in STARTUP.A51) so that startup doesn't zero that memory area. The startup code appears as follows:

.
.
.
;------------------------------------------------------------------------------
;
;  User-defined Power-On Initialization of Memory
;
;  With the following EQU statements, the initialization of memory
;  at processor reset can be defined:
;
;               ; the absolute start-address of IDATA memory is always 0
IDATALEN        EQU     80H     ; the length of IDATA memory in bytes.
;
XDATASTART      EQU     0H      ; the absolute start-address of XDATA memory
XDATALEN        EQU     0H      ; the length of XDATA memory in bytes.
;
PDATASTART      EQU     0H      ; the absolute start-address of PDATA memory
PDATALEN        EQU     0H      ; the length of PDATA memory in bytes.
;
;  Note:  The IDATA space physically overlaps the DATA and BIT areas of the
;          8051 CPU. At minimum, the memory space occupied from the C51
;          run-time routines must be set to zero.
;------------------------------------------------------------------------------
.
.
.

You may also need to change the XDATA memory clearing code in the startup code as well.

.
.
.
IF XDATALEN <> 0
                MOV     DPTR,#XDATASTART
                MOV     R7,#LOW (XDATALEN)
  IF (LOW (XDATALEN)) <> 0
                MOV     R6,#(HIGH XDATALEN) +1
  ELSE
                MOV     R6,#HIGH (XDATALEN)
  ENDIF
                CLR     A
XDATALOOP:      MOVX    @DPTR,A
                INC     DPTR
                DJNZ    R7,XDATALOOP
                DJNZ    R6,XDATALOOP
ENDIF
.
.
.

Article last edited on: 2004-05-24 21:21:26

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