; Source created with Parsic Version 3.x

; at              : 11.01.00 00:05:29


; Project File    : E:\DATEN\MPLAB\HOLM\ALARMV2.PIC

; Project Version : 0.0.80

; Created         : 03.06.99 00:25:00

; Last change     : 11.01.00 00:01:19

               PROCESSOR 16F84

               INCLUDE P16F84.INC

               RADIX DEC


               __IDLOCS H'0000'

               __CONFIG _CP_OFF & _PWRTE_ON & _WDT_ON & _XT_OSC

; Diverses

ZERO               EQU Z               ; ZERO-Flag
CARRY                EQU C               ; CARRY-Flag


; Variable

S0               = 12               ; located in Bank 0, 1
ZV1               = 13               ; located in Bank 0, 1
ZV1_HI               = 14               ; located in Bank 0, 1
ZV1_FD               = 15               ; located in Bank 0, 1
SYS_WSAV               = 16               ; located in Bank 0, 1
SYS_SSAV               = 17               ; located in Bank 0, 1
TR1               = 18               ; located in Bank 0, 1
TR1_HI               = 19               ; located in Bank 0, 1
RAM               = 20               ; located in Bank 0, 1

               ERRORLEVEL -302               ; disable warning (Bankswitching)
               ERRORLEVEL -306               ; disable warning (Pageswitching)

;****************************************
;Programmanfang
;****************************************

               ORG 0

               CLRF STATUS               ; switch to RAM-Bank 0
               MOVLW HIGH SYS_INIT               ; set ROM-Bank
               MOVWF PCLATH
               GOTO SYS_INIT

;****************************************
;Interrupt-Adress
;****************************************

               MOVWF SYS_WSAV               ; Register sichern
               SWAPF STATUS,W
               CLRF STATUS               ; BANK0
               MOVWF SYS_SSAV

               INCFSZ TR1,F
               GOTO SYS_INT_LABEL_0
               INCF TR1_HI,F

SYS_INT_LABEL_0
               BCF INTCON,T0IF               ; Interrupt quitieren

EXITINT

               SWAPF SYS_SSAV,W               ; Register zurück
               MOVWF STATUS
               SWAPF SYS_WSAV,F
               SWAPF SYS_WSAV,W

               RETFIE               ; RETurn From Interrupt and Enable GIE


;****************************************
; Subroutines
;****************************************


;****************************************
; Tables
;****************************************


;****************************************
;Initialisierung
;****************************************


SYS_INIT

               MOVLW B'00100000'
               MOVWF INTCON

; Ausgangs-Pegel setzen, bevor die Richtung gesetzt wird

               BCF STATUS,RP0               ; Bank 0
               MOVLW B'00000000'
               MOVWF PORTA

               MOVLW B'00000000'
               MOVWF PORTB

               MOVLW 15
               BSF STATUS,RP0               ; Bank 1
               MOVWF OPTION_REG


; Richtung setzen

               MOVLW B'11111001'
               MOVWF TRISA

               MOVLW B'11111111'
               MOVWF TRISB

; init var

               CLRF S0
               CLRF ZV1
               CLRF ZV1_HI
               CLRF ZV1_FD
               CLRF SYS_WSAV
               CLRF SYS_SSAV
               CLRF TR1
               CLRF TR1_HI

               BCF STATUS,RP0               ; Bank 0
               CLRF TMR0
               BCF INTCON,T0IF
               BSF INTCON,GIE               ; Interrupt freigeben

;**********************************
;******* Haupt-Programm ***********
;**********************************

MAIN

               CLRWDT

;***************************************************
; ODER - Gatter -> UG1
;***************************************************

LABEL_UG1_1
               BCF STATUS,RP0               ; Bank 0
               BTFSS PORTB,0
               GOTO LABEL_UG1_TRUE
LABEL_UG1_2
               BTFSS PORTB,1
               GOTO LABEL_UG1_TRUE
LABEL_UG1_3
               BTFSS PORTB,2
               GOTO LABEL_UG1_TRUE
LABEL_UG1_4
               BTFSS PORTB,3
               GOTO LABEL_UG1_TRUE
LABEL_UG1_5
               BTFSS PORTB,4
               GOTO LABEL_UG1_TRUE
LABEL_UG1_6
               BTFSS PORTB,5
               GOTO LABEL_UG1_TRUE
LABEL_UG1_7
               BTFSS PORTB,6
               GOTO LABEL_UG1_TRUE

LABEL_UG1_FALSE
               BCF S0,4
               GOTO LABEL_UG1_ENDE
LABEL_UG1_TRUE
               BSF S0,4
LABEL_UG1_ENDE
;***************************************************
; RS-FLIP-FLOP -> RS1
;***************************************************

               BCF STATUS,RP0               ; Bank 0
               BTFSC PORTA,0
               GOTO LABEL_RS1_RESET
               BTFSS S0,3
               GOTO LABEL_RS1_ENDE
               BSF PORTA,1               ; Ausgang setzen
               GOTO LABEL_RS1_ENDE
