Page 241 - Programming Microcontrollers in C
P. 241
226 Chapter 5 Programming Large 8-Bit Systems
txs
jsr _main ; execute main
_exit:
lds __sdata ; restore stack pointer
rts ; and return to calling program
__return:
rti ; used by default interrupt vector
;
.psect _data
__sdata:
.word 0 ; avoid any pointer to null
.end
The start-up program must be written to account for any special
problems that might be needed for your program. Through this
routine, memory can be initialized with data stored in ROM, the
special registers that must be processed within the first 64 bus cycles
can be set, the stack can be placed where the programmer desires,
and so forth. The code at the end of the routine restores the stack
pointer to the value it contained when the start-up routine was entered
and executes an rts, return to subroutine, to return control of the
processor to a monitor that started the program if one exists.
The location __sdata is the first byte following the volatile
memory used by the program. This value will be used by the memory
allocation functions to provide memory on the system heap.
Finally, the last line of the compiler command file
hexh11 -s -o %1.hex %1.h11
causes execution of the program hexh11 , which converts the object
module from machine code to an S record format that can be written
into an evaluation module or used to burn an EPROM version of the
microcontroller. This S record file can also be delivered to the factory
and used to define a mask for a mask ROM version of the
microcontroller. The file created by this line of code will have an
extension .hex.
EXERCISES
1. Write and compile a small program that will show some bit manipu
lations in PORTA. Make the program test, set, and clear bits in this