;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Copyright (c) 2001-2002 TIMEX Corporation.
; 
; This document is the property of, and contains information proprietary to
; TIMEX Corporation.  It is to be returned upon request.  Reproduction by any
; means, disclosure, or use of its contents for other than the expressed
; purpose for which it is loaned, without the written consent of TIMEX
; Corporation, is strictly prohibited.
;
; File Name:    Hw88349.h
;
; Module Names: None
;                                  
; Purpose: Hardware definitions for E0C888 family microprocessor.
;          Specific version: E0C88348/E0C88349
;
; File Change History:
;
;               02/28/2002 RVD - Created Hw88349.h for 851
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   RAM/ROM related equates
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Start of user ram
HW_START_OF_USER_RAM    EQU     0F000h

; End of user ram
HW_END_OF_USER_RAM      EQU     0F7FFh


; The start address of ROM
HW_ROM_START_ADDRESS    EQU     00000H

; The end address of ROM
HW_ROM_END_ADDRESS      EQU     0BFFFH

; Redefinitions for existing software.
HWMAXRAMADDRESS         EQU     HW_END_OF_USER_RAM              
HWMINRAMADDRESS         EQU     HW_START_OF_USER_RAM                

; Base address of all hardware peripherals. All peripherals are at 
; addresses FFxx.
HWBASEADDRESS           EQU     0FFH                

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   SC register Condition Code Flag definitions
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

bZeroFlag       EQU     00000001B       ; Zero Flag,                Z bit
bCarryFlag      EQU     00000010B       ; Carry Flag,               C bit
bOverflowFlag   EQU     00000100B       ; Overflow Flag,            V bit
bNegativeFlag   EQU     00001000B       ; Negative Flag,            N bit
bDecimalFlag    EQU     00010000B       ; Decimal Flag,             D bit
bUnpackFlag     EQU     00100000B       ; Unpack Flag,              U bit
bI0Flag         EQU     01000000B       ; Interrupt enable flag 0,  I0 bit
bI1Flag         EQU     10000000B       ; Interrupt enable flag 1,  I1 bit


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Input ports Definitions
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Input Port Register Addresses K00-K07 and addresses of the control registers
InPortK00       EQU     0FF54H          ; address of input ports K00-K07
InCompK00       EQU     0FF52H          ; address of input comparison reg K00-K07
IntSelectionK00 EQU     0FF50H          ; address of interrupt Selection register K00-K07
IntEnableK00    EQU     0FF23H          ; address of interrupt enable register K00-K07
IntPriorityK00  EQU     0FF20H          ; address of interrupt priority register K00-K07
InFlagK0L       EQU     0FF25H          ; address of interrupt flag K00-K03
InFlagK0H       EQU     0FF25H          ; address of interrupt flag K04-K07

; Input Port Register Addresses K10-K11 and addresses of the control registers
InPortK10       EQU     0FF55H          ; address of input port K10-K11
InCompK10       EQU     0FF53H          ; address of input comparison reg K10-K11
IntSelectionK10 EQU     0FF51H          ; address of interrupt enable register K10-K11
IntEnableK10    EQU     0FF23H          ; address of interrupt enable register K10-K11
IntPriorityK10  EQU     0FF21H          ; address of interrupt priority register K10-K11
InFlagK1        EQU     0FF25H          ; address of interrupt flag K10-K11

; Input Pins InPortK00
bK00            EQU     00000001B       ; bit address of K00
bK01            EQU     00000010B       ; bit address of K01
bK02            EQU     00000100B       ; bit address of K02
bK03            EQU     00001000B       ; bit address of K03
bK04            EQU     00010000B       ; bit address of K04
bK05            EQU     00100000B       ; bit address of K05
bK06            EQU     01000000B       ; bit address of K06
bK07            EQU     10000000B       ; bit address of K07
; Input Pins InPortK10
bK10            EQU     00000001B       ; bit address of K10
bK11            EQU     00000010B       ; bit address of K11

; Comparison Pins InCompK00
bKCP00          EQU     00000001B       ; bit address of KCP00
bKCP01          EQU     00000010B       ; bit address of KCP01
bKCP02          EQU     00000100B       ; bit address of KCP02
bKCP03          EQU     00001000B       ; bit address of KCP03
bKCP04          EQU     00010000B       ; bit address of KCP04
bKCP05          EQU     00100000B       ; bit address of KCP05
bKCP06          EQU     01000000B       ; bit address of KCP06
bKCP07          EQU     10000000B       ; bit address of KCP07
; Comparison Pins InCompK10
bKCP10          EQU     00000001B       ; bit address of KCP10
bKCP11          EQU     00000010B       ; bit address of KCP11

