APPENDIX A PROGRAM LIST
XRAM DSEG SADDR
CNT10:
DS
1
; For 10 ms wait
CNT60:
DS
1
; For 60 ms wait
CNT120:
DS
1
; For 120 ms wait
;=============================================================================
;
;
Define the memory stack area
;
;=============================================================================
XSTK DSEG AT
0FEE0H
STACKEND:
DS
20H
; Memory stack area = 32 bytes
STACKTOP:
; Start address of the memory stack area = FF00H
;*****************************************************************************
;
;
Initialization after RESET
;
;*****************************************************************************
XMAIN CSEG UNIT
RESET_START:
;-----------------------------------------------------------------------------
;
Initialize the stack pointer
;-----------------------------------------------------------------------------
MOVW
AX,
#STACKTOP
MOVW SP,
AX
; Set the stack pointer
;-----------------------------------------------------------------------------
;
Initialize the watchdog timer + detect low-v set the clock
;-----------------------------------------------------------------------------
;----- Initialize the watchdog timer -----
MOV
WDTM, #01101111B ; WDT overflow time = 2^20/fx = 131.07 ms
;----- Set the clock <1> -----
MOV
PCC, #00000000B ; The clock supplied to the CPU (fcpu) = fxp (=
fx/4 = 2 MHz)
MOV
LSRCM,
#00000001B ; Stop the oscillation of the low-speed
internal oscillator
;----- Initialize the port 2 -----
MOV
P2,
#00000011B ; Set output latches of P20, P21 as high (turn
off LED1, LED2) and P22, P23 as low
MOV
PM2, #11110000B ; Set P20-P23 as output mode
;----- Check the reset source -----
MOV
A,
RESF
; Read the reset source
BF
A.4, $CHECK_LVI ; Go to CHECK_LVI if not a reset by WDT
MOV P2, #00000001B
;
Light
LED2
CHECK_LVI:
BT
A.0, $SET_CLOCK ; Omit subsequent LVI-related processing and go
to SET_CLOCK during LVI reset
;----- Set low-voltage detection -----
MOV
LVIS, #00000111B ; Set the low-voltage detection level (VLVI) to
2.85 V +-0.15 V
SET1 LVION
; Enable the low-voltage detector operation
Application Note U18847EJ1V0AN
26