We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi! I'm using XBANKING.a51 from "Keil\C51\Examples\FarMemory\3 XData Areas on T89C51RD2" for access to various types of memory MCU Atmel AT89C5131. I'm define memory model - Large, "User Classes" as: XDATA (X:0x008000-X:0x009FFE) // off-chip XRAM HDATA_EEPROM (X:0x020000-X:0x0207FF) // on-chip EEPROM HDATA (X:0x010000-X:0x0103FF) // on-chip XRAM And variables as: in file MAIN.c unsigned char *Pointer1, *Pointer2; unsigned char far onBufer; // on-chip XRAM unsigned char xdata offBufer; // off-chip XRAM unsigned code cBufer = "Welcome"; // on-chip ROM in file EEPROM.c #pragma USERCLASS (HDATA = EEPROM) unsigned char far EEBufer; // on-chip EEPROM I'm programming next code: Pointer1 = onBufer; // pointer to 0x01AABB Pointer2 = cBuffer; // pointer to 0xFFCCDD memcpy(Pointer1, Pointer2, 20); Compiling my program and view "Disassembly Window": ... Pointer1 = onBuffer; 908010 MOV DPTR,#Pointer1(0x8010) 7402 MOV A,#0x02 // on-chip EEPROM area !!! F0 MOVX @DPTR,A A3 INC DPTR 74AA MOV A,#0xAA F0 MOVX @DPTR,A A3 INC DPTR 74BB MOV A,#0xBB F0 MOVX @DPTR,A Pointer2 = cBuffer; A3 INC DPTR 74FF MOV A,#0xFF F0 MOVX @DPTR,A A3 INC DPTR 74CC MOV A,#0xCC F0 MOVX @DPTR,A A3 INC DPTR 74DD MOV A,#0xDD F0 MOVX @DPTR,A memcpy(Pointer1, Pointer2, 20); ... Where the bug or my error?
Excuse, this mistake has turned out at creation of a question: Should be: unsigned char far onBufer[20]; unsigned char xdata offBufer[20]; unsigned char far EEBufer[20]; Value of Pointer1 in "Hint" of Dedug windows is 0x01AABB. If R3 - memory type, then how to define simultaneously two types of far (EEPROM, on-chip XRAM). In function memcpy(Pointer1,Pointer1,20) disassembler check: C?CSTPTR: C:0x0DA0 BB0106 CJNE R3,#Test(0x01),C:0DA9 //if r3<>r1 is not HXDATA area C:0x0DA3 8982 MOV DP0L(0x82),R1 C:0x0DA5 8A83 MOV DP0H(0x83),R2 C:0x0DA7 F0 MOVX @DPTR,A C:0x0DA8 22 RET C:0x0DA9 5002 JNC C:0DAD C:0x0DAB F7 MOV @R1,A C:0x0DAC 22 RET C:0x0DAD BBFE02 CJNE R3,#CCAP4H(0xFE),C:0DB2 C:0x0DB0 F3 MOVX @R1,A C:0x0DB1 22 RET C:0x0DB2 50FD JNC C:0DB1 C:0x0DB4 020AD6 LJMP C?CSTXPTR(C:0AD6) // write to EEPROM or off-chip XRAM
Did you notice that the EEPROM variables are defined in a USER_CLASS.
#pragma ORDER // keep variables in order of definition #pragma USERCLASS (HDATA = EEPROM) // use HDATA_EEPROM for E2PROM area #define DECLARE #include <eeprom.h> // include all variables
OK, I have understood, it turns out, that memory and indexes are allocated as follows:
+----------------+--------------+------------------------+--------------+-----------+ | Memory Type | Memory Class | Define in C language | Address in C | R3 in ASM | +----------------+--------------+------------------------+--------------+-----------+ | on-chip XDATA | HDATA | far | X:0x010000 | 0x02 | | off-chip XDATA | XDATA | xdata | X:0x000000 | 0x01 | | CODE | CODE | code | X:0x0000 | 0xFF | | EEPROM | HDATA_EEPROM | far & (HDATA = EEPROM) | C:0x0000 | 0x03 | +----------------+--------------+------------------------+--------------+-----------+ * using standard files XBANKING.a51 and EEPROM.c
There is another problem. In the menu "Options for Target" I choose "Memory Model = Lage: variables in XDATA". I have function in my program char Test (char value1, char *value2, char value3) in which parameters transferred through XDATA memory, but not through registers. XDATA memory is an off-chip. How to transfer parameters through on-chip XRAM?
There is no particular reason why on-chip XDATA has to be HDATA, while off-chip is XDATA.
Presumably, you are looking at some specific case where this happened to be (or seem) convenient to whoever set it up?
I shall ask on another. I define variables as:
char xdata A; // locate in off-chip XDATA char far B; // locate in on-chip XDATA
If the model of memory LARGE and a variable is defined as char C; , then where is placed a variable? It is necessary for me that in on-chip XDATA.
"It is necessary for me that in on-chip XDATA."
If it is necessary, then just specify it explicitly. Simple.