| |||||
Technical Support Support Resources
Product Information | C51: BATTERY-BACKED NON-VOLATILE MEMORYQUESTIONI 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? ANSWERStoring 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
.
.
.
FORUM THREADSThe following Discussion Forum threads may provide information related to this topic. Last Reviewed: Monday, May 24, 2004 | ||||
| |||||