       TITLE 'SOFTWARE INTERRUPT PROGRAM REV 3-29-90'
       LIST    P=16C54

                       ;SOFTWARE INTERRUPT APPLICATIONS
                       ;BRANCH IS MAIN PROGRAM REGISTER
BRANCH EQU     8
CNDTN  EQU     9
IO     EQU     0A
TEMP   EQU     0B

SETUP  CLRF    CNDTN
       MOVLW   4
       MOVWF   BRANCH  ;FOUR MAIN PROGRAM SECTIONS
       MOVLW   8
       OPTION          ;SET RTCC TO ONE COUNT PER INSTRUCTION CYCLE

START  CLRF    1       ;CLEAR RTCC REGISTER
       MOVF    6,W     ;READ I/O
       MOVWF   IO
       IORWF   CNDTN,W ;THIS SECTION OF CODE CALCULATES THE
       MOVWF   TEMP    ;JUMP TABLE. ANY INPUT THAT CHANGES FROM
       MOVF    CNDTN,W ;A ZERO TO A ONE IS CONSIDERED AN INTERRUPT.
       SUBWF   TEMP,1  ;THE EQUATION IS:
       MOVF    IO,W    ;  (IO + CNDTN) - CNDTN = INTERRUPT
       MOVWF   CNDTN   ;WHERE IO IS CURRENT INPUT AND
       MOVF    TEMP,W  ;CNDTN IS PREVIOUS INPUT.
       ANDLW   3       ;MASK OFF TOP 6 BITS
       ADDWF   2,1     ;ADD INPUT TO PC TO CREATE JUMP TABLE
       GOTO    MAIN    ;FOR INPUT=00
       GOTO    INT1    ;FOR INPUT=01
       GOTO    INT2    ;FOR INPUT=10
       GOTO    INT3    ;FOR INPUT=11

INT1   NOP             ;INTERRUPT LINE 1 CODE
       GOTO    START
INT2   NOP             ;INTERRUPT LINE 2 CODE
       GOTO    START
INT3   NOP             ;INTERRUPT LINES 1 AND 2 CODE
       GOTO    START

MAIN   MOVF    BRANCH,W
       ADDWF   2,1     ;ADD BRANCH TO PC TO CREATE JUMP TABLE
       NOP
       GOTO    MAIN4   ;JUMP TABLE, LAST FIRST ON DECREMENT TABLE
       GOTO    MAIN3
       GOTO    MAIN2
       GOTO    MAIN1

MAIN1  NOP             ;MAIN PROGRAM CODE BANK ONE
       GOTO    BRNCHK
MAIN2  NOP             ;MAIN PROGRAM CODE SECTION TWO
       GOTO    BRNCHK
MAIN3  NOP             ;MAIN PROGRAM CODE SECTION THREE
       GOTO    BRNCHK
MAIN4  NOP             ;MAIN PROGRAM CODE SECTION FOUR
       GOTO    BRNCHK

BRNCHK DECFSZ  BRANCH,1 ;DECREMENT BRANCH REGISTER AND CHECK FOR ZERO
       GOTO    TIMCHK
       MOVLW   4
       MOVWF   BRANCH  ;RELOAD BRANCH WITH 4 AT END OF MAIN

TIMCHK MOVLW   D'41'   ;CHECK TO SEE IF RTCC HAS REACHED 50(50-7)
       SUBWF   1,W     ;DETERMINE WAIT TIME
       ADDWF   2,1     ;ADD WAIT TIME TO PC
       NOP
       NOP
       NOP
       NOP
       NOP
       NOP
       NOP
       GOTO    START
       END