Detailed explanation of STARTUP.A51 of Keil C51

Publisher:WhisperingWavesLatest update time:2016-12-13 Source: eefocusKeywords:Keil  C51  STARTUP.A51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

$NOMOD51 ;Ax51 macro assembler control command: disable predefined 8051
;------------------------------------------------------------------------------
; This file is part of the C51 Compiler package
; Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
;------------------------------------------------------------------------------
; STARTUP.A51: This code is executed after processor reset.
; STARTUP.A51: The code generated by the STARTUP.A51 file will be executed after the microcontroller is reset!
; To translate this file use A51 with the following invocation:
;
A51 STARTUP.A51
;
; To link the modified STARTUP.OBJ file to your application use the following ;
BL51 invocation: ; BL51 , STARTUP.OBJ  ; ;------------------------------------------------------------------------------ ; ; User-defined Power-On Initialization of Memory ; ; With the following EQU statements the initialization of memory ; at processor reset can be defined : ; the absolute start-address of IDATA memory is always 0 IDATALEN EQU 80H ; the length of IDATA memory in bytes. ; IDATA (indirect addressing area) has a fixed starting address of 0; IDATALEN is used to specify the length of the IDATA area to be initialized (in bytes)*












XDATASTART EQU 0H ; the absolute start-address of XDATA memory
XDATALEN EQU 0H ; the length of XDATA memory in bytes.
;XDATA (External Direct Addressing Area) XDATASTART is used to specify the starting address of the XDATA area to be initialized
; XDATALEN is used to specify the length of the XDATA area to be initialized (in bytes)*

PDATASTART EQU 0H ; the absolute start-address of PDATA memory
PDATALEN EQU 0H ; the length of PDATA memory in bytes.
;PDATA (Page Addressing Area) PDATASTART is used to specify the starting address of the PDATA area to be initialized
; PDATALEN is used to specify the length of the PDATA area to be initialized (in bytes)*

; Notes: The IDATA space overlaps physically the DATA and BIT areas of the
; 8051 CPU. At minimum the memory space occupied from the C51 
; run-time routines must be set to zero.

;Note: The IDATA area in 8051 physically includes the DATA area (direct addressing area) and the BIT area (bit addressing area). C51 (library) occupies the minimum memory space, and the program needs to set it to 0 during runtime

;------------------------------------------------------------------------------
;
; Reentrant Stack Initilization
;

The following EQU statements define the stack pointer for reentrant ;
functions and initialized it: ; Stack Space for reentrant functions in the SMALL model. ; IBPSTACK EQU 0 ; set to 1 if small reentrant is used. ; IBPSTACKTOP EQU 0FFH+1 ; set top of stack to highest location+ 1 . ; Stack Space for reentrant functions in the LARGE model. ; XBPSTACK EQU 0 ; set to 1 if large reentrant is used. ; XBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1. ; ; Stack Space for reentrant functions in the COMPACT model.     ; PBPSTACK EQU 0 ; set to 1 if compact reentrant is used. ; PBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1. ; ; ------------------------------------------------------------------------------ ; ; Page Definition for Using the Compact Model with 64 KByte xdata RAM ; The following EQU statements define the xdata page used for pdata ; variables. The EQU PPAGE must conform with the PPAGE control used ; in the linker invocation. ; The following EQU statements define the use of the XDATA page for the PDATA variable PPAGEENABLE EQU 0 ; set to 1 if pdata object are used. ; PPAGE EQU 0 ; define PPAGE number. ; Define page number ; PPAGE_SFR DATA 0A0H ; SFR that supplies uppermost address byte ; (most 8051 variants use P2 as uppermost address byte) ; (most 8051 variants use P2 as uppermost address byte) ;------------------------------------------------------------------------------













































; Standard SFR Symbols 
; Standard SFR Symbols
ACC DATA 0E0H
B DATA 0F0H
SP DATA 81H
DPL DATA 82H
DPH DATA 83H

                                NAME    ?C_STARTUP


?C_C51STARTUP   SEGMENT   CODE
?STACK                  SEGMENT   IDATA

                               RSEG    ?STACK
                                 DS      1

                               EXTRN CODE (?C_START)
; External code (this label will represent the starting address of the user program)
                                PUBLIC ?C_STARTUP
; Symbol for external use

                                CSEG AT 0
; Place the following code at address 0 of the code segment (use AT instructions to locate the absolute address)
?C_STARTUP: LJMP STARTUP1

                              RSEG    ?C_C51STARTUP

STARTUP1:

IF IDATALEN <> 0   
; If the length is greater than 1, initialize IDATA
                MOV R0, #IDATALEN - 1
                CLR A
IDATALOOP: MOV @R0, A
                DJNZ R0, IDATALOOP
ENDIF

IF XDATALEN <> 0  
; If the length is greater than 1, initialize XDATA
                MOV DPTR,#XDATASTART
                MOV R7,#LOW (XDATALEN)


IF (LOW (XDATALEN)) <> 0
; Preset the number of external loops during initialization to R6
                MOV R6,#(HIGH (XDATALEN)) +1
ELSE
                MOV R6,#HIGH (XDATALEN)
ENDIF
                CLR A
