Page 240 - Programming Microcontrollers in C
P. 240
Header File 225
OPTION register, and the CONFIG register must be placed in this
location in the program. These registers become read only memory
locations after the first 64 bus cycles following reset.
The value __memory is calculated in the command file
motorfr.lnk and it is the number of bytes of memory that the
program uses for volatile memory. The start of the base memory
section is _sbss and it is zero for this program. The instruction
sequence starting with ldx #__sbss and ending with bne zbcl
will clear all of the volatile memory used by the program. Finally the
stack pointer is set to a value of 0xff and the C program is executed
by the jsr _main call.
.processor m68hc11
;
; C START-UP FOR MC68HC11
;
.external _main, __memory
.public _exit, __stext, __return
;
.psect _bss
__sbss:
.psect _text
__stext:
ldy #4096
bset 1,36,y ; set the prescaler to /4
clra ; reset the bss
ldx #__sbss ; start of bss
bra loop ; start loop
zbcl:
staa 0,x ; clear byte
inx ; next byte
loop:
cpx #__memory ; up to the end
bne zbcl ; and loop
prog:
sts __sdata ; save sp for monitor return
xgdx ; initialize stack pointer
ldd #00ffH ; put stack pointer at ff for HC11E9
xgdx