How to locate a subroutine segment at a fixed address in C51

Publisher:电子科技爱好者Latest update time:2016-11-22 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Q: How does C51 locate a subroutine segment at a fixed address?      

The following two questions need to be solved using C51

: 1. How to locate a subroutine segment at a fixed address?

      For example, locate INT BCD2HEX (INT XX) at 1000H

2. HOW to store a string at a fixed location in EEPROM?

      For example, put "COPYRIGHT 2001-11" at 200H.

Answer: Function location and variable location... 

1. Function location:

If you want to put the function

int BIN2HEX(int xx)

{

    ...

} in the C source file tools.c

at 0x1000 in CODE MEMORY, compile the project first, then open the M51 file of the project, and find the name of the function to be located under the line

* * * CODE MEMORY * * * , which should be in the form of: CODE xxxxH xxxxH UNIT ?PR?_BCD2HEX?TOOLS Then fill in the following content in : Project->Options for Target ...->BL51 Locate: Code : ?PR?_BCD2HEX?TOOLS(0x1000) Build again, and you will find that the function has been placed at 0x1000 in CODE MEMORY in M51. 2. Variable location with initial value: To locate a variable at an absolute position and assign an initial value, use _at_ If it cannot be completed, do the following: create a new file in the project, such as InitVars.c, and assign an initial value to the variable to be processed (assuming it is the code variable ): char code myVer = {"COPYRIGHT 2001-11"}; then add the file to the project, compile, open the M51 file, if the defined type is code, you can find it under * * * CODE MEMORY * * * : CODE xxxxH xxxxH UNIT ?CO?INITVARS then in: Project->Options for Target ...->BL51 Locate: Code, fill in: ?CO?INITVARS(0x200) and compile again. 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 under * * * XDATA MEMORY * * * , you can find: XDATA xxxxH xxxxH UNIT ?XD?INITVARS Then fill in: ?XD?INITVARS(0x200) in: Project->Options for Target ...->BL51 Locate: Xdata and compile again. Correspondingly, if the variables defined are data/idata, etc., just process accordingly. 3. If there are multiple variables or functions to be absolutely located, they should be arranged in order from low to high addresses.

































































Keywords:C51 Reference address:How to locate a subroutine segment at a fixed address in C51

Previous article:Various Problems in C51
Next article:8051 single chip microcomputer TLC1549 data acquisition program source code

Recommended ReadingLatest update time:2024-11-16 12:56

IO port simulation SPI communication C51 program
/**************************  Resources used in the file 1. Port: P0.4, P0.5, P0.6, P0.7 2. Call delay_ms function ******************************/ /*************************     Simulate SPI interface I/O definition ****************************/ sbit spi_cs=P0^1;   sbit spi_di=P0^2;   sbit spi_clk=P0^3; sbit spi_do=P0^
[Microcontroller]
KeilC51 Common Function Modules Instructions
This document includes the description of the clock interrupt, communication and keyboard scanning modules (see the attached source code) commonly used in the single-chip system. These modules use the foreground and background system model. In order to achieve maximum flexibility, it is necessary to define the config.
[Microcontroller]
Generation and use of static library in Keil C51
1. Create a new project, such as LibExample, with the code to generate the library file, and then add the code to it. Select Create Library in Output in Option for target, and compile to generate the library file. 2. Copy the generated library file (LibExample.lib) to the new project (Hello) folder, add it to the
[Microcontroller]
Generation and use of static library in Keil C51
How to write C51 interrupt function
1. Interrupt enable control The CPU's opening and masking of all interrupts of the interrupt system and a certain interrupt source are controlled by the interrupt enable register IE. § EX0 (IE.0), external interrupt 0 enable bit; § ET0 (IE.1), timer/counter T0 interrupt enable bit;
[Microcontroller]
Notes on using Keil C51 MCU development environment
It is best to use Keil to write C51 programs. You can also use Weifu, but Weifu's editing capabilities are far inferior. I am used to writing code with Keil, and then using Weifu hardware simulation (only WAVE simulation head). However, Keil is easy to use, but the key to writing code is still the C51 level, that is
[Microcontroller]
Notes on using Keil C51 MCU development environment
MCU driver TEA5767 FM stereo radio C51 general source code
TEA5767 FM stereo radio, source code for C51 MCU. The module is less than 2 yuan on Taobao. It is recommended to use Keil uVision5 to compile. I used this version to compile and pass. The circuit schematic is as follows: The microcontroller source program is as follows: #include REG52.H #include "Radio.H" #include
[Microcontroller]
MCU driver TEA5767 FM stereo radio C51 general source code
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号