LABEL_RS1_RESET
               BCF STATUS,RP0               ; Bank 0
               BCF PORTA,1               ; Ausgang zurücksetzen
LABEL_RS1_ENDE

;***************************************************
; ODER - Gatter -> UG2
;***************************************************

LABEL_UG2_1
               BTFSC PORTB,7
               GOTO LABEL_UG2_TRUE

LABEL_UG2_FALSE
               BCF S0,5
               GOTO LABEL_UG2_ENDE
LABEL_UG2_TRUE
               BSF S0,5
LABEL_UG2_ENDE
;***************************************************
; UND - Gatter -> UG3
;***************************************************

LABEL_UG3_1
               BCF STATUS,RP0               ; Bank 0
               BTFSS PORTA,1
               GOTO LABEL_UG3_FALSE
LABEL_UG3_2
               BTFSS S0,2
               GOTO LABEL_UG3_FALSE

LABEL_UG3_TRUE
               BSF PORTA,2
               GOTO LABEL_UG3_ENDE
LABEL_UG3_FALSE
               BCF STATUS,RP0               ; Bank 0
               BCF PORTA,2
LABEL_UG3_ENDE
;***************************************************
; Zähler -> ZV1
;***************************************************

               BTFSS PORTA,0               ; Reset ?
               GOTO LABEL_ZV1_COUNT
               CLRF ZV1
               CLRF ZV1_HI
               GOTO LABEL_ZV1_SETOUT

LABEL_ZV1_COUNT

; Test auf positive Flanke

               BTFSS S0,0
               GOTO LABEL_ZV1_SETFD
               BTFSC ZV1_FD,0
               GOTO LABEL_ZV1_SETFD

               BSF ZV1_FD,0


               BTFSC S0,1               ; Vorwärts oder Rückwärts ?
               GOTO LABEL_ZV1_BACKWARD

               INCFSZ ZV1,F
               GOTO LABEL_ZV1_SETOUT
               INCF ZV1_HI,F
               GOTO LABEL_ZV1_SETOUT

LABEL_ZV1_BACKWARD
               DECF ZV1,F
               INCFSZ ZV1,W
               GOTO LABEL_ZV1_SETOUT
               DECF ZV1_HI,F

LABEL_ZV1_SETOUT


LABEL_ZV1_SETFD

; Test auf negative Flanke

               BTFSC S0,0
               GOTO LABEL_ZV1_EXIT
               BCF ZV1_FD,0

LABEL_ZV1_EXIT

;***************************************************
; Timer -> TR1
;***************************************************

               MOVLW 7               ; Test auf >=
               SUBWF TR1_HI,W               ;F-W -> W
               BTFSS STATUS,CARRY
               GOTO LABEL_TR1_ENDE
               MOVLW 161
               SUBWF TR1,W               ;F-W -> W
               BTFSS STATUS,CARRY
               GOTO LABEL_TR1_ENDE

LABEL_TR1_RESET
               CLRF TR1               ; reset time
               CLRF TR1_HI               ; reset time

LABEL_TR1_SET               ; toggel output
               BTFSC S0,1
               GOTO LABEL_TR1_CLR
               BSF S0,1
               GOTO LABEL_TR1_ENDE
LABEL_TR1_CLR
               BCF S0,1
LABEL_TR1_ENDE

;***************************************************
; UND - Gatter -> UG4
;***************************************************

LABEL_UG4_1
               BCF STATUS,RP0               ; Bank 0
               BTFSS PORTA,1
               GOTO LABEL_UG4_FALSE
LABEL_UG4_2
               BTFSS S0,1
               GOTO LABEL_UG4_FALSE

LABEL_UG4_TRUE
               BSF S0,0
               GOTO LABEL_UG4_ENDE
LABEL_UG4_FALSE
               BCF S0,0
LABEL_UG4_ENDE
;***************************************************
; Vergleich -> IF1
;***************************************************

               MOVLW 180
               SUBWF ZV1,W               ; F - W -> W

LABEL_IF1_CHECK
               BTFSS STATUS,CARRY               ; Test auf -> <=
               GOTO LABEL_IF1_TRUE
               BTFSS STATUS,ZERO
               GOTO LABEL_IF1_FALSE

LABEL_IF1_TRUE
               BSF S0,2
               GOTO LABEL_IF1_EXIT

LABEL_IF1_FALSE
               BCF S0,2

LABEL_IF1_EXIT
;***************************************************
; ODER - Gatter -> LG5
;***************************************************

LABEL_LG5_1
               BTFSC S0,5
               GOTO LABEL_LG5_TRUE
LABEL_LG5_2
               BTFSC S0,4
               GOTO LABEL_LG5_TRUE

LABEL_LG5_FALSE
               BCF S0,3
               GOTO LABEL_LG5_ENDE
LABEL_LG5_TRUE
               BSF S0,3
LABEL_LG5_ENDE
;****************************************


               GOTO MAIN


               END

