1. The keyword _at_ in the microcontroller: defines the storage address of the variable.
2. What does this procedure mean?
- #define XBYTE((char*)0x20000L)
- XBYTE[0x8000]=0x41;
define XBYTE ((char*)0x20000L) defines XBYTE as a character pointer (or array) variable pointing to address 0x0000L XBYTE[0x8000]=0x41; assigns the value of 0x8000 in the array XBYTE to 0x41. That is, the memory unit at address 0x8000L is assigned 0x41. This means that you are using a 51 chip with an external data bus. The external memory is mostly RAM, and the capacity of RAM is at least 0x8000 (32k) bytes. The capacity of RAM may be 64k bytes? L stands for long, which means that 0x20000L is a long integer. Generally speaking, for 8-bit microcontrollers such as 51, integers are represented by 16-bit binary and long integers are represented by 32-bit binary. The 2 in 0x20000L is the memory type xdata, not part of the address.
3.51 MCU storage type:
data--->addressable on-chip ram
bdata--->bit-addressable on-chip ram
idata--->addressable on-chip ram, allowing access to all internal ram
pdata--->paged addressable off-chip ram (MOVX @R0) (256 BYTE/page)
xdata--->addressable off-chip ram (64k address range)
code--->program storage area (64k address range), corresponding to MOVC @DPTR
4.absacc.h
- /*------------------------------------------------ --------------------------
- ABSACC.H
- Direct access to 8051, extended 8051 and Philips 80C51MX memory areas.
- Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
- All rights reserved.
- -------------------------------------------------- --------------------------*/
- #ifndef __ABSACC_H__
- #define __ABSACC_H__
- #define CBYTE ((unsigned char volatile code *) 0)
- #define DBYTE ((unsigned char volatile data *) 0)
- #define PBYTE ((unsigned char volatile pdata *) 0)
- #define XBYTE ((unsigned char volatile xdata *) 0)
- #define CWORD ((unsigned int volatile code *) 0)
- #define DWORD ((unsigned int volatile data *) 0)
- #define PWORD ((unsigned int volatile pdata *) 0)
- #define XWORD ((unsigned int volatile xdata *) 0)
- #ifdef __CX51__
- #define FVAR(object, addr) (*((object volatile far *) (addr)))
- #define FARRAY(object, base) ((object volatile far *) (base))
- #define FCVAR(object, addr) (*((object const far *) (addr)))
- #define FCARRAY(object, base) ((object const far *) (base))
- #else
- #define FVAR(object, addr) (*((object volatile far *) ((addr)+0x10000L)))
- #define FCVAR(object, addr) (*((object const far *) ((addr)+0x810000L)))
- #define FARRAY(object, base) ((object volatile far *) ((base)+0x10000L))
- #define FCARRAY(object, base) ((object const far *) ((base)+0x810000L))
- #endif
- #endif
For example:
rval = CBYTE [0x0002]; points to the address 0002h of the program memory
rval = XWORD [0x0002]; points to the address 0004h of the external RAM // WORD is a word, two bytes, so it is 0004h
#define COM8255 XBYTE[0X060FF] //If COM8255 appears later, the MCU ports P0 and P2 will jointly output the absolute physical address of 0X060FF (the address points to the 82C55 instruction register)
#define PA8255 XBYTE[0X000FF] //If PA8255 appears later, the MCU ports P0 and P2 will jointly output the absolute physical address of 0X000FF (the address points to the 82C55 group A port register)
#define PB8255 XBYTE[0X020FF] //If PB8255 appears later, the MCU ports P0 and P2 will jointly output the absolute physical address of 0X020FF (the address points to the 82C55 group B port register)
#define PC8255 XBYTE[0X040FF] //If PC8255 appears later, the MCU ports P0 and P2 will jointly output the absolute physical address 0X040FF (the address points to the C group port register of 82C55)
4. Routine to drive external RAM
- /****************************************************** *************************
- *Program name: 51 MCU external expansion RAM test
- *Program function: write data to the external RAM, read data from the external RAM, and light up the 8 LEDs of port P1
- * Development tools: WSF-51DB development board
- * MCU model: AT89S52-24PU
- *Clock frequency: 12MHZ
- *Program author: Master Wu
- *Copyright statement: All rights reserved by Master Wu. Please indicate the source address and author when reprinting.
- *************************************************** ************************/
- #include
- #include
//Contains the absolute address access function of the off-chip storage space: XBYTE[] - sbit oe=P2^7; //External RAM chip select and address latch 74HC573 enable
- unsigned char code ramdata[100]= //define 100 data
- {
- 0,1,2,3,4,5,6,7,8,9,
- 10,11,12,13,14,15,16,17,18,19,
- 20,21,22,23,24,25,26,27,28,29,
- 30,31,32,33,34,35,36,37,38,39,
- 40,41,42,43,44,45,46,47,48,49,
- 50,51,52,53,54,55,56,57,58,59,
- 60,61,62,63,64,65,66,67,68,69,
- 70,71,72,73,74,75,76,77,78,79,
- 80,81,82,83,84,85,86,87,88,89,
- 90,91,92,93,94,95,96,97,98,99
- };
- //Delay ms function:
- void Delayms(unsigned int t)
- {
- unsigned int i,j;
- for(i=t;i>0;i--)
- for(j=120;j>0;j--);
- }
- //Main function:
- int main(void)
- {
- unsigned char i;
- oe=0; //Enable RAM chip select and address latch
- for(i=0;i<100;i++)
- XBYTE[300+i]=ramdata[i];
- //Write 100 data into the off-chip RAM, starting at address: 300
- while(1)
- {
- for(i=0;i<100;i++)
- {
- P1=XBYTE[300+i]; //Read data from the off-chip RAM and light up the 8 LEDs of port P1
- Delayms(500);
- }
- }
- return 0;
- }
Previous article:51 MCU simultaneous external expansion of RAM, ROM specific implementation and Keil specific settings
Next article:51 MCU resource expansion: jump from on-chip ROM to off-chip ROM
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- CC400 chip
- Sugar Glider Part 7: Software Design of the Exercise Reward System for Sugar Glider Based on RSL10
- X-NUCLEO-IKS01A3 Official Technical Data
- AT32F425-Evaluation Report-Serial Port and Waveform Display Host Computer Debugging-09
- There is a car image simulation project for paid consultation, using the Freescale solution
- Take a look at the USB Host microcontroller in gaming peripherals
- What is the component B93 on the circuit board?
- Looking for part-time embedded software engineer job
- Award-winning live broadcast: In-depth analysis of TI's latest C2000 real-time controller to solve the pain points of multi-MCU real-time power supply projects
- Use of 2.4G wireless communication module NRF24L01 on Cortex M