⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 startup400.a51

📁 基于DS80C400的ADz转换程序
💻 A51
字号:
; ---------------------------------------------------------------------------
;  Copyright (C) 2003-2005 Dallas Semiconductor Corporation, All Rights Reserved.
; 
;  Permission is hereby granted, free of charge, to any person obtaining a
;  copy of this software and associated documentation files (the "Software"),
;  to deal in the Software without restriction, including without limitation
;  the rights to use, copy, modify, merge, publish, distribute, sublicense,
;  and/or sell copies of the Software, and to permit persons to whom the
;  Software is furnished to do so, subject to the following conditions:
; 
;  The above copyright notice and this permission notice shall be included
;  in all copies or substantial portions of the Software.
; 
;  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
;  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;  MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
;  IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
;  OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
;  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
;  OTHER DEALINGS IN THE SOFTWARE.
; 
;  Except as contained in this notice, the name of Dallas Semiconductor
;  shall not be used except as stated in the Dallas Semiconductor
;  Branding Policy.
; ---------------------------------------------------------------------------

; ---------------------------------------------------------------------------
; Startup Code Version 8
; ---------------------------------------------------------------------------

$NOMOD51

#include <REG390.H>

;****************************************************************************
; 
; BEGIN CONFIGURABLE OPTIONS
;
; Set INITIALIZE_SERIAL0 to 0 to disable initialization of serial port 0.
; Disabling serial port 0 initialization will also disable the printing of
; the copyright message in init_rom(). When disabled, you must initialize
; serial port 0 yourself and/or override the C putchar() function if you
; want putchar(), puts(), or printf() to work.
;
$set (INITIALIZE_SERIAL0 = 1)


;
; Set USE_MONITOR to 0 to configure this program to load into bank 40 (flash on TINIm400)
; Set USE_MONITOR to 1 to configure this program to load into bank 20 (RAM on TINIm400)
;     where it is suitable for use by the Keil monitor.
;
$set (USE_MONITOR = 0)

;
; Set XTALMULT to 2 or 4 to use the crystal doubler or quadrupler.
; Set XTALMULT to 1 to use the default.  Do not use other
; values for XTALMULT.
;
$set (XTALMULT = 1)

;
; Set the OSCILLATOR_FREQ value to the value of the oscillator you are using.
; The TINIm400 uses a 14745600 Hz oscillator.  DO NOT CHANGE THIS VALUE TO
; REFLECT THE USE OF THE CRYSTAL MULTIPLIER.
;
OSCILLATOR_FREQ equ 14745600

;
; Set SERIAL0_BAUDRATE to the baud rate you want to get standard output at.
; Default is 115200.
;
SERIAL0_BAUDRATE equ 115200

;
; Set USE_REENTRANT_STACK to 1 to use Keil's reentrant stack (allows 
; recursive function calls).  Set REENTRANT_STACK_TOP to the top of the 
; reentrant stack if USE_REENTRANT_STACK is 1.
; REENTRANT_STACK_TOP cannot be greater than 0FFFFh and is always located
; in the first 64KB of the XDATA segment, regardless of the size of XDATA.
; Make sure the reentrant stack does not conflict with the XDATA project
; settings and variables. It is a good idea to declare the reentrant stack
; as an xdata application variable to prevent the linker from allocating
; the xdata space for other variables. For example, add the following to
; your C source:
; 
;    #define REENTRANT_STACK_TOP 0xffff
;
;    /* Total size of the reentrant stack the application uses. */
;    #define REENTRANT_STACK_SIZE 16386
;
;    /* Prevent the linker from using the stack space */
;    #define REENTRANT_STACK_LOC REENTRANT_STACK_TOP-REENTRANT_STACK_SIZE
;    static char xdata _reentrant_stack[REENTRANT_STACK_SIZE] _at_ REENTRANT_STACK_LOC;
;
; You must call task_reentrant_stack(size) for each task that has functions
; declared as "reentrant".
; See the reentrant stack sample application for a demonstration of the
; reentrant stack.
;
$set (USE_REENTRANT_STACK = 0)
REENTRANT_STACK_TOP equ 0FFFFh

;
; Set SETMAC to 1 to give the TINI a specific MAC ID as defined by 
; the equates MAC_MSB, MAC_5, ..., MAC_LSB.  Set SETMAC to 2 to
; set registers r5:r4:r3:r2:r1:r0 to your own MAC ID (see 'User MAC Code'
; below).  Use a SETMAC of 0 to find the MAC in a 2502-E48.
; (Note: You also have to call init_setclock() if there is no 2502-E48.)
;
$set (SETMAC = 0)

