关于Keil C软件的问题:请问用该软件编写单片机的C程序时或汇编程序时,里面那个START UP文件是干什么用的

如题所述

是初始化文件,初始化单片机,然后跳转到你的主程序开始执行。

给你一篇参考文档。http://zhishangsixia.blog.163.com/blog/static/116883245201031995415219/
这只是笔者所使用版本中的一个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 <your object file list>, STARTUP.OBJ <controls>
;
;------------------------------------------------------------------------------
;
; User-defined Power-On Initialization of Memory
; 用户上电初始化程序
; With the following EQU statements the initialization of memory
; at processor reset can be defined:
;使用以下的EQU命令定义在CPU复位时初始化的内存空间即清零
; ; the absolute start-address of IDATA memory is always 0
IDATALEN EQU 80H ; the length of IDATA memory in bytes.
;定义用0初始化的内部数据存储器长度以字节计

XDATASTART EQU 0H ; the absolute start-address of XDATA memory

;定义外部数据存储器的绝对起始地址
XDATALEN EQU 0H ; the length of XDATA memory in bytes.
;定义用0初始化的内部数据存储器长度,以字节计

PDATASTART EQU 0H ; the absolute start-address of PDATA memory

;;定义分页的外部数据存储器的绝对起始地址

PDATALEN EQU 0H ; the length of PDATA memory in bytes.

;定义用0初始化的分页外部数据存储器长度,以字节计
; 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.
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.

; 使用SMALL存储器模式再入函数时将其设置成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.
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
;
; 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)
;
;------------------------------------------------------------------------------

; 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:
;一下四个IF-ENDIF为数据区清零的程序段
IF IDATALEN <> 0
MOV R0,#IDATALEN - 1
CLR A
IDATALOOP: MOV @R0,A
DJNZ R0,IDATALOOP
ENDIF

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

IF PPAGEENABLE <> 0
MOV PPAGE_SFR,#PPAGE
ENDIF

IF PDATALEN <> 0
MOV R0,#LOW (PDATASTART)
MOV R7,#LOW (PDATALEN)
CLR A
PDATALOOP: MOVX @R0,A
INC R0
DJNZ R7,PDATALOOP
ENDIF
; 下一IF-ENDIF函数设置使用SMALL存储器模式时再入函数的堆栈空间.
IF IBPSTACK <> 0
EXTRN DATA (?C_IBP)

MOV ?C_IBP,#LOW IBPSTACKTOP
ENDIF
; 下一IF-ENDIF函数设置使用LARGE存储器模式时再入函数的堆栈空间.
IF XBPSTACK <> 0
EXTRN DATA (?C_XBP)

MOV ?C_XBP,#HIGH XBPSTACKTOP
MOV ?C_XBP+1,#LOW XBPSTACKTOP
ENDIF
; 下一IF-ENDIF函数设置使用COMPACT存储器模式时再入函数的堆栈空间.
IF PBPSTACK <> 0
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
;上一语句使程序跳转至用户的main()函数
END

参考资料:http://zhishangsixia.blog.163.com/blog/static/116883245201031995415219/

温馨提示:答案为网友推荐,仅供参考