M68HC16 Z SERIES
INITIALIZATION AND PROGRAMMING EXAMPLES
MOTOROLA
USER’S MANUAL
E-19
ORG
$0200
;start program after interrupt table
*****
Initialize
*****
INIT:
;initialization stuff
TEMP
EQU
$0006
;variable space used in hex to asc routine
SCCNT
EQU
$0004
;stores the current number of seconds
MNCNT
EQU
$0002
;stores the current number of minutes
HRCNT
EQU
$0000
;stores the current number of hours
INITSYS:
;The following section is normally part of
;INCLUDE 'INITSYS.ASM', but we want to
;leave the COP on.
LDAB
#$0F
TBEK
;point EK to bank F for register access
LDAB
#$00
TBXK
;point XK to bank 0
TBYK
;point YK to bank 0
TBZK
;point ZK to bank 0
LDD
#$00CF
;initialize the SIM MCR
STD
SIMMCR
;this is redundant; it happens at reset
LDAA
#$7F
STAA
SYNCR
;set system clock to 16.78 Mhz
LDAB
#$C0
STAB
SYPCR
;enable the watchdog (COP)
;and set time-out period to 8 seconds
INCLUDE
'INITRAM.ASM'
;turn on internal SRAM at $10000
;set stack in bank 1 (SK=1, SP=03FE)
INCLUDE
'INITSCI.ASM'
;set SCI baud rate at 9600 baud
;enable SCI transmitter and receiver
LDD
#$0638
STD
PICR
;set the periodic interrupt at request level 6
;& assign vector #56 (address $00070) to it
LDD
#$0110
STD
PITR
;initialize PITR to interrupt every 1 sec
LDD
#$FFF9
;initialize Chip Sel Base Reg for Autovector
STD
CSBAR3
;on an IACK cycle: A24-A11=$FFF8, blK_sz = 8K
LDD
#$7801
;initialize Chip Sel Option Reg for
Autovector:
STD
CSOR3
;asynchronous, any Interrupt Priority Level
LDAB
#$FF
;set port F pins to be IRQ pins
STAB
PFPAR
;this is redundant: it happens at reset
LDAB
#$01
TBZK
;set zk nibble to bank 1 for variable access
LDZ
#$0000
;index those variables from $10000
LDD
#$0000
STD
SCCNT,Z
;clear sccnt register
STD
MNCNT,Z
;clear mncnt register
STD
HRCNT,Z
;clear hrcnt register
STD
TEMP,Z
;clear “save” variable space
LDAB
RSR
;find out who caused the last reset