[技术问答] STARTUP.A51是干啥用的?

[复制链接]
1868|3
 楼主| 小明的同学 发表于 2018-10-22 17:46 | 显示全部楼层 |阅读模式
看到BSP里有这个文件,好像每个项目都用。
 楼主| 小明的同学 发表于 2018-10-22 17:46 | 显示全部楼层
  1. $NOMOD51
  2. ;------------------------------------------------------------------------------
  3. ;  This file is part of the C51 Compiler package
  4. ;  Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
  5. ;------------------------------------------------------------------------------
  6. ;  STARTUP.A51:  This code is executed after processor reset.
  7. ;
  8. ;  To translate this file use A51 with the following invocation:
  9. ;
  10. ;     A51 STARTUP.A51
  11. ;
  12. ;  To link the modified STARTUP.OBJ file to your application use the following
  13. ;  BL51 invocation:
  14. ;
  15. ;     BL51 <your object file list>, STARTUP.OBJ <controls>
  16. ;
  17. ;------------------------------------------------------------------------------
  18. ;
  19. ;  User-defined Power-On Initialization of Memory
  20. ;
  21. ;  With the following EQU statements the initialization of memory
  22. ;  at processor reset can be defined:
  23. ;
  24. ;               ; the absolute start-address of IDATA memory is always 0
  25. IDATALEN        EQU     80H     ; the length of IDATA memory in bytes.
  26. ;
  27. XDATASTART      EQU     0H      ; the absolute start-address of XDATA memory
  28. XDATALEN        EQU     2FFH     ; the length of XDATA memory in bytes.
  29. ;
  30. PDATASTART      EQU     0H      ; the absolute start-address of PDATA memory
  31. PDATALEN        EQU     0H      ; the length of PDATA memory in bytes.
  32. ;
  33. ;  Notes:  The IDATA space overlaps physically the DATA and BIT areas of the
  34. ;          8051 CPU. At minimum the memory space occupied from the C51
  35. ;          run-time routines must be set to zero.
  36. ;------------------------------------------------------------------------------
  37. ;
  38. ;  Reentrant Stack Initilization
  39. ;
  40. ;  The following EQU statements define the stack pointer for reentrant
  41. ;  functions and initialized it:
  42. ;
  43. ;  Stack Space for reentrant functions in the SMALL model.
  44. IBPSTACK        EQU     0       ; set to 1 if small reentrant is used.
  45. IBPSTACKTOP     EQU     0FFH+1  ; set top of stack to highest location+1.
  46. ;
  47. ;  Stack Space for reentrant functions in the LARGE model.      
  48. XBPSTACK        EQU     0       ; set to 1 if large reentrant is used.
  49. XBPSTACKTOP     EQU     0FFFFH+1; set top of stack to highest location+1.
  50. ;
  51. ;  Stack Space for reentrant functions in the COMPACT model.   
  52. PBPSTACK        EQU     0       ; set to 1 if compact reentrant is used.
  53. PBPSTACKTOP     EQU     0FFFFH+1; set top of stack to highest location+1.
  54. ;
  55. ;------------------------------------------------------------------------------
  56. ;
  57. ;  Page Definition for Using the Compact Model with 64 KByte xdata RAM
  58. ;
  59. ;  The following EQU statements define the xdata page used for pdata
  60. ;  variables. The EQU PPAGE must conform with the PPAGE control used
  61. ;  in the linker invocation.
  62. ;
  63. PPAGEENABLE     EQU     0       ; set to 1 if pdata object are used.
  64. ;
  65. PPAGE           EQU     0       ; define PPAGE number.
  66. ;
  67. PPAGE_SFR       DATA    0A0H    ; SFR that supplies uppermost address byte
  68. ;               (most 8051 variants use P2 as uppermost address byte)
  69. ;
  70. ;------------------------------------------------------------------------------

  71. ; Standard SFR Symbols
  72. ACC     DATA    0E0H
  73. B       DATA    0F0H
  74. SP      DATA    81H
  75. DPL     DATA    82H
  76. DPH     DATA    83H



  77.                 NAME    ?C_STARTUP


  78. ?C_C51STARTUP   SEGMENT   CODE
  79. ?STACK          SEGMENT   IDATA

  80.                 RSEG    ?STACK
  81.                 DS      1

  82.                 EXTRN CODE (?C_START)
  83.                 PUBLIC  ?C_STARTUP

  84.                 CSEG    AT      0
  85. ?C_STARTUP:     LJMP    STARTUP1

  86.                 RSEG    ?C_C51STARTUP

  87. STARTUP1:
  88. ;Disable POR
  89.         MOV 0C7H,#0AAH
  90.         MOV 0C7H,#55H
  91.         MOV 0FDH,#5AH
  92.        
  93.         MOV 0C7H,#0AAH
  94.         MOV 0C7H,#55H
  95.         MOV 0FDH,#0A5H

  96. IF IDATALEN <> 0
  97.                 MOV     R0,#IDATALEN - 1
  98.                 CLR     A
  99. IDATALOOP:      MOV     @R0,A
  100.                 DJNZ    R0,IDATALOOP
  101. ENDIF

  102. IF XDATALEN <> 0
  103.                 MOV     DPTR,#XDATASTART
  104.                 MOV     R7,#LOW (XDATALEN)
  105.   IF (LOW (XDATALEN)) <> 0
  106.                 MOV     R6,#(HIGH (XDATALEN)) +1
  107.   ELSE
  108.                 MOV     R6,#HIGH (XDATALEN)
  109.   ENDIF
  110.                 CLR     A
  111. XDATALOOP:      MOVX    @DPTR,A
  112.                 INC     DPTR
  113.                 DJNZ    R7,XDATALOOP
  114.                 DJNZ    R6,XDATALOOP
  115. ENDIF

  116. IF PPAGEENABLE <> 0
  117.                 MOV     PPAGE_SFR,#PPAGE
  118. ENDIF

  119. IF PDATALEN <> 0
  120.                 MOV     R0,#LOW (PDATASTART)
  121.                 MOV     R7,#LOW (PDATALEN)
  122.                 CLR     A
  123. PDATALOOP:      MOVX    @R0,A
  124.                 INC     R0
  125.                 DJNZ    R7,PDATALOOP
  126. ENDIF

  127. IF IBPSTACK <> 0
  128. EXTRN DATA (?C_IBP)

  129.                 MOV     ?C_IBP,#LOW IBPSTACKTOP
  130. ENDIF

  131. IF XBPSTACK <> 0
  132. EXTRN DATA (?C_XBP)

  133.                 MOV     ?C_XBP,#HIGH XBPSTACKTOP
  134.                 MOV     ?C_XBP+1,#LOW XBPSTACKTOP
  135. ENDIF

  136. IF PBPSTACK <> 0
  137. EXTRN DATA (?C_PBP)
  138.                 MOV     ?C_PBP,#LOW PBPSTACKTOP
  139. ENDIF

  140.                 MOV     SP,#?STACK-1
  141. ; This code is required if you use L51_BANK.A51 with Banking Mode 4
  142. ; EXTRN CODE (?B_SWITCH0)
  143. ;               CALL    ?B_SWITCH0      ; init bank mechanism to code bank 0
  144.                 LJMP    ?C_START

  145.                 END
 楼主| 小明的同学 发表于 2018-10-22 17:46 | 显示全部楼层
里面是一堆汇编程序,不知道啥,没学过汇编看不懂。
稳稳の幸福 发表于 2018-10-22 18:40 | 显示全部楼层
startup.a51是keil C51的启动代码,keil的库文件里面已经有一个默认的启动代码了,如果你的工程里没有启动代码,keil就会使用库里的默认启动代码,如果有,keil就会编译并使用你的启动代码,库里的启动代码会被忽略。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

159

主题

1640

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部