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. 用戶定義需上電初始化的內(nèi)存空間
;
; With the following EQU statements the initialization of memory
; at processor reset can be defined: . 在CPU復(fù)位時(shí),使用以下EQU命令可定義初始化的內(nèi)存空間
;
; ; the absolute start-address of IDATA memory is always 0. IDATA 存儲(chǔ)器的空間的絕對(duì)起始地址總是0
IDATALEN EQU 80H ; the length of IDATA memory in bytes. IDATA存儲(chǔ)器空間初始化大小--80個(gè)bytes
;
XDATASTART EQU 0H ; the absolute start-address of XDATA memory. XDATA存儲(chǔ)器空間的絕對(duì)起始地址0x00
XDATALEN EQU 0H ; the length of XDATA memory in bytes.XDATA存儲(chǔ)器空間初始化大小--0個(gè)bytes
;
PDATASTART EQU 0H ; the absolute start-address of PDATA memory. PDATA存儲(chǔ)器空間的絕對(duì)起始地址0x00
PDATALEN EQU 0H ; the length of PDATA memory in bytes. PDATA存儲(chǔ)器空間初始化大小--0個(gè)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指令定義了堆棧再入函數(shù)和初始化
;
; Stack Space for reentrant functions in the SMALL model.使用SMALL存儲(chǔ)器模式時(shí)再入函數(shù)的堆棧
IBPSTACK EQU 0 ; set to 1 if small reentrant is used. 使用SMALL存儲(chǔ)器模式再入函數(shù)時(shí)將其設(shè)置成1
IBPSTACKTOP EQU 0FFH+1 ; set top of stack to highest location+1. 將堆棧頂設(shè)置為最高地址+1
;
; Stack Space for reentrant functions in the LARGE model.使用LARGE存儲(chǔ)器模式時(shí)再入函數(shù)的堆??臻g
XBPSTACK EQU 0 ; set to 1 if large reentrant is used. 使用LARGE存儲(chǔ)器模式再入函數(shù)時(shí)將其設(shè)置成1
XBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1. 將堆棧頂設(shè)置為最高地址+1
;
; Stack Space for reentrant functions in the COMPACT model.使用COMPACT存儲(chǔ)器模式時(shí)再入函數(shù)的堆??臻g
PBPSTACK EQU 0 ; set to 1 if compact reentrant is used. 使用COMPACT存儲(chǔ)器模式再入函數(shù)時(shí)將其設(shè)置成1
PBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1. 將堆棧頂設(shè)置為最高地址+1
;
;------------------------------------------------------------------------------
;
; Page Definition for Using the Compact Model with 64 KByte xdata RAM. 使用COMPACT存儲(chǔ)器模式時(shí)64K字節(jié)XDATA存儲(chǔ)器空間的分頁(yè)定義
;
; The following EQU statements define the xdata page used for pdata. 以下用EQU指令定義PDATA類型變量在XDATA存儲(chǔ)器空間的頁(yè)地址
; 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類型變量時(shí)將其設(shè)置成1
;
PPAGE EQU 0 ; define PPAGE number. 定義頁(yè)
;
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: ;單片機(jī)上電IDATA內(nèi)存清零 如果不需要上電清零IDATA 可以注銷IF到IFEDN之間的話句或者修改IDTALEN的長(zhǎng)度 為了具有掉電保護(hù)功能
IF IDATALEN <> 0
MOV R0,#IDATALEN - 1
CLR A
IDATALOOP: MOV @R0,A
DJNZ R0,IDATALOOP
ENDIF
;單片機(jī)上電XDATA內(nèi)存清零 如果不需要上電清零XDATA 可以注銷IF到IFEDN之間的話句或者修改IDTALEN的長(zhǎng)度 為了具有掉電保護(hù)功能
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存儲(chǔ)器頁(yè)面高位地址
IF PPAGEENABLE <> 0
MOV PPAGE_SFR,#PPAGE
ENDIF
;單片機(jī)上電PDATA內(nèi)存清零 如果不需要上電清零PDATA 可以注銷IF到IFEDN之間的話句或者修改PDATALEN的長(zhǎng)度
IF PDATALEN <> 0
MOV R0,#LOW (PDATASTART)
MOV R7,#LOW (PDATALEN)
CLR A
PDATALOOP: MOVX @R0,A
INC R0
DJNZ R7,PDATALOOP
ENDIF