1. Startup code generated by Keil C
Program Listing 1.1 AT89C51 startup code
$NOMOD51 //Do not use the default special function register 51
;------------------------------------------------------------------------------
; 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.
; It is clear that this code will be executed first after the processor is powered on and 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 ; BL51 is the linker used by Keil. This is the command line format. ;------------------------------------------------------------------------------ ; ; User-defined Power-On Initialization of Memory ; Below we will define some symbolic constants related to memory initialization. Compared with ICCAVR, Keil's explicit declaration of symbolic constants is easier to understand. ; 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. ;IDDATALEN refers to the 128-byte RAM on the chip, I refers to internal XDATASTART EQU 0H ; the absolute start-address of XDATA memory XDATALEN EQU 0H ; the length of XDATA memory in bytes. ; XDATA refers to the off-chip SRAM space, X refers to external PDATASTART EQU 0H ; the absolute start-address of PDATA memory PDATALEN EQU 0H ; the length of PDATA memory in bytes. ; PDATA refers to program memory, p refers to program ; 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 register space and memory space of the 8051 CPU are not uniformly addressed, but are distinguished by instructions, so the addresses of different storage areas may overlap. ;------------------------------------------------------------------------------ ; ; Reentrant Stack Initialization ; ; The following EQU statements define the stack pointer for reentrant ; functions and initialized it: ; Keil C does not use the stack to pass parameters by default, so the function is not reentrant (for the concept of reentrancy, see the section on thread safety and reentrant functions). Keil requires the user to explicitly declare whether the function has the reentrant attribute in order to initialize the stack for the C function call. ; 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. ;Stack in different memory modes. There are three mode settings in Keil compiler: Small: All variables are placed in the internal RAM area Compact: All variables are placed in the lower 256 bytes of external RAM by default (addressable by R0) Large: All variables are placed in external RAM (DPTR addressing) This is caused by the 51 processor's numerous addressing modes. Different addressing modes have different efficiencies. ;------------------------------------------------------------------------------ ; ; 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. ; PPAGEENABLE EQU 0 ; set to 1 if pdata object is used. ; PPAGE EQU 0 ; define PPAGE number. ; PPAGE_SFR DATA 0A0H ; SFR that supplies uppermost address byte ; (most 8051 variants use P2 as uppermost address byte) ; ;------------------------------------------------------------------------------ ; 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) PUBLIC ?C_STARTUP CSEG AT 0 //Starting point of the code segment ?C_STARTUP: LJMP STARTUP1 //Jump to the STARTUP1 program area. RSEG ?C_C51STARTUP STARTUP1: //IF ENDIF is a conditional compilation command. The code is compiled only when the condition is true. IF IDATALEN <> 0 //If there is IDATA, clear the data in the IDATA area, similar to clearing the BSS area MOV R0,#IDATALEN - 1 CLR A IDATALOOP: MOV @R0,A DJNZ R0,IDATALOOP ENDIF //If there is an external data area, clear the area from XDATASTART to XDATASTART + XDATALEN in the external data area //Since there are many storage area types and compilation models for 51, the following code clears the corresponding area according to different configurations IF XDATALEN <> 0 MOV DPTR,#XDATASTART MOV R7,#LOW (XDATALEN) IF (LOW (XDATALEN)) <> 0 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 MOV R0,#LOW (PDATASTART) MOV R7,#LOW (PDATALEN) CLR A PDATALOOP: MOVX @R0,A INC R0 DJNZ R7,PDATALOOP ENDIF IF IBPSTACK <> 0 EXTRN DATA (?C_IBP) MOV ?C_IBP,#LOW IBPSTACKTOP ENDIF IF XBPSTACK <> 0 EXTRN DATA (?C_XBP) MOV ?C_XBP,#HIGH XBPSTACKTOP MOV ?C_XBP+1,#LOW XBPSTACKTOP ENDIF IF PBPSTACK <> 0 EXTRN DATA (?C_PBP) MOV ?C_PBP,#LOW PBPSTACKTOP ENDIF //This is where the stack pointer is initialized MOV SP,#?STACK-1 ; This code is required if you use L51_BANK.A51 with Banking Mode 4 ; EXTRN CODE (?B_SWITCH0) ; CALL ?B_SWITCH0 ; init bank mechanism to code bank 0 LJMP ?C_START END From the above code, we have found some operations that are the same as the ATmega8 initialization code: initializing the stack and bss area. Since the storage space and addressing mode of AT89C51 are more complex than ATmega8, many initialization codes based on different configurations are added to the initial code.
Previous article:Analysis of 51 MCU stack
Next article:How the serial port works
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- 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
- [AIoT Smart Smoke Detection System] SiPEED MAIX Bit K210 Development Board Hands-on Experience
- CC2540 learning to send strings
- EEWORLD University Hall----Live Replay: ADI Energy Storage System Helps Build Electric Vehicle Fast Charging Stations
- Digital Temperature Servo Control System Based on Microcontroller
- [Perf-V Evaluation] Study and RTL Simulation Experiment of Hummingbird E203 Open Source SOC
- About the power supply problem of LED constant current chip
- LIN communication, no response error, please help
- Very useful, a summary of RF dry goods (worth collecting)
- Work (II) Implementation of Linear and Nonlinear Signal Source Based on MCU + FPGA
- [GD32L233C-START Review] 5. Flash Read and Write - Using Internal Flash to Store Data