51 Setting variables, arrays, and functions in fixed positions in single-chip microcomputers

Publisher:创新火箭Latest update time:2019-04-18 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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


                     }


Reference address:51 Setting variables, arrays, and functions in fixed positions in single-chip microcomputers

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

Characteristics of 8051 microcontroller_What are the control bus signals of 8051 microcontroller
  Characteristics of 8051 microcontroller   The instruction system of 8051 consists of 111 instructions. If classified by the number of bytes, there are 49 single-byte instructions, 46 double-byte instructions and 16 three-byte instructions, mainly single-byte instructions; if classified by instruction execution time,
[Microcontroller]
Design of power battery management system based on CC430F5137 microcontroller
Introduction With the continuous development of new energy vehicles, large factories have gradually begun to use transport vehicles driven by power batteries. The batteries commonly used in electric vehicles are lead-acid batteries, lithium batteries, nickel-metal hydride batteries, etc. The battery is an object that
[Microcontroller]
Design of power battery management system based on CC430F5137 microcontroller
PROTUS simulation 51 single chip microcomputer frequency measurement program
frequency meter: LCD1602 display Without adding external counting hardware, this test software can measure the highest frequency up to 460KHz working principle: The number of input pulses counted within 1 second is the frequency value. The maximum count value of a 16-bit binary adder counter is 65535. Set time
[Microcontroller]
PROTUS simulation 51 single chip microcomputer frequency measurement program
Connect 8051 based microcontroller to SCI port
This application note describes how to configure the UART of a high-speed microcontroller or ultra-high-speed flash microcontroller to communicate with an SCI-enabled device. It begins with a brief discussion of the differences between SCI and UART modules and ends with a practical example of how to configure an 8051-
[Microcontroller]
Connect 8051 based microcontroller to SCI port
About the Intelligent Power Cabinet of Single Chip Microcomputer C8051F060
  1. Introduction   As the capacity of generators continues to increase, the requirements for excitation systems are getting higher and higher. The various types of excitation regulators currently used in China are very advanced, but the manufacturing level of power cabinets is not satisfactory, which is bound to aff
[Microcontroller]
About the Intelligent Power Cabinet of Single Chip Microcomputer C8051F060
Design program of electronic speed and mileage anti-theft alarm based on 51 single chip microcomputer
    //************************************************ ************     //Title: 4x4 keyboard input function // Function description: char gotkey(void) // Input data from the 4*4 keypad and return 0~9, and other data. //*********************************************************** //Time delay function //***************
[Microcontroller]
51 microcontroller principle and application
  The 51 microcontroller is an 8-bit microcontroller designed based on the Harvard structure, also called AT89C51. It was launched by Intel in the early 1980s and became one of the most popular microcontrollers at the time. It is still widely used in various embedded systems.   The architecture of the 51 microcontro
[Microcontroller]
Reasons why 51 single chip microcomputer cannot start oscillating normally
How to ensure that the crystal oscillator starts oscillating normally? 1. There are many ways to judge. Using an oscilloscope to view the waveform is the most direct. You can also use the voltage range of a digital multimeter to measure the voltage. Because the duty cycle of the crystal oscillator waveform is 50%, t
[Microcontroller]
Reasons why 51 single chip microcomputer cannot start oscillating normally
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号