XDATALOOP: MOVX @DPTR,A
                INC DPTR
                DJNZ R7,XDATALOOP
                DJNZ R6,XDATALOOP
ENDIF

IF PPAGEENABLE <> 0
                MOV     PPAGE_SFR,#PPAGE
ENDIF

IF PDATALEN <> 0  
;If the length is greater than 1, initialize PDATA
                MOV R0,#LOW (PDATASTART)
                MOV R7,#LOW (PDATALEN)
                CLR A
PDATALOOP: MOVX @R0,A
                INC R0
                DJNZ R7,PDATALOOP
ENDIF

IF IBPSTACK <> 0   
; When using reentrant functions in SMALL mode, set the stack
EXTRN DATA (?C_IBP)

                MOV     ?C_IBP,#LOW IBPSTACKTOP
ENDIF

IF XBPSTACK <> 0   
; Stack EXTRN DATA to be set when using reentrant functions in COMPACT mode
(?C_XBP)

                MOV     ?C_XBP,#HIGH XBPSTACKTOP
                MOV     ?C_XBP+1,#LOW XBPSTACKTOP
ENDIF

IF PBPSTACK <> 0  
;Stack to be set when using reentrant functions in LARGE mode
EXTRN DATA (?C_PBP)
                MOV ?C_PBP,#LOW PBPSTACKTOP
ENDIF

                MOV SP,#?STACK-1
; This code is required if you use L51_BANK.A51 with Banking Mode 4
; If your program uses Mode 4 program grouping technology (BANKING), please enable the following program code
; EXTRN CODE (?B_SWITCH0)
; CALL ?B_SWITCH0 ; init bank mechanism to code bank 0
; The program starts from the first block (bank0)
                LJMP ?C_START ; Jump to your program entry from here

                END

;*******************************************************************

The original project did not include the startup.A51 file, and the program sometimes had garbled characters and pointer overflow, causing system abnormalities. After adding this file, for the C8051F340 microcontroller 4K Xdata, I sampled the following settings:

; ; Stack Space for reentrant
functions in the LARGE model. ; XBPSTACK EQU 1 ; set to 1 if large reentrant is used. ; XBPSTACKTOP EQU 0FFFH+1; set top of stack to highest location+1. ;





The system is now running stably!


Keywords:Keil  C51  STARTUP.A51 Reference address:Detailed explanation of STARTUP.A51 of Keil C51

Previous article:51 Values ​​in MCU
Next article:Design and Implementation of Embedded Real-time Control Module Based on C51

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

Absolute address positioning of KEIL C51
For MCU space allocation, see *.M51 file. For ARM and DSP space allocation, see *.map file.   1. Function location: If you want to place 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 projec
[Microcontroller]
The integration method of 51 MCU and MDK in Keil5
I don't know how friends in the forum deal with MDK and 51. Some time ago, I used Keil4 to write 51 and Keil5 to write ARM. Later I found that the two can actually be integrated together. Here I share my tricks. 1. There are many tutorials on the installation of Keil5 on the Internet. Here I provide the package of MD
[Microcontroller]
The integration method of 51 MCU and MDK in Keil5
STM32 Problem Record: This time Keil compiler is to blame
I recently wrote an STM32 serial port program that uses a circular buffer to send data: use the head pointer (front) to point to the next data to be sent, and use the tail pointer (rear) to point to the location where the new data is stored. The interrupt will determine whether front and rear are equal. If they are eq
[Microcontroller]
Basic knowledge of Keil C51 development system 2
3. Section 3 Storage Mode The storage mode determines the default storage area for variables, function parameters, etc. that do not have a clear storage type specified. There are three types in total: 1. 1. Small mode All default variables and parameters are loaded into the internal RAM. The advantage is fast access
[Microcontroller]
Summary of four ways of working of C51 MCU serial port
Mode 0: Synchronous shift register input and output mode 1. Use shift registers to achieve serial/parallel conversion (function) 2. Baud rate: fosc/12 3. RXD (P3.0) ---- used for serial data input and output TXD (P3.1) ---- acts as the shift clock for output 4. Data size: 8 bits 5. Mode 0 sending: ○ Serial port inter
[Microcontroller]
Summary of four ways of working of C51 MCU serial port
Code efficiency of Keil C51
The efficiency of C51 program compilation to generate assembly code is determined by many factors. For Keil C51, it is mainly affected by the following two factors:  Section 1 The impact of storage mode     The storage mode determines the storage space of the default variables, and the complexity of the assembly cod
[Microcontroller]
Application and feature analysis of Keil c51
Keil c51 is known as the best development environment for 51 series microcontrollers, and everyone must be familiar with it. Everyone knows some of its common features (it is also mentioned in books), such as: because the RAM in 51 is very small, C51 functions do not pass parameters through the stack (except for reent
[Microcontroller]
S3C2440 ADS transplantation Keil
Recently, some errors occurred when converting the ADS1.2 project to MDK4.03. This article lists the possible errors and provides relevant solutions so that everyone can solve them as soon as possible in the future conversion. 1: error  :  No  section  matches  selector  –no  section  to  be  FIRST/LAST. Cha
[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号