; Interrupt selection mask IntSelectionK00
bSIK00          EQU     00000001B       ; bit address of SIK00
bSIK01          EQU     00000010B       ; bit address of SIK01
bSIK02          EQU     00000100B       ; bit address of SIK02
bSIK03          EQU     00001000B       ; bit address of SIK03
bSIK04          EQU     00010000B       ; bit address of SIK04
bSIK05          EQU     00100000B       ; bit address of SIK05
bSIK06          EQU     01000000B       ; bit address of SIK06
bSIK07          EQU     10000000B       ; bit address of SIK07
; Interrupt selection mask IntSelectionK10
bSIK10          EQU     00000001B       ; bit address of SIK10
bSIK11          EQU     00000010B       ; bit address of SIK11

; Interrupt Enable registers in IntEnableK00=IntEnableK10
bEK0L           EQU     00001000B       ; K00-K03 interrupt enable register
bEK0H           EQU     00010000B       ; K04-K07 interrupt enable register
bEK1            EQU     00100000B       ; K10-K11 interrupt enable register

; Interrupt Priority  registers in IntPriorityK00 (priority for K00-K07)
bPK00           EQU     01000000B       ; K00-K07 interrupt priority register
bPK01           EQU     10000000B

; Interrupt Priority  registers in IntPriorityK10 (priority for K10-K11)
bPK10           EQU     00000001B       ; K10-K11 interrupt priority register
bPK11           EQU     00000010B

; Interrupt Factor Flags InFlagK0L=InFlagK0H=InFlagK1
bFK0L           EQU     00001000B       ; bit address of FK0L (K00-K03 factor flag)
bFK0H           EQU     00010000B       ; bit address of FK0H (K04-K07 factor flag)
bFK1            EQU     00100000B       ; bit address of FK1  (K10-K11 factor flag)

    

;*****************************************************************************
;
; OUTPUT PORT DEFINITIONS
;
;*****************************************************************************

; Ouput Ports
OutPortR0       EQU     0FF73H          ; address of ports R00-R07
OutPortR1       EQU     0FF74H          ; address of ports R10-R17
OutPortR2       EQU     0FF75H          ; address of ports R20-R27
OutPortR3       EQU     0FF76H          ; address of ports R30-R37
OutPortR4       EQU     0FF77H          ; Used only as R/W registers in the E0C88348
OutPortR5       EQU     0FF78H          ; address of ports R50-R51

; High Impedance control register
OutPortHighImpedance EQU 0FF70H         ; address of the high impedance control register
        
bHZR0L          EQU     00000001B       ; R00-R03 high impedance control register   
bHZR0H          EQU     00000010B       ; R04-R07 high impedance control register   
bHZR1L          EQU     00000100B       ; R10-R13 high impedance control register   
bHZR1H          EQU     00001000B       ; R14-R17 high impedance control register   
bHZR4L          EQU     00010000B       ; R/W register  
bHZR4H          EQU     00100000B       ; R/W register
bHZR50          EQU     01000000B       ; R50 high impedance control register   
bHZR51          EQU     10000000B       ; R51 high impedance control register   

; Output pins OutPortR0
bR00            EQU     00000001B       ; bit address of R00
bR01            EQU     00000010B       ; bit address of R01
bR02            EQU     00000100B       ; bit address of R02
bR03            EQU     00001000B       ; bit address of R03
bR04            EQU     00010000B       ; bit address of R04
bR05            EQU     00100000B       ; bit address of R05
bR06            EQU     01000000B       ; bit address of R06
bR07            EQU     10000000B       ; bit address of R07
; Output pins OutPortR1
bR10            EQU     00000001B       ; bit address of R10
bR11            EQU     00000010B       ; bit address of R11
bR12            EQU     00000100B       ; bit address of R12
bR13            EQU     00001000B       ; bit address of R13
bR14            EQU     00010000B       ; bit address of R14
bR15            EQU     00100000B       ; bit address of R15
bR16            EQU     01000000B       ; bit address of R16
bR17            EQU     10000000B       ; bit address of R17
; Output pins OutPortR2
bR20            EQU     00000001B       ; bit address of R20
bR21            EQU     00000010B       ; bit address of R21
bR22            EQU     00000100B       ; bit address of R22
bR23            EQU     00001000B       ; bit address of R23
bR24            EQU     00010000B       ; bit address of R24
bR25            EQU     00100000B       ; bit address of R25
bR26            EQU     01000000B       ; bit address of R26
bR27            EQU     10000000B       ; bit address of R27
; Output pins OutPortR3
bR30            EQU     00000001B       ; bit address of R30
bR31            EQU     00000010B       ; bit address of R31
bR32            EQU     00000100B       ; bit address of R32
bR33            EQU     00001000B       ; bit address of R33
bR34            EQU     00010000B       ; bit address of R34
bR35            EQU     00100000B       ; bit address of R35
bR36            EQU     01000000B       ; bit address of R36
bR37            EQU     10000000B       ; bit address of R37
; Output pins OutPortR5
bR50            EQU     00000001B       ; bit address of R50
bR51            EQU     00000010B       ; bit address of R51

