1. Variables or arrays without initial values
Simply use the _at_ keyword plus the address.
like:
unsigned char idata myvar _at_ 0x40;
unsigned char code myvar[10] _at_ 0x40;
There are spaces before and after the _at_ keyword.
2. Variables or arrays with initial values
To locate a variable at an absolute position and assign an initial value, you cannot use _at_ to complete the task. You need to do the following:
1. Create a new file in the project, such as InitVars.c, and assign initial values to the variables to be processed (assuming it is code variables):
char code myVer = {"COPYRIGHT 2001-11"};
2. Then add the file to the project, compile, open the M51 file, if the definition is code type, then
* * * C O D E M E M O R Y * * *
You can find below:
CODE xxxxH xxxxH UNIT ?CO?INITVARS
Then in:
Project->Options for Target ...->BL51 Locate:Code
Fill in:
?CO?INITVARS(0x200)
Just compile again.
1. Correspondingly, if it is an xdata variable, write in InitVars.c:
char xdata myVer = {"COPYRIGHT 2001-11"};
Then add the file to the project, compile, open the M51 file, and
* * * X D A T A M E M O R Y * * *
You can find below:
XDATA xxxxH xxxxH UNIT ?XD?INITVARS
Then in:
Project->Options for Target ...->BL51 Locate:Xdata
Fill in:
?XD?INITVARS(0x200)
Compile again. Correspondingly, if the variables such as data/idata are defined, just handle them accordingly.
3. Function Positioning
If you want to C source file tools.c function
int BIN2HEX(int xx)
{
...
}
Place it at 0x1000 of CODE MEMORY, compile the project first, then open the M51 file of the project,
* * * C O D E M E M O R Y * * *
Find the name of the function to be located under the line, which should be like:
CODE xxxxH xxxxH UNIT ?PR?_BCD2HEX?TOOLS
Then in:
Project->Options for Target ...->BL51 Locate:Code
Fill in the following information:
?PR?_BCD2HEX?TOOLS(0x1000)
Build again, and you will find that the function has been placed at 0x1000 in CODE MEMORY in M51.
If you want to locate multiple functions at the same time, just separate them with ",":
?PR?myTest1?MAIN(0x3900), ?PR?myTest2?MAIN(0x4000)
4. Calling method when you know the function address but not the function name (using function pointer to call the function at the absolute address)
1. Define the prototype of the function to be called
typedef void (*CALL_MYTEST)(void);
This is a prototype of a callback function, the parameter is empty.
2. Define the corresponding function pointer variable
CALL_MYTEST myTestCall = NULL;
3. Function pointer variable assignment, pointing to the function at the absolute address we locate
myTestCall = 0x3900;
4. Function pointer call
if (myTestCall != NULL)
{
myTestCall(); // Call the function myTest1 at the function pointer, set the PC pointer to 0x3900
}
Previous article:Memory Unit and Bit Address in C51
Next article:Where are the working registers R0~R7 of the 51 MCU located in the internal RAM?
Recommended ReadingLatest update time:2024-11-16 21:50
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
- Single chip microcomputer control technology (Li Shuping, Wang Yan, Zhu Yu, Zhang Xiaoyun)
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!
- 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
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [CB5654 Intelligent Voice Development Board Review] Hardware Review
- FPGA Implementation of Floating-Point LMS Algorithm
- Selection of aluminum electrolytic capacitors
- EEWORLD University Hall ---- FanySkill Installation Instructions For Allegro 16.617.2 Version
- Yibite provides Bluetooth, 4G DTU, WiFi, lora and other modules for free. Come and play if you want to!
- [GD32L233C-START Review] 3. Software GPIO simulation + hardware SPI drive LCD screen
- How to Design and Implement Embedded Navigation System
- Is it better for startups to choose driver chips or driver modules?
- 【AT32F421 Review】+ Reading and Writing of W25Q16 Memory Module
- Understanding FreeRTOS in one article