MAC_MSB equ 00h
MAC_5   equ 60h
MAC_4   equ 62h
MAC_3   equ 63h
MAC_2   equ 64h
MAC_1   equ 65h
MAC_LSB equ 67h

;
; Change ERASE_IDATA to erase the internal data memory before the program begins. 
;
ERASE_IDATA     equ     100h    ; the amount of IDATA memory to erase

;
; Change length from 0 to erase starting at address ERASE_XDATA_ADDR for 
; ERASE_XDATA_LEN bytes.
;
ERASE_XDATA_ADDR equ    0h      ; the absolute start-address of XDATA memory
ERASE_XDATA_LEN  equ    0h      ; the length of XDATA memory in bytes. 

;
; Set INTERNALSRAM to 1 to enable the internal 64KB SRAM on the DS80C410/411.
; (Note: This has no effect on the DS80C400.)
;
$set (INTERNALSRAM = 0)

;
; END OF CONFIGURABLE OPTIONS
;
;****************************************************************************
TIMER_RELOAD equ (65536 - ((OSCILLATOR_FREQ) / (32 * SERIAL0_BAUDRATE)))


$if (USE_REENTRANT_STACK <> 0)
C_XBP_SEG        SEGMENT	DATA AT 070H
        	RSEG	C_XBP_SEG

?C_XBP:        	DSB	2

XBPSTACKTOP     equ REENTRANT_STACK_TOP + 1

Public ?C_XBP
$endif

;
; Direct where the ROM puts the boot status flags
;
BFLAGS        	equ	21h

                name    ?C_STARTUP
                ;
                ; Make sure the compiler does not use the OS flags & bits
                ;
                DSEG at 08h
regbank123:     ds      24

                DSEG AT 20h
wos_flags:      ds      1

                DSEG AT 27h
rom_flags:      ds      1

                DSEG AT 68h
wos_crit_count: ds      1

        	DSEG AT 6Bh
sched_reload:        ds	2
curr_pc:        ds      3

                DSEG AT 72h
sched:          ds      3
ms_count:       ds      5

        	DSEG AT 7Ah
xbp_loc:        ds	1

                DSEG AT 7Bh
hb_chandle:     ds      5

                ISEG AT 80h
hb_open_cache:  ds      6


                extrn code (?C_START)
                public  ?C_STARTUP

$if (USE_MONITOR = 0)
?C_CPURESET?0   segment code at 400000H
$endif
$if (USE_MONITOR = 1)
?C_CPURESET?0   segment code at 200000H
$endif

                rseg    ?C_CPURESET?0
?C_STARTUP:     sjmp    past_loader_tag
                db     'TINI'                              ; Tag for TINI Environment 1.02c
                                                           ; or later (ignored in 1.02b)
                db      byte2(?C_STARTUP)                  ; Target bank
past_loader_tag:
                clr     ea                                 ; No interrupts, please

$if INTERNALSRAM = 1
        	; 
        	; If DS80C410/DS80C411, optionally enable the internal 64KB SRAM on CE0
        	; and set it to merged code=data.
        	; 
	        mov	a, mcon1
	        anl	a, #01111111b                      ; Clear IRAMD
	        orl	a, #01000000b                      ; Set PRAME
                mov     ta, #0xAA                          ; Enable access to MCON1
                mov     ta, #0x55
	        mov	mcon1, a
$endif

                ;
                ; Make sure we are in contiguous mode
                ;
                mov     ta, #0xAA                          ; Enable access to ACON
                mov     ta, #0x55
                orl     acon, #2                           ; 24 bit mode
                ljmp    far sanity_check                   ; Sanity check: Make sure 24 bit mode is on
sanity_check:
                mov     ta, #0xAA                          ; Enable access to MCON
                mov     ta, #0x55
                mov     mcon, #0xAF                        ; Relocate RAM, data memory
                mov     ta, #0xAA                          ; Enable access to ACON
                mov     ta, #0x55
                orl     acon, #0x04                        ; Extended stack

                ;
                ; Use the minimum number of stretch cycles on MOVX memory
                ;
                anl     ckcon, #0f8h

        	;
        	; Make sure we are in a known state with respect to
        	; our fancy data pointers and register banks
        	;
                mov     dps, #0
                mov     psw, #0

        	;
        	; Set stack to 0 (we lose one byte, but don't
        	; have to know the size)
        	;
                mov     sp,#0
                mov     esp,#0

                ;
                ; Do the Crystal Multiplier
                ;
