C8051FXX启动文件详细注释

来源:互联网 发布:mysql 合计 编辑:程序博客网 时间:2024/06/05 21:14


原始文件:
$NOMOD51;------------------------------------------------------------------------------;  This file is part of the C51 Compiler package;  Copyright (c) 1988-2005 Keil Elektronik GmbH and Keil Software, Inc.;  Version 8.01;;  *** <<< Use Configuration Wizard in Context Menu >>> ***;------------------------------------------------------------------------------;  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;  Lx51 invocation:;;     Lx51 your object file list, STARTUP.OBJ  controls;;------------------------------------------------------------------------------;;  User-defined <h> Power-On Initialization of Memory;;  With the following EQU statements the initialization of memory;  at processor reset can be defined:;; <o> IDATALEN: IDATA memory size <0x0-0x100>;     <i> Note: The absolute start-address of IDATA memory is always 0;     <i>       The IDATA space overlaps physically the DATA and BIT areas.IDATALEN        EQU     80H;; <o> XDATASTART: XDATA memory start address <0x0-0xFFFF> ;     <i> The absolute start address of XDATA memoryXDATASTART      EQU     0     ;; <o> XDATALEN: XDATA memory size <0x0-0xFFFF> ;     <i> The length of XDATA memory in bytes.XDATALEN        EQU     0      ;; <o> PDATASTART: PDATA memory start address <0x0-0xFFFF> ;     <i> The absolute start address of PDATA memoryPDATASTART      EQU     0H;; <o> PDATALEN: PDATA memory size <0x0-0xFF> ;     <i> The length of PDATA memory in bytes.PDATALEN        EQU     0H;;</h>;------------------------------------------------------------------------------;;<h> Reentrant Stack Initialization;;  The following EQU statements define the stack pointer for reentrant;  functions and initialized it:;; <h> Stack Space for reentrant functions in the SMALL model.;  <q> IBPSTACK: Enable SMALL model reentrant stack;     <i> Stack space for reentrant functions in the SMALL model.IBPSTACK        EQU     0       ; set to 1 if small reentrant is used.;  <o> IBPSTACKTOP: End address of SMALL model stack <0x0-0xFF>;     <i> Set the top of the stack to the highest location.IBPSTACKTOP     EQU     0xFF +1     ; default 0FFH+1  ; </h>;; <h> Stack Space for reentrant functions in the LARGE model.      ;  <q> XBPSTACK: Enable LARGE model reentrant stack;     <i> Stack space for reentrant functions in the LARGE model.XBPSTACK        EQU     0       ; set to 1 if large reentrant is used.;  <o> XBPSTACKTOP: End address of LARGE model stack <0x0-0xFFFF>;     <i> Set the top of the stack to the highest location.XBPSTACKTOP     EQU     0xFFFF +1   ; default 0FFFFH+1 ; </h>;; <h> Stack Space for reentrant functions in the COMPACT model.    ;  <q> PBPSTACK: Enable COMPACT model reentrant stack;     <i> Stack space for reentrant functions in the COMPACT model.PBPSTACK        EQU     0       ; set to 1 if compact reentrant is used.;;   <o> PBPSTACKTOP: End address of COMPACT model stack <0x0-0xFFFF>;     <i> Set the top of the stack to the highest location.PBPSTACKTOP     EQU     0xFF +1     ; default 0FFH+1  ; </h>;</h>;------------------------------------------------------------------------------;;  Memory Page for Using the Compact Model with 64 KByte xdata RAM;  <e>Compact Model Page Definition;;  <i>Define the XDATA page used for PDATA variables. ;  <i>PPAGE must conform with the PPAGE set in the linker invocation.;; Enable pdata memory page initalizationPPAGEENABLE     EQU     0       ; set to 1 if pdata object are used.;; <o> PPAGE number <0x0-0xFF> ; <i> uppermost 256-byte address of the page used for PDATA variables.PPAGE           EQU     0;; <o> SFR address which supplies uppermost address byte <0x0-0xFF> ; <i> most 8051 variants use P2 as uppermost address bytePPAGE_SFR       DATA    0A0H;; </e>;------------------------------------------------------------------------------; Standard SFR Symbols ACC     DATA    0E0HB       DATA    0F0HSP      DATA    81HDPL     DATA    82HDPH     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?C_STARTUP:     LJMP    STARTUP1                RSEG    ?C_C51STARTUPSTARTUP1:IF IDATALEN <> 0                MOV     R0,#IDATALEN - 1                CLR     AIDATALOOP:      MOV     @R0,A                DJNZ    R0,IDATALOOPENDIFIF 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     AXDATALOOP:      MOVX    @DPTR,A                INC     DPTR                DJNZ    R7,XDATALOOP                DJNZ    R6,XDATALOOPENDIFIF PPAGEENABLE <> 0                MOV     PPAGE_SFR,#PPAGEENDIFIF PDATALEN <> 0                MOV     R0,#LOW (PDATASTART)                MOV     R7,#LOW (PDATALEN)                CLR     APDATALOOP:      MOVX    @R0,A                INC     R0                DJNZ    R7,PDATALOOPENDIFIF IBPSTACK <> 0EXTRN DATA (?C_IBP)                MOV     ?C_IBP,#LOW IBPSTACKTOPENDIFIF XBPSTACK <> 0EXTRN DATA (?C_XBP)                MOV     ?C_XBP,#HIGH XBPSTACKTOP                MOV     ?C_XBP+1,#LOW XBPSTACKTOPENDIFIF PBPSTACK <> 0EXTRN DATA (?C_PBP)                MOV     ?C_PBP,#LOW PBPSTACKTOPENDIF                MOV     SP,#?STACK-1; This code is required if you use L51_BANK.A51 with Banking Mode 4;<h> Code Banking; <q> Select Bank 0 for L51_BANK.A51 Mode 4#if 0   ;     <i> Initialize bank mechanism to code bank 0 when using L51_BANK.A51 with Banking Mode 4.EXTRN CODE (?B_SWITCH0)                CALL    ?B_SWITCH0      ; init bank mechanism to code bank 0#endif;</h>                LJMP    ?C_START                END