;*****************************************************************************
;
; GENERAL PURPOSE INPUT/OUTPUT PORT DEFINITIONS
;
;*****************************************************************************

; Input/Ouput Port P00-P07, P10-P17
InOutPortP00    EQU     0FF62H          ; address of ports P00-P07
InOutPortP10    EQU     0FF63H          ; address of ports P10-P17

; Input/Ouput Control registers
P00Control      EQU     0FF60H          ; address of ports P00-P07 control register
P10Control      EQU     0FF61H          ; address of ports P10-P17 control register

; I/O pins InOutPortP00 
bP00            EQU     00000001B       ; P00 I/O port data
bP01            EQU     00000010B       ; P01 I/O port data
bP02            EQU     00000100B       ; P02 I/O port data
bP03            EQU     00001000B       ; P03 I/O port data
bP04            EQU     00010000B       ; P04 I/O port data
bP05            EQU     00100000B       ; P05 I/O port data
bP06            EQU     01000000B       ; P06 I/O port data
bP07            EQU     10000000B       ; P07 I/O port data
; I/O pins InOutPortP10 
bP10            EQU     00000001B       ; P10 I/O port data
bP11            EQU     00000010B       ; P11 I/O port data
bP12            EQU     00000100B       ; P12 I/O port data
bP13            EQU     00001000B       ; P13 I/O port data
bP14            EQU     00010000B       ; P14 I/O port data
bP15            EQU     00100000B       ; P15 I/O port data
bP16            EQU     01000000B       ; P16 I/O port data
bP17            EQU     10000000B       ; P17 I/O port data

; P00Control Input/Ouput Port Direction Bit Definitions 
bIOC00          EQU     00000001B       ; Direction control bit for P00 (1 = out)
bIOC01          EQU     00000010B       ; Direction control bit for P01 (1 = out)
bIOC02          EQU     00000100B       ; Direction control bit for P02 (1 = out)
bIOC03          EQU     00001000B       ; Direction control bit for P03 (1 = out)
bIOC04          EQU     00010000B       ; Direction control bit for P04 (1 = out)
bIOC05          EQU     00100000B       ; Direction control bit for P05 (1 = out)
bIOC06          EQU     01000000B       ; Direction control bit for P06 (1 = out)
bIOC07          EQU     10000000B       ; Direction control bit for P07 (1 = out)
; P01Control Input/Ouput Port Direction Bit Definitions 
bIOC10          EQU     00000001B       ; Direction control bit for P10 (1 = out)
bIOC11          EQU     00000010B       ; Direction control bit for P11 (1 = out)
bIOC12          EQU     00000100B       ; Direction control bit for P12 (1 = out)
bIOC13          EQU     00001000B       ; Direction control bit for P13 (1 = out)
bIOC14          EQU     00010000B       ; Direction control bit for P14 (1 = out)
bIOC15          EQU     00100000B       ; Direction control bit for P15 (1 = out)
bIOC16          EQU     01000000B       ; Direction control bit for P16 (1 = out)
bIOC17          EQU     10000000B       ; Direction control bit for P17 (1 = out)

;*****************************************************************************
;
; SERIAL PORT DEFINITIONS
;
;*****************************************************************************

; SIC = Serial Interface Control

; Serial Control Registers
SICConfigReg    EQU     0FF48H          ; Serial interface CONFIGURATION register see details below
SICControlReg   EQU     0FF49H          ; Serial interface CONTROL register see details below
SICStatusReg    EQU     0FF49H          ; Serial interface STATUS register see details below

; Serial Port Registers
SICPorts        EQU     InOutPortP10    ; the SIC uses I/O ports
SICPortsDirReg  EQU     P10Control      ; I/O ports direction register
SICData         EQU     0FF4AH          ; Serial data register 8 bits of data
SICIntEnable    EQU     0FF23H          ; Address of int enable for error,receiving and transmiting serial interrupt
SICIntPriority  EQU     0FF20H          ; Address of int priority for error,receiving and transmiting serial interrupt
SICIntFlag      EQU     0FF25H          ; address of int factor flag for error,receiving and transmiting serial interrupt

; Serial interface CONFIGURATION => SICConfigReg
bESIF           EQU     00000001B       ; Set the serial interface terminals(P10-P13)
                                        ; =0 I/O ports, =1 Serial input/output terminals
