In the previous article, the program memory of the microcontroller was expanded, and the 4KB memory space was increased to 64KB. In fact, 4K's code space is still improvised, but the 51's own 256B data storage space is really tight, and 128MB is not available to users, so it has to expand the off-chip RAM. The expansion RAM method is similar to the expansion ROM in that it occupies the P0/P2 interface to do the address line. At the same time, P0 uses the latch 74373 to time-division multiplex the address and data signals.
In the past, RAM was expanded to use assembly language to access memory. The advantage was that the positioning was precise. The disadvantage was that a large program size was a bit difficult to maintain, so we had to use C instead.
Corresponds to the assembly language with R1, R0/DPTR to access the external RAM, keil C extends the storage type, increased as pdata (equivalent to movx @ Rn access mode) / xdata (equivalent to movx @ DPTR access mode) storage type for access Chip ram. At the same time, it also provides absolute address access macros, such as PBYTE/XBYTE, view definition:
[cpp] view plaincopy#define PBYTE((unsigned char volatile pdata*)0);
#define XBYTE((unsigned char volatile xdata*)0);
In fact, it is still a pointer to the corresponding storage type.
Before simulating graphs and code, clean up keil c to provide access to absolute addresses:
1._at_define the variable:
Variable type [Storage type] Variable name _at_ constant, the specified variable is stored in the ram position specified by the constant, attention bit type variable can not use _at_ specified position;
2. Absolute address access:
The header file absacc.h provides absolute address access macros for byte/word addressing, such as
Val=XBYTE[0x0000]; read the memory value at the chip ram 0x00
XBYTE[0x0200] = val; write memory value outside the chip ram 0x0200
Extended ram simulation diagram:
c language version:
Finally, look at the internal storage of the data after the program is running:
postscript:
Originally wanted to expand their own ram, but the ram chip is a high-speed signal, their layout will be saved, or play mud. . .
60V Battery Pack ,Battery Pack With Outlet,Back Up Battery Pack,Ev Battery Pack
Zhejiang Casnovo Materials Co., Ltd. , https://www.casnovonewenergy.com