User`s manual

PK220082 s Power Management
Recommended Power Fail Routine
Z-World recommends the following routines to handle an NMI. The
routines monitor the state of the /PFO line, via U18 and the data bus, to
determine if the brownout condition is continuing or if the power has
returned to normal levels. If you use one of these routines, you need not
worry about multiple power-failure /NMIs because these routines never
return from the first /NMI unless the power returns.
Program C-1. Suggested Power Fail Routine
main(){
...
}
...
char dummy[24]; // reserve dummy stack
// for /NMI processing
...
#define NMI_BIT 3 // routine will test data
#define NMI PIODB2 // bit 3 to determine
// state of /NMI line
#JUMP_VEC NMI_VEC myint
#asm
myint::
ld sp,dummy+24 ; force stack pointer
; to top of “dummy”
; array to prevent
; overwriting of code
; or data
;do whatever service, within allowable
;executuin time
loop:
call hitwd ; make sure no
; watchdog reset
; during brownout
ld bc,NMI ; load the read-NMI
; register to bc
in a,(c) ; read the read-NMI
; register to /PFO
bit NMI_BIT, a ; check /PFO status
jr z,loop ; wait until brownout
; condition clears
timeout: ; then... a tight loop
; to force a watchdog
; timeout
jp timeout ; which will reset the
; Z180
#endasm