bSMD0           EQU     00000010B       ; Serial MODE selection:
bSMD1           EQU     00000100B       ; SMD0 - SMD1
                                        ;   0  -  0     Clock synchronous master  
                                        ;   1  -  0     Clock synchronous slave
                                        ;   0  -  1     Asynchronous 7-Bit
                                        ;   1  -  1     Asynchronous 8-Bit

bSCS0           EQU     00001000B       ; SCS0 - SCS1 - Mode select bits
bSCS1           EQU     00010000B       ;   0  -  0     FOSC3/16
                                        ;   1  -  0     FOSC3/8
                                        ;   0  -  1     FOSC3/4
                                        ;   1  -  1     Programmable timer

bPMD            EQU     00100000B       ; Parity mode selection Odd=1, Even=0
bEPR            EQU     01000000B       ; Parity Enable register 0=No parity,1=with parity

                                        ; D7 is always read as 0

; Serial interface CONTROL => SICControlReg
bTXEN           EQU     00000001B       ; Transmit enable
bTXTRG          EQU     00000010B       ; Transmit Trigger/Status(Run=1/Stop=0) write 0 is invalide
bRXEN           EQU     00000100B       ; Receive enable
bRXTRG          EQU     00001000B       ; Receive Trigger/Status(Run=1/Stop=0) write 0 is invalide
; Serial interface STATUS =>   SICStatusReg
bOER            EQU     00010000B       ; Overrun flag
bPER            EQU     00100000B       ; Parity flag
bFER            EQU     01000000B       ; Framing flag

                                            ; D7 is always read as 0
; SIC ports pin redefinition SICPorts

bSIN            EQU     bP10            ; Serial input
bSOUT           EQU     bP11            ; Serial Output
bSCLK           EQU     bP12            ; Serial Clock (!SCLK port)
bSRDY           EQU     bP13            ; Serial Data ready signal (!SRDY port)

; SIC ports direction register redefinitions SICPortsDirReg
; same bits as the ports pin redefinition 1=output          

; Serial Port Interrupt ENABLE Pins SICIntEnable
bESTRA          EQU     00000001B       ; Serial TRANSMITING Interrupt enable
bESREC          EQU     00000010B       ; Serial RECEIVING Interrupt enable
bESERR          EQU     00000100B       ; Serial ERROR Interrupt enable

; Serial Port Interrupt PRIORITY Pins SICIntPriority
bPSIF0          EQU     00010000B       ; Serial interrupt priority
bPSIF1          EQU     00100000B       ; PSIF0 - PSIF1
                                        ;   0   -  0    Level 0 None
                                        ;   1   -  0    Level 1 IRQ1 
                                        ;   0   -  1    Level 2 IRQ2
                                        ;   1   -  1    Level 3 IRQ3

; Serial Port Factor Flag SICIntFlag
bFSTRA          EQU     00000001B       ; Serial TRANSMITING Interrupt factor flag
bFSREC          EQU     00000010B       ; Serial RECEIVING Interrupt factor flag
bFSERR          EQU     00000100B       ; Serial ERROR Interrupt factor flag
        
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   System Controler and bus control
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; System Control Registers
; The explanation below is for MCU (single chip) operational Mode and not for MPU mode.

MCUBusControl   EQU     0FF00H          ; Data Bus Mode Controlers see details below
MCUStackPage    EQU     0FF01H          ; SP page allocatable address only = 0 in single chip mode
MCUOperationalConfig EQU 0FF02H         ; Operating mode selection +
OSCControl      EQU     MCUOperationalConfig ; Operating clock control OSC1/OSC3 +
                                            ; Operating Wait state settings
; MCUBusControl Bus mode - CPU MODE
bCE0            EQU     00000001B       ; Chip Enable (=0 in single chip mode)
bCE1            EQU     00000010B       ; Chip Enable (=0 in single chip mode)
bCE2            EQU     00000100B       ; Chip Enable (=0 in single chip mode)
bCE3            EQU     00001000B       ; Chip Enable (=0 in single chip mode)

bCEMD0          EQU     00010000B       ; Chip Enable Modes in corrolation with CEMD1
bCEMD1          EQU     00100000B       ; Unused in single chip mode

bBSMD0          EQU     01000000B       ; !!! Bus mode selection !!!
bBSMD1          EQU     10000000B       ; BSMD0 - BSMD1
                                        ;   0   -  0    Single Chip mode (default)
                                        ;   1   -  0    64K mode
                                        ;   0   -  1    512K (minimum) mode
                                        ;   1   -  1    512K (maximum) mode
