Problem: -------- All I am doing here is that msg1 table is initialized and trying to print this info out to see if I am able to access ERAM properly. I am serring 'Use on-Chip ROM' and 'USE on-chip XRAM" (large model). Also I am enabling the on-chip XRAM by clearing bit 1 in the AUXR SFR (AUXR = 0x1). I cannot see what I am doing wrong here. Any pointers on this will be highly appreciated. Thanks, Venkat Program: -------- #include <REG66x.H> /* for the intended 8051 derivative */ #include <stdio.h> /* prototype declarations for I/O functions */ #include <stdlib.h> #include <string.h> #include <math.h> sfr SBUF = 0x99; char xdata helloMsg[] = "Hello World"; char xdata xdata_buffer[32]; int xdata num_data[32]; char xdata msg1[64] = { 0 , 0xfe, 0x10, 0x10, 0x10, 0xfe, 0, 0xfc, 0x12, 0x12, 0x12, 0xfc, 0, 0xfe, 0x08, 0x10, 0x20, 0xfe, 0, 0x02, 0x02, 0xfe, 0x02, 0x02, 0, 0xfe, 0x12, 0x32, 0x52, 0x8c, 0, 0x7c, 0x82, 0x82, 0x82, 0x7c, 0, 0xfe, 0x08, 0x10, 0x20, 0xfe, 0, 0x0 , 0x0 , 0x82, 0xfe, 0x82, 0, 0 , 0xc6, 0x28, 0x10, 0x28, 0xc6, 0, 0 , 0x38, 0x7c, 0xf8, 0x7c, 0x38, 0, 0 }; char myputchar (char c) { while (!TI); TI = 0; return (SBUF = c); } void main (void) { int ix, j; char c; /* serial port properties */ RCLK = 1; TCLK = 1; S0CON = 0x50; /* timer 2 properties */ RCAP2L = 0xF6; RCAP2H = 0xFF; TR2 =1; /* Timer 0 & 1 properties */ TH0 = 0; TL0 = 0; TMOD = 1; /* Enable interrupts */ ES0 = 1; EA = 1; TR0 = 1; AUXR = 0x1; TI = 1; printf ("\n ...........\n"); printf ("....hm[%d]=%s....\n", strlen(helloMsg), helloMsg); memcpy (xdata_buffer, "XDATA Buffer", sizeof (xdata_buffer)); printf("....Xdata[%d]=%s.... \n", strlen(xdata_buffer), xdata_buffer); j = 0; for (ix = 0; ix < 32; ix++) { printf ("%x ", msg1[ix]); j++; if ( j == 16 ) { printf("\n"); j = 0; } } while (1); } Output ------ The integer array output is garbage. ........... ....hm[11]=Hello World.... ....Xdata[12]=XDATA Buffer.... 730f 2e0f 2e0f 2e0f f 310f f 320f f 330f f 340f f 350f f 360f f 370f f 380f f 390f f 3a0f f 3b0f f 3c0f f 3d0f f 3e0f
The problem is that you enable the AUX ram in the main function. XDATA is initialized as part of the startup process -- before the main C function is called. So, enabling the AUX RAM in main is pointless if you have initialized variables (which you do). That's why msg1 contains garbage. Follow the directions in this knowledgebase article: http://www.keil.com/support/docs/1978.htm Jon
Jon, many thanks for pointing out to web page http://www.keil.com/support/docs/1978.htm. I did try this also earlier in trying to resolve this problem. I am not sure that I have the startup.a51 setup correctly. With the startup.a51 copiled into (please see below), I get scrolling blank lines. If possible, can you take a look at the startup.a51 file? I appreciate your response. The only changes to Keil's original startup.a51 file are: XDATASTART EQU 0H ; the absolute start-address of XDATA memory XDATALEN EQU 0300H ; the length of XDATA memory in bytes. and under startup1 label: ; enable on-chip xdata RAM ANL AUXR1,#NOT 02H ; AUXR1/Bit 1 (clear to 0 to enable on-chip XRAM) File appended for completness of my description Startup.a51 ---------------------------------------- $NOMOD51 ;------------------------------------------------------------------------------ ; This file is part of the C51 Compiler package ; Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc. ;------------------------------------------------------------------------------ ; STARTUP.A51: This code is executed after processor reset. ; ; To translate this file use A51 with the following invocation: ; ; A51 STARTUP.A51 ; ; To link the modified STARTUP.OBJ file to your application use the following ; BL51 invocation: ; ; BL51 <your object file list>, STARTUP.OBJ <controls> ; ;------------------------------------------------------------------------------ ; ; 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 0300H ; 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. ; ; Notes: The IDATA space overlaps physically 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. ;------------------------------------------------------------------------------ ; ; Reentrant Stack Initilization ; ; The following EQU statements define the stack pointer for reentrant ; functions and initialized it: ; ; Stack Space for reentrant functions in the SMALL model. IBPSTACK EQU 0 ; set to 1 if small reentrant is used. IBPSTACKTOP EQU 0FFH+1 ; set top of stack to highest location+1. ; ; Stack Space for reentrant functions in the LARGE model. XBPSTACK EQU 0 ; set to 1 if large reentrant is used. XBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1. ; ; Stack Space for reentrant functions in the COMPACT model. PBPSTACK EQU 0 ; set to 1 if compact reentrant is used. PBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1. ; ;------------------------------------------------------------------------------ ; ; Page Definition for Using the Compact Model with 64 KByte xdata RAM ; ; The following EQU statements define the xdata page used for pdata ; variables. The EQU PPAGE must conform with the PPAGE control used ; in the linker invocation. ; PPAGEENABLE EQU 0 ; set to 1 if pdata object are used. ; PPAGE EQU 0 ; define PPAGE number. ; PPAGE_SFR DATA 0A0H ; SFR that supplies uppermost address byte ; (most 8051 variants use P2 as uppermost address byte) ; ;------------------------------------------------------------------------------ ; Standard SFR Symbols ACC DATA 0E0H B DATA 0F0H SP DATA 81H DPL DATA 82H DPH DATA 83H AUXR1 DATA 08EH NAME ?C_STARTUP ?C_C51STARTUP SEGMENT CODE ?STACK SEGMENT IDATA RSEG ?STACK DS 1 EXTRN CODE (?C_START) PUBLIC ?C_STARTUP CSEG AT 0 ?C_STARTUP: LJMP STARTUP1 RSEG ?C_C51STARTUP STARTUP1: ; enable on-chip xdata RAM ANL AUXR1,#NOT 02H ; AUXR1/Bit 1 (clear to 0 to enable on-chip XRAM) IF IDATALEN <> 0 MOV R0,#IDATALEN - 1 CLR A IDATALOOP: MOV @R0,A DJNZ R0,IDATALOOP ENDIF 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 IF PPAGEENABLE <> 0 MOV PPAGE_SFR,#PPAGE ENDIF IF PDATALEN <> 0 MOV R0,#LOW (PDATASTART) MOV R7,#LOW (PDATALEN) CLR A PDATALOOP: MOVX @R0,A INC R0 DJNZ R7,PDATALOOP ENDIF IF IBPSTACK <> 0 EXTRN DATA (?C_IBP) MOV ?C_IBP,#LOW IBPSTACKTOP ENDIF IF XBPSTACK <> 0 EXTRN DATA (?C_XBP) MOV ?C_XBP,#HIGH XBPSTACKTOP MOV ?C_XBP+1,#LOW XBPSTACKTOP ENDIF IF PBPSTACK <> 0 EXTRN DATA (?C_PBP) MOV ?C_PBP,#LOW PBPSTACKTOP ENDIF MOV SP,#?STACK-1 ; This code is required if you use L51_BANK.A51 with Banking Mode 4 ; EXTRN CODE (?B_SWITCH0) ; CALL ?B_SWITCH0 ; init bank mechanism to code bank 0 LJMP ?C_START END
The STARTUP code looks OK to me. Since the 662 only has 768 bytes of on-chip XDATA, you should FIRST check that your program uses no more than 768 bytes of XDATA. If it does, that may be the problem. Look in the map file to see where the table is located and verify that you REALLY have memory there. Have you tried running the program in the simulator? Jon
Jon, I truly appreciate your fast reponse. Yes, I verified that data reference is within 768 bytes of XDATA. I also tried to define 769 bytes and the complier complains it. Works fine with Simulator. I am hooking up emulator to see what is happening. I also casted the data via the following command printf ("%bd ", (char) msg1[ix]); No luck yet in resolving this problem. Thanks, Venkat