/××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××/


$NOMOD51                                 ;使编译器不使能预定义的8051符号,避免产生重复定义的错误。
;------------------------------------------------------------------------------
;  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 <your object file list>, STARTUP.OBJ <controls>
;     BL51是Keil使用的链接器(Linker),这是命令行的使用格式,一般不用,使用IDE环境,用project管理,有相应的按钮可以实现该功能.
;------------------------------------------------------------------------------
;
;  User-defined Power-On Initialization of Memory ---  初始化RAM单元
;
;  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.---根据你选用的芯片可以适当的修改这些值 
;
XDATASTART      EQU     0H      ; the absolute start-address of XDATA memory--以下两项根据目标系统的外设配置和连接自己修改  
XDATALEN        EQU     0H      ; the length of XDATA memory in bytes.
;
PDATASTART      EQU     0H      ; the absolute start-address of PDATA memory
PDATALEN        EQU     0H      ; the length of PDATA memory in 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   --注意的再入堆栈的方向区别的芯片自带的堆栈的生长方式,自顶向下生长的!而SP是是自底向上的!        
;   --且再入堆栈是由编译器自己管理的,一般不必去关心,只是在有再入函数的时候,根据函数的存储器模式使用相应的RAM空间做为再入堆栈。 
;  The following EQU statements define the stack pointer for reentrant
;  functions and initialized it:
;Keil C默认情况不是用堆栈来传递参数的,所以造成函数不可重入,Keil要求用户显示声明函数是否具有可重入属性,以便为C函数调用初始化栈。
;  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.
;不同内存模式下的堆栈。Keil 编译器中有三种模式设置:
;Small:所有的变量都放在内部RAM区
;Compact:所有变量在默认情况下都会放在外部RAM的低256字节中(可由R0寻址)
;Large:所有变量都放在外部RAM中(DPTR寻址)
;这是由51处理器繁多的寻址模式导致的,不同的寻址模式有不同的效率
;
;------------------------------------------------------------------------------
;
;  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 are 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) 很多的外部页面寻址以P2口为高位地址的数值,有使用外部页面RAM的情况
;     对PPAGEENABLE 设置为1 ,根据硬件连接修改PPAGE的值。
;------------------------------------------------------------------------------