; MCUOperationalConfig bits & OSCControl
bVDC0           EQU     00000001B       ; Operating mode selection
bVDC1           EQU     00000010B       ; VDC0 - VDC1
                                        ;   0  -  0     Normal (Vd1=2.2V)
                                        ;   1  -  0     Low power (Vd1=1.3V)
                                        ;   x  -  1     High speed (Vd1=3.3)

bOSCC           EQU     00000100B       ; OSC3 oscillation ON=1/OFF=0 Control
bCLKCHG         EQU     00001000B       ; CPU operating Clk 1=OSC3, 0=OSC1

                                            ; Wait control register
bWT0            EQU     00010000B       ; WT0 - WT1 - WT0
bWT1            EQU     00100000B       ;  0  - 0   -  0    No wait (Default)
bWT2            EQU     01000000B       ;  1  - 0   -  0    2
                                        ;  0  - 1   -  0    4
                                        ;  1  - 1   -  0    6
                                        ;  0  - 0   -  1    8
                                        ;  1  - 0   -  1    10
                                        ;  0  - 1   -  1    12
                                        ;  1  - 1   -  1    14

bEBR            EQU     10000000B       ; Bus release enable register (not used in single chip mode)

;*****************************************************************************
;
; WATCHDOG TIMER REGISTER DEFINITIONS
;
;*****************************************************************************

; WatchdogTimer Control Registers
Watchdog        EQU     0FF40H          ; address of watchdog reset
bWDRST          EQU     00000100B       ; watchdog reset value 

;*****************************************************************************
;
; MAIN CLOCK TIMER RESISTER DEFINITIONS
;
;*****************************************************************************

; Timer Control Registers
; 1/2/8/32Hz Timer

ClkData         EQU     0FF41H          ; address of Timer Data Register
ClkIntEnable    EQU     0FF22H          ; address of Timer Interrupt enables
ClkPriority     EQU     0FF20H          ; Address of int priority for the clk Timer int
ClkIntFlags     EQU     0FF24H          ; address of Timer Factor Flags
ClkControl      EQU     0FF40H          ; address of Timer Reset register
                                        ; STOP/RUN Control register

; Clock timer data ClkData  default=00H
                                            ; Read only
bTM0            EQU     00000001B       ; 128Hz
bTM1            EQU     00000010B       ; 64Hz
bTM2            EQU     00000100B       ; 32Hz
bTM3            EQU     00001000B       ; 16Hz
bTM4            EQU     00010000B       ; 8Hz
bTM5            EQU     00100000B       ; 4Hz
bTM6            EQU     01000000B       ; 2Hz
bTM7            EQU     10000000B       ; 1Hz

; Main Timer Interrupt Enable Pins ClkIntEnable
    
bETM1           EQU     00000001B       ; Enable 1Hz interrupt
bETM2           EQU     00000010B       ; Enable 2Hz interrupt
bETM8           EQU     00000100B       ; Enable 8Hz interrupt
bETM32          EQU     00001000B       ; Enable 32Hz interrupt

; Clock Timer Interrupt PRIORITY Pins ClkPriority

bPTM0           EQU     00000001B       ; Clock timer interrupt priority
bPTM1           EQU     00000010B       ; PTM0 - PTM1
                                        ;   0   -  0    Level 0 None
                                        ;   1   -  0    Level 1 IRQ1
                                        ;   0   -  1    Level 2 IRQ2
                                        ;   1   -  1    Level 3 IRQ3
; Clock Timer factor flags ClkIntFlags
                                        ; Note: to reset a factor flag write 1
bFTM1           EQU     00000001B       ; 1Hz interrupt Factor flag
bFTM2           EQU     00000010B       ; 2Hz interrupt Factor flag
bFTM8           EQU     00000100B       ; 8Hz interrupt Factor flag
bFTM32          EQU     00001000B       ; 32Hz interrupt Factor flag

; Clock Timer Control register ClkControl

bTMRST          EQU     00000010B       ; Reset the clock timer by write 1 to this bit
bTMRUN          EQU     00000001B       ; Run=1/Stop=0 of Clk Timer (reading invalid)

;*****************************************************************************
;
; STOPWATCH REGISTER DEFINITIONS
;
;*****************************************************************************

; Stopwatch Control Registers 
; 1/10/100 HZ 

StpData         EQU     0FF43H          ; address of Stopwatch Data Register
StpIntEnable    EQU     0FF22H          ; address of Stopwatch Interrupt enables
StpPriority     EQU     0FF20H          ; Address of int priority for the Stopwatch int
StpIntFlags     EQU     0FF24H          ; address of Stopwatch Factor Flags
StpControl      EQU     0FF42H          ; address of Stopwatch Reset register
                                            ; STOP/RUN status register
