Startup. A51 annotations

Source: Internet
Author: User
------------------------------------------------------------------------------
; Startup. A51: initialization program for user power-on
;------------------------------------------------------------------------------
;
User-Defined memory space for power-on Initialization
;
Use the following equ command to define the memory space to be initialized when the CPU is reset.
;
; The absolute starting address of the idata storage space is always 0.
Idatalen equ 80 h; number of bytes in the idata storage space initialized with 0 Required
;
Xdatastart equ 0 h; absolute start address of the xdata storage space
Xdatalen equ 0 h; the number of space bytes in the xdata memory that need to be initialized with 0.
;
Pdatastart equ 0 h; absolute start address of the pdata storage space
Pdatalen equ 0 h; the number of pdata storage space bytes initialized with 0.
;
Note: The idata storage space includes the data and bit storage space of the 8051 microcontroller physically.
I heard that at least ensure that the memory space related to the running library of the C51 compiler is initialized by 0.
;------------------------------------------------------------------------------
;
; Re-entry function simulation Initialization
;
The following uses the equ command to define the initialization of the re-entry function simulation Stack pointer
;
; The stack space of the re-entry function when small memory mode is used.
Ibpstack equ 0; set it to 1 when the small memory mode is used for re-entry function.
Ibpstacktop equ 0ffh + 1; set the top of the stack to the highest address + 1.
;
The stack space of the re-entry function when large memory mode is used.
Xbpstack equ 0; set it to 1 when the large memory mode is used for re-entry function.
Xbpstacktop equ 0 ffffh + 1; set the top of the stack to the highest address + 1.
;
The stack space of the re-entry function when the Compact memory mode is used.
Pbpstack equ 0; set it to 1 when the Compact memory mode is used for re-entry functions.
Pbpstacktop equ 0 ffffh + 1; set the top of the stack to the highest address + 1.
;
;------------------------------------------------------------------------------
;
The paging definition of 64 K Bytes xdata memory space when compact memory mode is used
;
The following uses the equ command to define the page address of the pdata type variable in the xdata storage space
When pfage is defined using the equ command, it must be consistent with the control parameter of the l51 connection locator pdata command.
;
Ppageenable equ 0; set it to 1 when pdata type variable is used.
Ppage equ 0; defines the page number.
;
;------------------------------------------------------------------------------
Name? C_startup; Module name? C_stautup
? C_c51startup segment Code; Code
? Stack segment idata; stack
Rseg? Stack
If any Chinese character can be used, correct it if it is wrong.
Welcome to the homepage of laid-off farmers
DS 1
Extrn code (? C_start); program start address
Public? C_startup
Cseg at 0x8000; defines the starting address of the user program, which may be useful when using the mon51 Simulator
? C_startup: ljmp startup1
Rseg? C_c51startup
Startup1:
;
; Initialize the serial port
MoV scon, #40 h
MoV tmod, #20 h
MoV Th1, # 0fdh
SETB tr1
CLR Ti
Single-Chip Microcomputer power-on idata memory reset if no power-on Reset idata can be deregistered if to ifedn sentence
Or modify the length of idtalen to have the power-down protection function. I don't know how long the idtalen is.
If idatalen <> 0
MoV r0, # idatalen-1
CLR
Idataloop: mov @ r0,
Djnz r0, idataloop
Endif
;
Single-Chip Microcomputer power-on xdata memory reset if no power-on Reset xdata can be deregistered if to ifedn sentence
Or modify the length of xdatalen.
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
Xdataloop: movx @ dptr,
INC dptr
Djnz R7, xdataloop
Djnz R6, xdataloop
Endif
;
; Send pdata Memory Page high address
If ppageenable <> 0
MoV P2, # ppage
Endif
;
Single-Chip Microcomputer power-on pdata memory reset if no power-on Reset xdata can be deregistered if to ifedn sentence
Or modify the pdatalen length.
If pdatalen <> 0
MoV r0, # pdatastart
MoV R7, # Low (pdatalen)

CLR
Pdataloop: movx @ r0,
INC R0
Djnz R7, pdataloop
Endif
;
Set the stack space of the re-entry function when small memory mode is used.
If ibpstack <> 0
Extrn data (? C_ibp)
MoV? C_ibp, # Low ibpstacktop
Endif
;
Set the stack space of the re-entry function when large memory mode is used.
If xbpstack <> 0
Extrn data (? C_xbp)
MoV? C_xbp, # High xbpstacktop
MoV? C_xbp + 1, # Low xbpstacktop
Endif
;
Set the stack space of the re-entry function when the Compact memory mode is used.
If pbpstack <> 0
Extrn data (? C_pbp)
MoV? C_pbp, # Low pbpstacktop
Endif
;
; Set the starting address of the stack
MoV sp ,#? Stack-1; for example mov sp, # 4fh
;
; This code is required if you use l51_bank.a51 with banking Mode 4
If your program uses the mode 4 program grouping technology, start the following program.
; Extrn code (? B _switch0)
; Call? B _switch0; init bank mechanic to code bank 0
The program starts from the first group of bank 0
Jump to the main function of the user program
Ljmp? C_start
End
; Linshengfeng

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.