Keil C51 Startup.a51我的理解
扫描二维码
随时随地手机看文章
$NOMOD51
;------------------------------------------------------------------------------
; 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.
;
; 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: . 在CPU复位时,使用以下EQU命令可定义初始化的内存空间
;
; ; the absolute start-address of IDATA memory is always 0. IDATA 存储器的空间的绝对起始地址总是0
IDATALEN EQU 80H ; the length of IDATA memory in bytes. IDATA存储器空间初始化大小--80个bytes
;
XDATASTART EQU 0H ; the absolute start-address of XDATA memory. XDATA存储器空间的绝对起始地址0x00
XDATALEN EQU 0H ; the length of XDATA memory in bytes.XDATA存储器空间初始化大小--0个bytes
;
PDATASTART EQU 0H ; the absolute start-address of PDATA memory. PDATA存储器空间的绝对起始地址0x00
PDATALEN EQU 0H ; the length of PDATA memory in bytes. PDATA存储器空间初始化大小--0个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.
;------------------------------------------------------------------------------
;
; Reentrant Stack Initilization. 再入堆栈初始化
;
; The following EQU statements define the stack pointer for reentrant
; functions and initialized it: . 以下用EQU指令定义了堆栈再入函数和初始化
;
; Stack Space for reentrant functions in the SMALL model.使用SMALL存储器模式时再入函数的堆栈
IBPSTACK EQU 0 ; set to 1 if small reentrant is used. 使用SMALL存储器模式再入函数时将其设置成1
IBPSTACKTOP EQU 0FFH+1 ; set top of stack to highest location+1. 将堆栈顶设置为最高地址+1
;
; Stack Space for reentrant functions in the LARGE model.使用LARGE存储器模式时再入函数的堆栈空间
XBPSTACK EQU 0 ; set to 1 if large reentrant is used. 使用LARGE存储器模式再入函数时将其设置成1
XBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1. 将堆栈顶设置为最高地址+1
;
; Stack Space for reentrant functions in the COMPACT model.使用COMPACT存储器模式时再入函数的堆栈空间
PBPSTACK EQU 0 ; set to 1 if compact reentrant is used. 使用COMPACT存储器模式再入函数时将其设置成1
PBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1. 将堆栈顶设置为最高地址+1
;
;------------------------------------------------------------------------------
;
; Page Definition for Using the Compact Model with 64 KByte xdata RAM. 使用COMPACT存储器模式时64K字节XDATA存储器空间的分页定义
;
; The following EQU statements define the xdata page used for pdata. 以下用EQU指令定义PDATA类型变量在XDATA存储器空间的页地址
; variables. The EQU PPAGE must conform with the PPAGE control used
; in the linker invocation.
;
PPAGEENABLE EQU 0 ; set to 1 if pdata object are used. 使用PDATA类型变量时将其设置成1
;
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_STAUTUP
?C_C51STARTUP SEGMENT CODE ;代码
?STACK SEGMENT IDATA ;堆栈
RSEG ?STACK
DS 1
EXTRN CODE (?C_START);程序开始地址
PUBLIC ?C_STARTUP
CSEG AT 0 ;用户程序开始地址
?C_STARTUP: LJMP STARTUP1
RSEG ?C_C51STARTUP
STARTUP1: ;单片机上电IDATA内存清零 如果不需要上电清零IDATA 可以注销IF到IFEDN之间的话句或者修改IDTALEN的长度 为了具有掉电保护功能
IF IDATALEN <> 0
MOV R0,#IDATALEN - 1
CLR A
IDATALOOP: MOV @R0,A
DJNZ R0,IDATALOOP
ENDIF
;单片机上电XDATA内存清零 如果不需要上电清零XDATA 可以注销IF到IFEDN之间的话句或者修改IDTALEN的长度 为了具有掉电保护功能
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
;送PDATA存储器页面高位地址
IF PPAGEENABLE <> 0
MOV PPAGE_SFR,#PPAGE
ENDIF
;单片机上电PDATA内存清零 如果不需要上电清零PDATA 可以注销IF到IFEDN之间的话句或者修改PDATALEN的长度
IF PDATALEN <> 0
MOV R0,#LOW (PDATASTART)
MOV R7,#LOW (PDATALEN)
CLR A
PDATALOOP: MOVX @R0,A
INC R0
DJNZ R7,PDATALOOP
ENDIF