Keil C51 and Keil ARM coexist

Publisher:epsilon15Latest update time:2016-12-12 Source: eefocusKeywords:Keil  C51  ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Section 1 Absolute Address Access 

C51 provides three methods to access absolute addresses: 
1. Absolute macros: 

In the program, use "#include" to use the macros defined in it to access absolute addresses, including: 
CBYTE, XBYTE, PWORD, DBYTE, CWORD, XWORD, PBYTE, DWORD. 

For specific usage, you can take a look at absacc.h. 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 
2. _at_ keyword 
Just add _at_ const after the data definition, but note: 

(1) Absolute variables cannot be initialized; 

(2) Bit-type functions and variables cannot be specified with _at_. 

For example: 
idata struct link list _at_ 0x40; specifies that the list structure starts at 40h. 
xdata char text[25b] _at_0xE000; specifies that the text array starts from 0E000H. 
Tip: If the external absolute variable is an I/O port or other data that can change by itself, it needs to be described using the volatile keyword, please refer to absacc.h. 

3. Connection positioning control 

This method uses the connection control instruction code xdata pdata data bdata to perform "segment" address. If you want to specify a specific variable address, it is very limited and will not be discussed in detail.

Section 2 Keil C51 and assembly interface

1. The interface method within the module 
is to use the #pragma statement. The specific structure is: 
#pragma asm 
assembly line 
#pragma endasm 

This method essentially tells the C51 compiler through asm and ndasm that the intermediate line does not need to be compiled into an assembly line, so there is SRC in the compilation control instruction to control the storage of these non-compiled lines.

2. Interface between modules 

The interface between C module and assembly module is relatively simple. Use C51 and A51 to compile the source file respectively, and then use L51 to connect the obj file. The key issue is the parameter passing between C function and assembly function. There are two parameter passing methods in C51. 
(1) Passing function parameters through registers. 
At most 3 parameters can be passed through registers. The rules are as follows: 

Number of parameters

char

int

long,float

General pointers

1
2
3

R7
R5
R3

R6 & R7
R4 & R5
R2 & R3

R4~R7
R4~R7

R1~R3
R1~R3
R1~R3


(2) Fixed memory transfer: 

This method transfers bit type parameters to a storage segment: 
? function_name?BIT. 
Other types of parameters are transferred to the following segment: ? function_name?BYTE, and are stored in a pre-selected order. 
As for where this fixed storage area is located, it is determined by the storage mode. 

(3) Function return value: 
The function return value is always placed in a register, with the following rules:

Return type

Registev

illustrate

bit

Flags

Returned by specific flags

char/unsigned char 1_byte pointer

R7

A single byte is returned by R7

int/unsigned int 2_byte pointer

R6 & R7

The double byte is returned by R6 and R7, with the MSB in R6

long&unsigned long 

R4~R7

MSB at R4, LSB at R7

float

R4~R7

32-bit IEEE format

General pointers

R1~R3

Storage type in R3 high R2 low R1

(4) SRC control 

This control instruction compiles the C file to generate an assembly file (.SRC). The assembly file can be renamed to generate an assembly .ASM file, and then compiled with A51. 
Section 3 Common files in the Keil C51 software package 

There are several C source files in the C51LiB directory. These C source files play a very important role. With a slight modification, they can be used in your own dedicated system. 
1. Dynamic memory allocation 

init_mem.c: This file is the source code for initializing the dynamic memory area. It can specify the location and size of the dynamic memory. Only when init_mem() is used can other functions such as malloc, calloc, realloc, etc. be called back. 

calloc.c: This file is the source code for allocating memory to an array. It can specify the unit data type and the number of units. 
malloc.c: This file is the source code of malloc, which allocates a fixed size of memory. 
realloc.c: This file is the source code of realloc.c, and its function is to adjust the size of the currently allocated dynamic memory. 

2. C51 startup file STARTUP.A51 

The startup file STARTUP.A51 contains the target board startup code. This file can be added to each project. As long as it is reset, the file will be executed immediately. Its functions include: 

defining the internal RAM size, external RAM size, and reentrant stack position; 
clearing the internal, external, or external memory in units of pages; 
initializing the reentrant stack and stack pointer according to the storage mode; 
initializing the 8051 hardware stack pointer 

to the main() function; developers 

can modify the following data to initialize the system. 

Constant Name Meaning 