; Stopwatch data StpData    default=00H
                                        ; Read only
bSW0            EQU     00000001B       ; ----------------
bSW1            EQU     00000010B       ; BCD   1/100 sec
bSW2            EQU     00000100B       ; 
bSW3            EQU     00001000B       ; 
bSW4            EQU     00010000B       ; -----------------
bSW5            EQU     00100000B       ; BCD   1/10 sec
bSW6            EQU     01000000B       ; 
bSW7            EQU     10000000B       ; 

; Main  Stopwatch Enable Pins StpIntEnable
    
bESW1           EQU     00010000B       ; Enable 1Hz Stp interrupt
bESW10          EQU     00100000B       ; Enable 10Hz Stp interrupt
bESW100         EQU     01000000B       ; Enable 100Hz Stp interrupt

; Stopwatch Interrupt PRIORITY Pins StpPriority

bPSW0           EQU     00000100B       ; Clock timer interrupt priority
bPSW1           EQU     00001000B       ; PSW0 - PSW1
                                        ;   0   -  0    Level 0 None
                                        ;   1   -  0    Level 1 IRQ1
                                        ;   0   -  1    Level 2 IRQ2
                                        ;   1   -  1    Level 3 IRQ3
; Stopwatch factor flags StpIntFlags
                                        ; Note: to reset a factor flag write 1
bFSW1           EQU     00010000B       ; 1Hz interrupt Factor flag
bFSW10          EQU     00100000B       ; 10Hz interrupt Factor flag
bFSW100         EQU     01000000B       ; 100Hz interrupt Factor flag

; Stopwatch control register StpControl

bSWRST          EQU     00000010B       ; Reset the Stopwatch by write 1 to this bit
bSWRUN          EQU     00000001B       ; Run=1/Stop=0 of Stopwatch 

;*****************************************************************************
;
;   PROGRAMMABLE TIMER
;
;*****************************************************************************

Timer0Data       EQU    0FF35H          ; Timer0 counter data (D7=MSB, D0=LSB) readonly register
Timer1Data       EQU    0FF36H          ; Timer1 counter data (D7=MSB, D0=LSB) readonly register
Timer0ReloadData EQU    0FF33H          ; Timer0 reload data for timer 0 initialization
Timer1ReloadData EQU    0FF34H          ; Timer1 reload data for timer 1 initialization
TimerIntEnable   EQU    0FF23H          ; address of timers Interrupt enables
TimerPriority    EQU    0FF21H          ; address of Interrupt priority
TimerIntFlags    EQU    0FF25H          ; address of Interrupt factor flags for timer0 and timer1
TimersControl    EQU    0FF30H          ; Mode(8/16bit)/TOUT(timer0/1)/Timers clock souces
Timer0Control    EQU    0FF31H          ; Timer0 control register
Timer1Control    EQU    0FF32H          ; Timer1 control Register

; Timer0 / Timer1 Enable Pins TimerIntEnable

bEPT0           EQU     01000000B       ; Enable Timer0 interrupt
bEPT1           EQU     10000000B       ; Enable Timer1 interrupt

; Programmable Timer interrupt priority TimerPriority

bPPT0           EQU     00000100B       ; PPT0 - PPT1
bPPT1           EQU     00001000B       ;   0   -  0    Level 0 None
                                        ;   1   -  0    Level 1 IRQ1
                                        ;   0   -  1    Level 2 IRQ2
                                        ;   1   -  1    Level 3 IRQ3

; Programmable Timer interrupt Factor flags TimerIntFlags

bFPT0           EQU     01000000B       ; Timer0 interrupt factor flag
bFPT1           EQU     10000000B       ; Timer1 interrupt factor flag

;   Mode selection (8/16bit), Output selection TOUT(timer0 or timer1),
;   Timers clock souces selction(OSC1/OSC3)
;   Reg: TimersControl   

bMODE16         EQU     00010000B       ; 8/16 bit mode selection
                                        ; 0 = 8-bit 2 channel
                                        ; 1 = 16-bit 1 channel

bCKSEL0         EQU     00000001B       ; Timer0 source Clock Selection (0=OSC1,1=OSC3)
bCKSEL1         EQU     00000010B       ; Timer1 source Clock Selection (0=OSC1,1=OSC3)

bCHSEL          EQU     00001000B       ; Selects the channel of TOUT signal (0=Timer0,1=Timer1)
bPTOUT          EQU     00000100B       ; Controls the Output signal on TOUT

; Timer0 Control Register Timer0Control

bPRUN0          EQU     00000001B       ; Timer0 Run=1/Stop=0 control
bPSET0          EQU     00000010B       ; 1=loads the value from Timer0ReloadData to Timer0Data
bCONT0          EQU     00000100B       ; Timer0 continuous=1/One-shot=0 mode selection

