Due to the importance of the CPU and program startup code file STARTUP.a51, some 8051-derived CPU products require the CPU to be initialized to meet the corresponding hardware in the design. Therefore, sometimes users need to modify STARTUP.a51, so make a comment:
;--------------------------------------------------
;startup.A51: User power-on initialization program
;----------------------------------------------------
;
;Use the following EQU command to define the memory space that needs to be initialized with 0 when the CPU is reset
;
;The absolute starting address of the IDATA memory space is always zero
IDATALEN EQU 80H ;The number of bytes of the IDATA memory space that need to be initialized with 0
;
XDATASTART EQU 0H ;The absolute starting address of the XDATA memory space
XDATALEN EQU 0H ;The number of bytes of the XDATA memory space that need to be initialized with 0
;
PDATASTART EQU 0H ;The absolute starting address of the PDATA memory space
PDATALEN EQU 0H ;The number of bytes of the PDATA memory space that need to be initialized with 0
; Note: The IDATA memory space physically includes the DATA and BIT storage spaces of the 8051 microcontroller
; At least the memory space related to the C51 compiler runtime library must be initialized with 0
;
;Reentrant function simulation initialization
;-----------------------------------------------------------
;The following uses the EQU instruction to define the initialization of the reentrant function simulation stack pointer
;
;The stack space of the reentrant function when using the SMALL memory mode
IBPSACK EQU 0 ;Set it to 1 when using the SMALL memory mode reentrant function
IBPSTACKTOP EQU 0FFH+1 ;Set the top of the stack to the highest address plus 1
;
;When using LARGE memory mode, the stack space of the reentry function
is XBPSTACK EQU 0;When using LARGE memory mode, set it to 1 when reentering the function
XBPSTACKTOP WQU 0FFFFH+1;Set the top of the stack to the highest address plus 1
;
;When using COMPACT memory mode, the stack space of the reentry function
is PBPSTACK EQU 0;When using COMPACT memory mode, set it to 1 when reentering the function
PBPSTACKTOP WQU 0FFFFH+1;Set the top of the stack to the highest address plus 1
;;----------------------------------------------------
;When using COMPACT memory mode, the paging definition of the 64KB X DATA memory space
;
;The following uses the EQU instruction to define the page address of the PDATA type variable in the XDATA memory space
;When using the EQU instruction to define PFAGE, it must be consistent with the control parameters of the L51 connection locator PDATA instruction
;
PPAGEENABLE EQU 0;When using PDATA type variables, set it to 1
PPAGE EQU 0 ;Define page number
;
;------------------------------------------------
NAME ? C_STARTUP ;Module name? C_STARTUP
? C_51STARTUP SEGMENT CODE ;Code segment
? STACK SEGMENT IDATA ;Stack segment
RSEG ? STACK ;Stack
DS 1
EXTRN COE(? C_START) ;Program start address
PUBLIC ? C_STARTUP
CSEG AT 0x8000 ;Define the starting address of the user program, which may be useful when using the MON51 emulator
? C_STARTUP: LFMP STARTUP1
RSEG ? C_51STARTUP
STARTUP1:
;
;Initialize serial port
MOV SCOM, #40H
MOV TMOD, #20H
MOV TH1, #0FDH
SETB TR1
CLR T1
;The IDATA memory is cleared when the MCU is powered on. If you do not need to clear IDATA on power-on, you can cancel the statement between IF and IFEDN
, or modify the length of IDTALEN. In order to make the CPU have power-off protection function, you need to determine the length of IDTALEN.
IF IDATALEN <> 0
MOV R0, # IDATALEN-1
CLR A
IDATALOOP: MOV @R0,A
DJNZ R0,IDATALOOP
ENDIF
;
;The XDATA memory is cleared when the MCU is powered on. If you do not need to clear XDATA on power-on, you can cancel the statement between IF and IFEDN
, or modify the length of XDTALEN.
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
END IF
;
;Send PDATA memory page high address
IF PPAGEENABLE <> 0
MOV P2, #PPAGE
ENDIF
;
;The PDATA memory is cleared when the MCU is powered on. If you do not need to clear XDATA on power-on, you can cancel
the statements between IF and IFEDN or modify the length of PDATALEN
IF PDATALEN <> 0
MOV R0, #PDATASTART
MOV R7, #LOW (PDATALEN)
CLR A
PDATALOOP: MOV @R0, A
INC R0
DJNZ R7,PDATALOOP
ENDIF
;
;Set the stack space for reentry function when using SMALL memory mode
IF IBPSTACK <> 0
EXTRN DATA(? C_IBP)
MOV ? C_IBP, #LOW IBPSTACKTOP
ENDIF
;
;Set the stack space for reentry function when using LARGE memory mode
IF XBPSTACK <> 0
EXTRN DATA (? C_XBP)
MOV ? C_XBP, #HIGH XBPSTACKTOP
MOV ? C_XBP +1, #LOW XBPSTACKTOP
ENDIF
;
;Set the stack space for reentry function when using COMPACT memory modeIF
PBPSTACK <> 0
EXTRN DATA(? C_PBP)
MOV ? C_PBP, #LOW PBPSTACKTOP
END IF
;
;Set the starting address of the stackMOV
SP, #? STACK-1 ;For example, MOV SP, #4FH
;
;If the program exceeds 64K, use program grouping technology to start the following program
;EXTRN CODE(? B_SWITCH0)
;CALL ? B_SWITCH0
;The program starts executing from the first group of bank 0 blocks
;Jump to the user program MAIN function
LJMP ? C_START
END
Previous article:Add assembly method to keil c file
Next article:Detailed Modbus routine based on single chip microcomputer
Recommended ReadingLatest update time:2024-11-15 21:05
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
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
- Wireless secure communication terminal based on FPGA system on chip
- After cashing out 1.5 billion yuan, Mobike's post-80s founder left behind two unspoken rules for life
- Three audio hardware interfaces
- RISC-V cross-compilation tool chain and the process of building a simulation environment
- 【New Year's Festival Competition】+ Characteristics of Southern Small Cities
- VESA and Computer Display Monitor Timing (DMT) Industry Standards and Guidelines
- Thyristor control relay problem analysis
- A flyback adapter reference design with a maximum output of 9V 5A
- Download Gift|ADI Flow Cytometer Solution
- EEWORLD University Hall----Application of TI DLP? Technology in 3D Machine Vision and Automated Optical Inspection