IDATALEN Length of internal RAM to be cleared 
XDATA START Specify the starting address of external RAM to be cleared 
XDATALEN Length of external RAM to be cleared 
IBPSTACK Whether the small mode reentrant stack pointer needs to be initialized, 1 means required. The default value is 0. 
IBPSTACKTOP specifies the top address of the small mode reentrant stack.  XBPSTACK specifies 
whether the large mode reentrant stack pointer needs to be initialized. The default value is 0.  XBPSTACKTOP specifies the top address of the large mode reentrant stack . PBPSTACK specifies whether the Compact reentrant stack pointer needs to be initialized. The default value is 0.  PBPSTACKTOP specifies the top address of the Compact mode reentrant stack.  PPAGEENABLE P2 initialization enable switch  PPAGE specifies P2 value  PDATASTART The first address of the external RAM page to be cleared  PDATALEN The length of the external RAM page to be cleared.  Tip: If you want to initialize P2 as the high-end address of the compact mode, you must: PPAGEENAGLE=1, PPAGE is the P2 value, for example, specify a page 1000H-10FFH, then PPAGE=10H,  3. Standard input and output file  putchar.c  putchar.c is a low-level character output subroutine. Developers can modify it and apply it to their own hardware systems, such as outputting characters to CLD or LEN.  Default: putchar.c outputs a character to the serial port. XON and XOFF are flow control marks. The line feed character "*n" is automatically converted to carriage return/line feed "  ".  getkey.c  The getkey function is a low-level character input subroutine. This program can be used in your own hardware system, such as matrix keyboard input. By default, characters are input through the serial port.  4. Other files  include the INIT.A51 function with unique functions for Watch-Dog and functions applicable to 8×C751. Please refer to the source code. Section 4 Segment Naming Conventions and Program Optimization  1. Segment Naming Conventions  The target files generated by the C51 compiler are stored in many segments. These segments are some units of code space or data space. A segment can be relocatable or absolute. Each relocatable segment has a type and name. The C51 segment name has the following regulations: Each segment name  consists of a prefix and a module name. The prefix indicates the storage type, and the module name is the name of the compiled module. For example:  ? CO? main1: Indicates the constant part of the code segment in the main1 module  ? PR? function1? module refers to the executable segment of function function1 in module module. For specific regulations, please refer to the manual.  2. Program optimization  C51 compiler is a compiler with optimization function. It provides six levels of optimization function. Ensure the highest efficiency of generating target code (least code, fastest running speed). For specific six-level optimization content, please refer to the help.  The following compilation control instructions are provided in C51 to control code optimization:  OPTIMIZE (SJXE): Try to use subroutines to reduce program code.  NOAREGS: Do not use absolute register access, and the program code is independent of the register segment.  NOREGPARMS: Parameter passing is always implemented in the local data segment, and the program code is compatible with the lower version of C51.  OPTIMIZE (SIZE) AK OPTIMIZE (speed) provides 6 levels of optimization function, the default is: OPTIMIZE (6, SPEED).
















































Keywords:Keil  C51  ARM Reference address:Keil C51 and Keil ARM coexist

Previous article:Keil C51 compilation error warning solution accumulation
Next article:How to use Keil C51 software

Recommended ReadingLatest update time:2024-11-16 19:25

11. Exceptions and interrupts of ARM architecture
1. Introduction of exceptions and interrupts 1.1. The concept of interruption An interrupt is a response made by the CPU to an event that occurs in the system: the CPU pauses the program being executed, automatically switches to execute the corresponding processing program after preserving the scene, and returns to
[Microcontroller]
11. Exceptions and interrupts of ARM architecture
Arm Neoverse is becoming a new force in the data center
Arm's next move after it acquires general-purpose computing power for phones and Internet of Things devices is unclear. Although the x86 giants dominate the data center, competition between Arm and RISC-V on smaller platforms has begun to take shape. However, Arm has been actively expanding its business and moving up
[Embedded]
Arm Neoverse is becoming a new force in the data center
ARM7 Getting Started 12, SPI Communication
The digital tube displays 1-F. Main program: /******************************************************************************* *File: Main.c *Function: The LED digital tube displays characters 0-F, and controls 4 LEDs to display the corresponding hexadecimal ****************************************************
[Microcontroller]
ARM7 Getting Started 12, SPI Communication
Quickly learn Arm (20)--Interrupt Vector Controller VIC[2]
The above is a diagram used to introduce the relationship between VIC and various registers. Because the blog cannot contain too large diagrams, I can only reduce it to a size that is almost invisible. A leader once advised me to be calm and not to use overtime to prove the quality of my work. I really accepted it
[Microcontroller]
Quickly learn Arm (20)--Interrupt Vector Controller VIC[2]
Arm revenue hits record high
Earlier, SoftBank Group released the company's revenue data for the first fiscal quarter of 2021 (April to June). In the report, they also disclosed Arm's revenue performance in the first quarter of 2021. Earlier, SoftBank also released the company's financial report performance for fiscal year 2020, which also includ
[Semiconductor design/manufacturing]
Arm revenue hits record high
LCD driver development in ARM9 series embedded processor S3C2410 system
  This article is based on the LCD interface of Samsung's ARM9 core chip S3C2410 and introduces the general method of developing embedded LCD drivers on the Linux platform.   The hardware of this article uses the development board of Samsung's S3C2410 chip. The software uses the Linux 2.4.19 platform. The compiler i
[Microcontroller]
Selection of startup file and firmware library macro definition in stm32 - keil
● Startup file selection 1. Low-density devices (STM32F10nx4 = 16k, STM32F10nx6 = 32k) - startup_stm32f10x_ld_vl.s: Small capacity value type. STM32F100xx series, flash memory 16k~32k bytes. - startup_stm32f10x_ld.s: small capacity type. STM32F101xx, STM32F102xx, STM32F103xx series, flash memory 16k~32k bytes.  
[Microcontroller]
Selection of startup file and firmware library macro definition in stm32 - keil
ARM addressing mode experiment
1. Experimental Purpose 1.            Understand various addressing modes: immediate value; register; register shift; register indirect addressing; indexed addressing. 2.            Consolidate and improve the basic skills of using assembly language for programming in the ADS environment.   2. Experimental Content
[Microcontroller]
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号