home *** CD-ROM | disk | FTP | other *** search
- ;-----------------------------------------------------;
- ; ;
- ; CSTARTUP.S03 ;
- ; ;
- ; This module contains the 8051 C startup-routine and ;
- ; must usually be tailored to suit customer hardware. ;
- ; Version: 2.00 [A.R. 10/Jun/87] ;
- ;-----------------------------------------------------;
- NAME CSTARTUP
-
- LSTWID+ ; XXX -- to see INCLUDE files more easily
-
- ;$DEFMM.INC ; define memory model
- $\C51V2\DEFEM.INC ; define memory model -- XXX Extended Memory Model
-
- PUBLIC exit
- EXTERN _R ; Register bank (0, 8, 16 or 24)
- EXTERN main
-
- ;--------------------------------------------------------------;
- ; Virtual stack segment. It should be mapped into external RAM ;
- ;--------------------------------------------------------------;
- IF single_chip = 0
-
- RSEG XSTACK
- DS 512 ; Change if needed
- xstack_end:
- ENDIF
-
- ;--------------------------------------------------------------;
- ; Internal stack used for LCALL's and temporary storage for ;
- ; code generator help-routines (math etc). Stack can be loca- ;
- ; ted anywhere in the internal RAM with the exception of ;
- ; _R - _R+7 that are reserved for R0-R7. Note that C interrupt ;
- ; routines require that you increase stack by 25 bytes to ;
- ; assure that no overflows occur. ;
- ;--------------------------------------------------------------;
- RSEG ISTACK
- stack_begin:
- IF single_chip
- DS 150
- ELSE
- DS 20
- ENDIF
-
- RSEG CSTART
- startup: ; Should be at location zero
- ; SJMP init_C
- LJMP init_C ; XXX -- I guess because increased size for
- ; interrupt vectors
- ; DS 20 ; Space for 8051 vectors
- DS 256 ; Space for MCS-51 vectors -- XXX
- ; Note that highest interrupt vector address
- ; for 83C152 is 0x53 (83 decimal). The value
- ; specified here should be chosen to allow for
- ; the processor with the highest interrupt
- ; vector address.
- ; 100 decimal == 0x064
- ; 128 decimal == 0x080
- ; 256 decimal == 0x100
- ;--------------------------------------------------------------;
- ; This is the place to insert interrupt vectors/handlers in. ;
- ; For locations consult the Intel Microcontroller Handbook. ;
- ;--------------------------------------------------------------;
-
- init_C:
- ;---------------------------------------------------------------;
- ; Ativate the (at link-time) selected register bank. ;
- ;---------------------------------------------------------------;
-
- MOV A,#_R
- MOV C,ACC.3
- MOV PSW.3,C
- MOV C,ACC.4
- MOV PSW.4,C
-
- MOV SP,#stack_begin ; From low to high addresses
- ;--------------------------------------------------------------;
- ; If you don't want global/static C variables to be initial- ;
- ; ized at startup you can just remove the next two lines. ;
- ; NOTE: Never remove the call in the large models (-m0 or -m1) ;
- ;--------------------------------------------------------------;
-
- EXTERN ?SEG_INIT_L17
- LCALL ?SEG_INIT_L17 ; Initialize segments
-
- ;--------------------------------------------------------------;
- ; If hardware must be initiated from assembly or if interrupts ;
- ; should be on when reaching main, this is the place to insert ;
- ; such code. ;
- ;--------------------------------------------------------------;
-
- IF single_chip
-
- MOV R1,#0
- LCALL main ; main()
- exit: ; someone called exit()
-
- ELSE
-
- MOV R6,#HIGH(xstack_end)
- MOV R7,#LOW(xstack_end)
-
- IF banked_mode
-
- EXTERN ?X_CALL_L18
-
- MOV DPTR,#main
- LCALL ?X_CALL_L18 ; main()
- DW 0 ; No parameter space
- local_exit: ; someone called exit()
-
- ELSE
-
- MOV DPTR,#0 ; No parameters
-
- LCALL main ; main()
- exit: ; someone called exit()
-
- ENDIF
-
- ENDIF
-
- ;--------------------------------------------------------------;
- ; Now when we are ready with our C program (usually 8051 C ;
- ; programs are continouous) we must perform a system-dependent ;
- ; action. In this simple case we just stop. ;
- ;--------------------------------------------------------------;
-
- SJMP $ ; Forever...
-
- IF banked_mode
-
- RSEG FLIST
- exit:
- DD local_exit
-
- ENDIF
-
- END startup
-
-