Detailed explanation of C51 startup code under keil

Publisher:Wanderlust123Latest update time:2016-11-18 Source: eefocusKeywords:keil  C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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


Keywords:keil  C51 Reference address:Detailed explanation of C51 startup code under keil

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

C51 Timer usage and generation of 1ms system tick
When GATE=0, TR0 and TR1 are used to control the start of T1 and T0, and when GATE=1, external interrupts are used for control. When C/T is 0, it indicates timer mode. When C/T is 1, it indicates counter mode, which counts the external negative transition pulses of T0 or T1. Calculation of the timer initial value: TH
[Microcontroller]
C51 Timer usage and generation of 1ms system tick
Keil compilation error about the use of __use_no_semihosting_swi
__use_no_semihosting_swi, that is, do not use semihost mode to prevent the program from entering software interrupts. 1. If file operations such as printf, fopen, and fclose occur during the compilation of an embedded program, the device will enter the software interrupt BAEB when it is running because there is no u
[Microcontroller]
Detailed explanation of data idata xdata code in keil c51
51 single-chip microcomputer adopts Harvard structure. The memory space addressing has overlap. Different variables can be defined on different buses (referred to as bus domains in this article, or domains for short). Several domain modifiers such as data, idata, xdata, and code are defined in keilc51. These modifiers
[Microcontroller]
Detailed explanation of data idata xdata code in keil c51
Simple implementation of assembly and C language mixed keil9.0 project source code
The core intention of system design: Use timers to run other tasks during the delay process. Project source code: Link: https://pan.baidu.com/s/1LEV9qYmUn6SdemGz7TH6dw Extraction code: iua5  Switch tasks and record the position to ensure that you can switch back after the time is up. (Switch out in the task, switc
[Microcontroller]
Simple implementation of assembly and C language mixed keil9.0 project source code
51 MCU C language learning notes 4: Keil C51 absolute address access
When using Keil to program 8051 microcontrollers, absolute addresses are often required for access, especially for hardware operations, such as DA AD sampling, LCD liquid crystal operations, printing operations, and so on. C51 provides three methods to access absolute addresses:  1. Absolute macros:      In the prog
[Microcontroller]
C51 MCU Memory Optimization
  52 has 256B of data storage area. If you don't pay attention to some details, it is easy to get an error when the RAM exceeds 128. The following is an explanation of the problem:   The two most common ones are:   ① When the number of variables exceeds 128, the code must be compiled in compact mode. In practice, as l
[Microcontroller]
CH375 read and write U disk C51 sample source program
#include "datatype.h" #include "console.h" #include "44b0x.h" #include string.h /* Please see the CH375HF9.H file for detailed descriptions of the following definitions*/ #define LIB_CFG_FILE_IO 1 /* file Copy mode of read and write data, 0 is "external subroutine", 1 is "internal copy" */ #define LIB_CFG_INT_EN 1 /*
[Microcontroller]
Analysis of several common warnings encountered in the Keil programming environment
There are several common warnings in Keil. Of course, compared with errors, the degree of warning is not as serious as the error. Sometimes, if you ignore it, unexpected errors will occur. Let's take a look at several common errors and analyze the reasons for them. 1. Warning 280: 'i': unreferenced local variable
[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号