bPSC00          EQU     00001000B       ; Timer0 prescale dividing ratio selection
bPSC01          EQU     00010000B       ; PSC00 - PSC01     Ratio
                                        ;   0   -  0      Source clk/1
                                        ;   1   -  0      Source clk/4
                                        ;   0   -  1      Source clk/16
                                        ;   1   -  1      Source clk/64 

bPLPOL          EQU     00100000B       ; Timer0 pulse polarity selection

bFCSEL          EQU     01000000B       ; Timer0 function selection

bEVCNT          EQU     10000000B       ; Timer0 mode selection(0=Timer,1=Event Counter)

; Timer1 Control Register Timer1Control

bPRUN1          EQU     00000001B       ; Timer1 Run=1/Stop=0 control
bPSET1          EQU     00000010B       ; 1=loads the value from Timer1ReloadData to Timer1Data
bCONT1          EQU     00000100B       ; Timer1 continuous=1/One-shot=0 mode selection

bPSC10          EQU     00001000B       ; Timer1 prescale dividing ratio selection
bPSC11          EQU     00010000B       ; PSC00 - PSC01     Ratio
                                        ;   0   -  0      Source clk/1
                                        ;   1   -  0      Source clk/4
                                        ;   0   -  1      Source clk/16
                                        ;   1   -  1      Source clk/64 

;*****************************************************************************
;
; LCD CONTROL REGISTER DEFINITIONS
;
;*****************************************************************************

LCDPower        EQU     0FF09H          ; LCD Power Type and Drive contol 
LCDConfig       EQU     0FF10H          ; LCD configuration register(duty, dot font, expansion)
LCDControl      EQU     0FF11H          ; Contrast and display control register

; LCDPower pins

bDUTY8          EQU     00000001B       ; 0=1/32 and 1/16 duty, 1 = 1/8 duty
bLCDAJ          EQU     00000010B       ; 0= Type B LCD (5.5V), 1= Type A (4.5V)

; LCDConfig pins

bLDUTY          EQU     00000010B       ; 0=1/32 duty, 1=1/16 duty
bDTFNT          EQU     00000100B       ; 0=5x8 dots,  1=5x5 dots
bLCFRM          EQU     00001000B       ; FR output control for expanded LCD driver(0=Off,1=ON)
bLCCLK          EQU     00010000B       ; CL output control for expanded LCD driver(0=Off,1=ON)

; LCDControl pins

bLC0            EQU     00000001B       ; LCD Contrast Adjustment
bLC1            EQU     00000010B       ; LC0 - LC1 - LC2 - LC3    Contrast
bLC2            EQU     00000100B       ;  0     0     0     0      Light
bLC3            EQU     00001000B       ;  ....................
                                        ;  1     1     1     1       Dark

bLCDC0          EQU     00010000B       ; Controls the LCD display
bLCDC1          EQU     00100000B       ; LCDC0 - LCDC1  LCD Display
                                        ;   0   -  0        Drive off
                                        ;   1   -  0        Normal display
                                        ;   0   -  1        All LCDs out(Dynamic)
                                        ;   1   -  1        All LCDs lit (Static)

bDSPAR          EQU     01000000B       ; LCD display memory Area 
                                        ; 0=Display area 0, 1=Display area 1

;*****************************************************************************
;
; SOUND GENERATOR REGISTER DEFINITIONS
;
;*****************************************************************************

BZConfig        EQU     0FF45H          ; Buzzer output signal config(Freq,duty)
BZControl       EQU     0FF44H          ; Output generation register

; Buzzer configuration BZConfig

bBZFQ0          EQU     00000001B       ; Buzzer frequency selection
bBZFQ1          EQU     00000010B       ; BZFQ0 - BZFQ1 - BZFQ2 -  Ferq.
bBZFQ2          EQU     00000100B       ;   0       0       0      4096.0 Hz
                                        ;   1       0       0      3276.8 Hz
                                        ;   0       1       0      2730.7 Hz      
                                        ;   1       1       0      2340.6 Hz
                                        ;   0       0       1      2048.0 Hz
                                        ;   1       0       1      1638.4 Hz
                                        ;   0       1       1      1365.3 Hz
                                        ;   1       1       1      1170.3 Hz