$if XTALMULT = 2
startup_setxtal_mult_2:
                ;
                ; Multiply crystal frequency by 2
        	;
                mov     pmr, #10000010b                    ; Set for crystal * 2
                mov     pmr, #10010010b                    ; Enable multiplier
WaitCrystal:
                mov     a, exif                            ; Wait for multiplier to be ready
                jnb     acc.3, WaitCrystal                 ; Jump if CKRY is low
                mov     pmr, #00010010b                    ; Go to crystal * 2

$elseif XTALMULT = 4
startup_setxtal_mult_4:
                ;
                ; Multiply crystal frequency by 4
        	;
                mov     pmr, #10000010b                    ; Set to power up value
                mov     pmr, #10001010b                    ; Set for crystal * 4
                mov     pmr, #10011010b                    ; Enable multiplier
WaitCrystal4:
                mov     a, exif                            ; Wait for multiplier to be ready
                jnb     acc.3, WaitCrystal4                ; Jump if CKRY is low
                mov     pmr, #00011010b                    ; Go to crystal * 4
$endif

$if (INITIALIZE_SERIAL0 <> 0)
        	; Enable the serial0, using timer 2 at 115200
                ; Use this equation for the reloads:
                ;     reload H:L = 65536 - (oscillator / (32 * baud))
                ; We now use User Configurable Equates for the serial
        	; port settings.  The default is for 115200, which
        	; yeilds the following:
                ;     65536 - (14745600 / (32 * 115200)) = 65536 - (14745600 / 3686400)
                ;                                        = 65536 - 4
                ;                                        = 65532
                ;                                        = 0xFFFC
                mov     scon0, #5Ah                        ; 10 bit serial 0, use timer baud rate, enable recieving
                mov     rcap2h, #High(TIMER_RELOAD)        ; Set timer reload high byte
                mov     rcap2l, #Low(TIMER_RELOAD)         ; Set timer reload low bye
                mov     t2con, #30h                        ; Enable timer 2 for serial port
                setb    tr2                                ; Set timer 2 to run

                ; Make sure that we can output to the serial port
                setb    ti
$else
        	clr	tr2				   ; Disable serial 0 output if configured by ROM loader
$endif


if ERASE_IDATA <> 0
        	; Save the boot state -- this direct will be saved and cleared by init_romexport
        	push	BFLAGS
                mov     r0, #ERASE_IDATA - 1
                clr     a
erase_idata_loop:
                mov     @r0, a
                djnz    r0, erase_idata_loop
        	pop	BFLAGS
endif

$if (USE_REENTRANT_STACK <> 0)
        	mov	xbp_loc, #?C_XBP
                mov     ?C_XBP,#HIGH XBPSTACKTOP
                mov     ?C_XBP+1,#LOW XBPSTACKTOP
else
        	mov	xbp_loc, #0
$endif


$if SETMAC = 1
                mov     r0, #MAC_LSB
                mov     r1, #MAC_2
                mov     r2, #MAC_3
                mov     r3, #MAC_4
                mov     r4, #MAC_5
                mov     r5, #MAC_MSB

$endif

$if SETMAC = 2
;    
; User MAC Code
;
; Insert code here that will get a MAC address in registers
; r5:r4:r3:r2:r1:r0, with r5 the MSB.
;

$endif

$if SETMAC > 0
        	; Push registers r0 to r5
                push    0
                push    1
                push    2
                push    3
                push    4
                push    5

                mov     a, #'C'
                push    acc
                mov     a, #'A'
                push    acc
                mov     a, #'M'
                push    acc
$endif




IF ERASE_XDATA_LEN <> 0
                mov     dptr, #ERASE_XDATA_ADDR
                mov     r7, #BYTE0 (ERASE_XDATA_LEN)
  IF (BYTE0 (ERASE_XDATA_LEN)) <> 0
                mov     r6, #(BYTE1 ERASE_XDATA_LEN) +1
  ELSE
                mov     r6, #BYTE1 (ERASE_XDATA_LEN)
  ENDIF
  IF (BYTE1 (ERASE_XDATA_LEN)) <> 0
                mov     r5, #(BYTE2 ERASE_XDATA_LEN) +1
  ELSE
                mov     r5, #BYTE2 (ERASE_XDATA_LEN)
  ENDIF
                clr     a
erase_xdata_loop:      
                movx    @dptr, a
                inc     dptr
                djnz    r7, erase_xdata_loop
                djnz    r6, erase_xdata_loop
                djnz    r5, erase_xdata_loop
endif

                ljmp    ?C_START
                end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -