User`s manual

It will assemble your source program and generate hex code within 4K locations from
$2000 to $2FFF.
Here is a very simple program, but it’s complete. It will light up all 7 segments one at a
time when it’s running. The RAM byte named ‘counter’ is added for demonstrating how a
RAM data byte is used in a user program. In this simple program it’s not really necessary,
because the accumulator A can be used as the RAM bytecounter’.
For a good programming practice, you should always place the lds instruction in the first
line of your code.
#include reg9s12.h
REGBLK: equ $0000
STACK: equ $2000
;
org $1000
counter: rmb 1
org $2000 ; program code
start: lds #STACK
ldx #REGBLK
ldaa #$ff
staa ddrh,x ; make port H an output port
staa pth,x ; turn off 7-segment LED display
begin: ldaa #1 ; start with segment A
back: coma ; for common anode 7-segment LED
staa pth,x ; turn on display
coma ; back to original value
jsr d250ms ; delay 250ms
rola ; go to next segment
tab
andb #$80 ; if it reaches decimal point
bne begin ; do it all over again
anda #$fe ; force bit0 to 0
jmp back
*
d250ms: pshx
psha
ldaa #250 ; delay 250 ms
staa counter
delay1: ldx #6000 ; 6000 x 4 = 24,000 cycles = 1ms
delay: dex ; this instruction takes 1 cycle
bne delay ; this instruction takes 3 cycles
dec counter
bne delay1 ; not 250ms yet, delay again
pula
pulx
rts
end
2. Click File button, select Save option to save your assembly source file. Save your file
frequently while editing. If you are creating a new file and giving the file a name to save,
enter the file name including file extension, such as “Flash_7seg.asm”, not just
“Flash_7seg”.
23