bDUTY0          EQU     00010000B       ; Buzzer signal duty ratio selection
bDUTY1          EQU     00100000B       ; DUTY0 - DUTY1 - DUTY2 -  Buzzer Freq.
bDUTY2          EQU     01000000B       ;                       4096.0   3276.8  2730.7  2340.6
                                        ;                       2048.0   1638.4  1365.3  1170.3
                                        ;   0       0       0    8/16     8/20    12/24   12/28
                                        ;   1       0       0    7/16     7/20    11/24   11/28
                                        ;   0       1       0    6/16     6/20    10/24   10/28
                                        ;   1       1       0    5/16     5/20     9/24    9/28
                                        ;   0       0       1    4/16     4/20     8/24    8/28
                                        ;   1       0       1    3/16     3/20     7/24    7/28
                                        ;   0       1       1    2/16     2/20     6/24    6/28
                                        ;   1       1       1    1/16     1/20     5/24    5/28

; Buzzer Contro register pins BZControl

bBZON           EQU     00000001B       ; Buzzer output control
bENON           EQU     00000010B       ; Envelope ON=1/OFF=0 control
bENRST          EQU     00000100B       ; Envelope Reset 1=Reset
bENRTM          EQU     00001000B       ; Envelope Attenuation time(1=1 sec, 0=0.5 sec)
bSHTPW          EQU     00010000B       ; One-Shot buzzer duration width selection
                                        ; 0=31.25 msec, 1=125 msec
bBZSHT          EQU     00100000B       ; One-shot buzzer trigger/status
                                        ; Read  1 = Busy, 0 = Ready
                                        ; Write 1 = Trigger, 0=no opertation
bBZSTP          EQU     01000000B       ; One-shot buzzer forcibly stop (write 1 to stop)

;*****************************************************************************
;
; LAMP PORT DEFINITIONS
;
;*****************************************************************************

; Lamp Control Registers
ELControl       EQU     0FF40H          ; Lamp/EL output control register R34(FOUT)
ELPort          EQU     OutPortR3       
; Lamp Control Pins
bELFoutOn       EQU     00001000B       ; 1=FOUT Signal output, 0=HIGH DC output
bFOUT0          EQU     00010000B       ; FOUT signal frequency
bFOUT1          EQU     00100000B       ; FOUT0 - FOUT1 - FOUT2 - FOUT Freq.
bFOUT2          EQU     01000000B       ;   0       0       0      fOSC1/1
                                        ;   1       0       0      fOSC1/2
                                        ;   0       1       0      fOSC1/4
                                        ;   1       1       0      fOSC1/8
                                        ;   0       0       1      fOSC3/1
                                        ;   1       0       1      fOSC3/2
                                        ;   0       1       1      fOSC3/4
                                        ;   1       1       1      fOSC3/8


bLampOn         EQU     bR33            ; Turns on Lamp (HON), (1 = on)
bELCLKOn        EQU     bR34            ; 

;*****************************************************************************
;
; ANALOG COMPARATOR PORT DEFINITIONS
;
;*****************************************************************************

; Analog Comparator Register
ACPRegister     EQU     0FF13H          ; Analog comparator control and data register

; Analog Comparator Control Pins
bCMP0DT         EQU     00000001B       ;Comparator0 data
bCMP1DT         EQU     00000010B       ;Comparator1 data
bCMP0ON         EQU     00000100B       ;Comparator0 on=1/off=0
bCMP1ON         EQU     00001000B       ;Comparator1 on=1/off=0


;*****************************************************************************
;
; LOW BATTERY LEVEL DETECTION REGISTER DEFINITIONS
;
;*****************************************************************************

; Battery Level Detect 
SVDReg          EQU     0FF12H          ; supply voltage detection register

; SVDReg pins

bSVDON          EQU     00010000B       ; Controls the turning ON=1/OFF=0 
                                        ; of the continuous sampling mode
bSVDSP          EQU     00100000B       ; Controls the turning ON=1/OFF=0
                                        ; of the 1/4 HZ sampling mode
bSVD0           EQU     00000001B       ; SVD detection level
bSVD1           EQU     00000010B       ; SVD0 - SVD1 - SVD2 - SVD3
bSVD2           EQU     00000100B       ;   0      0      0      0      Level 0
bSVD3           EQU     00001000B       ;   1      0      0      0      Level 1
                                        ;   0      1      0      0      Level 2
                                        ;   1      1      0      0      Level 3
                                        ;   0      0      1      0      Level 4
                                        ;   1      0      1      0      Level 5
                                        ;   0      1      1      0      Level 6
                                        ;   1      1      1      0      Level 7
                                        ;   0      0      0      1      Level 8
                                        ;   1      0      0      1      Level 9
                                        ;   0      1      0      1      Level 10
                                        ;   1      1      0      1      Level 11
                                        ;   0      0      1      1      Level 12
                                        ;   1      0      1      1      Level 13
                                        ;   0      1      1      1      Level 14
                                        ;   1      1      1      1      Level 15