; Standard SFR Symbols 
ACC     DATA    0E0H        ;关键字DATA  A51伪指令定义单片机内部数据存储器字节地址的符号
B       DATA    0F0H
SP      DATA    81H
DPL     DATA    82H
DPH     DATA    83H

                NAME    ?C_STARTUP   ;定义当前程序模块的目标模块名


?C_C51STARTUP   SEGMENT   CODE       ;定义一个可再定位的段符号名和段所在的存储空间,汇编器产生的这个段符号名在BL51/L51连接定位时用
?STACK          SEGMENT   IDATA      ;定义一个IDATA段,段名?STACK ,符合C51编译器的命名规则

                RSEG    ?STACK        ;声明当前段是IDATA段,段中保留空间。
                DS      1

                EXTRN CODE (?C_START)  ;声明本模块引用的外部全局符号,用于和C相连接在.src文件中可以看到这个符号 
                PUBLIC  ?C_STARTUP     ;声明可被其他模块使用的全局符号,由.src文件中可以看出这个符号的作用。

                CSEG    AT      0      ;结束当前的IDATA段,产生一个位于CODE中新段,起始地址是0000H。代码段的起始点 
?C_STARTUP:     LJMP    STARTUP1       ;C编译器编译源程序后,芯片复位之后的复位代码第一个就是执行这条语句。

                RSEG    ?C_C51STARTUP  ;选择段名为?C_C51STARTUP的CODE段为当前段,存储程序代码。

STARTUP1:

IF IDATALEN <> 0                      ;条件汇编指令,有IDATA区的话,清IDATA区。
                MOV     R0,#IDATALEN - 1
                CLR     A
IDATALOOP:      MOV     @R0,A
                DJNZ    R0,IDATALOOP
ENDIF

IF XDATALEN <> 0                      ;如果有外部数据区,则把外部数据区中从XDATASTART到XDATASTART+ XDATALEN的区域清零
                MOV     DPTR,#XDATASTART
                MOV     R7,#LOW (XDATALEN)
  IF (LOW (XDATALEN)) <> 0
                MOV     R6,#(HIGH (XDATALEN)) +1 ;如果低地址是零,一个高地址就代表256字节
  ELSE
                MOV     R6,#HIGH (XDATALEN)
  ENDIF
                CLR     A
XDATALOOP:      MOVX    @DPTR,A
                INC     DPTR
                DJNZ    R7,XDATALOOP
                DJNZ    R6,XDATALOOP
ENDIF

IF PPAGEENABLE <> 0                   ;清外部页RAM区域
                MOV     PPAGE_SFR,#PPAGE ;给P2口赋相应的值,根据用户自己的目标系统。
ENDIF

IF PDATALEN <> 0                     ;清外部页RAM区域
                MOV     R0,#LOW (PDATASTART)
                MOV     R7,#LOW (PDATALEN)
                CLR     A
PDATALOOP:      MOVX    @R0,A
                INC     R0
                DJNZ    R7,PDATALOOP
ENDIF

IF IBPSTACK <> 0                      ;使用再入堆栈的情况,用户自己在程序中定义函数的存储模式。
                                      ; C51定义了三个全局变量,?C_IBP,?C_XBP,?C_PBP来存储再入堆栈的栈顶地址
EXTRN DATA (?C_IBP)                   ; 声明本模块使用的外部全局符号,符号的段类型限制了符号的使用范围,而符号本身则代表的是一个RAM单元的地址址

                MOV     ?C_IBP,#LOW IBPSTACKTOP
ENDIF                                  

IF XBPSTACK <> 0                      ;函数是Large存储模式的时候,存储再入堆栈的区域。
EXTRN DATA (?C_XBP)                   ;

                MOV     ?C_XBP,#HIGH XBPSTACKTOP
                MOV     ?C_XBP+1,#LOW XBPSTACKTOP
ENDIF

IF PBPSTACK <> 0                      ;函数是Compact模式的时候,存储再入堆栈栈顶地址的存储单元和栈的利用空间
EXTRN DATA (?C_PBP)                   ;
                MOV     ?C_PBP,#LOW PBPSTACKTOP
ENDIF

                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       ;把执行的权力交给C主函数。

                END

0 0