; Source created with Parsic Version 3.x

; at              : 13.03.2000 00:34:32


; Project File    : E:\DATEN\DELPHI\PARSIC\INTERNET\BSP\COMFORT.PIC

; Project Version : 1.0.187

; Created         : 04.01.1980 07:08:00

; Last change     : 13.03.2000 00:34:24

               PROCESSOR 16F84

               INCLUDE P16F84.INC

               RADIX DEC


               __IDLOCS H'0100'

               __CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC

; Diverses

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


; Variable

MF1               = 12               ; located in Bank 0, 1
MF1_HI               = 13               ; located in Bank 0, 1
SYS_WSAV               = 14               ; located in Bank 0, 1
SYS_SSAV               = 15               ; located in Bank 0, 1
MF1_FD               = 16               ; located in Bank 0, 1
S0               = 17               ; located in Bank 0, 1
S1               = 18               ; located in Bank 0, 1
ZR1               = 19               ; located in Bank 0, 1
ZR1_FD               = 20               ; located in Bank 0, 1
S2               = 21               ; located in Bank 0, 1
MF2               = 22               ; located in Bank 0, 1
MF2_HI               = 23               ; located in Bank 0, 1
ZR2               = 24               ; located in Bank 0, 1
ZR2_FD               = 25               ; located in Bank 0, 1
MF3               = 26               ; located in Bank 0, 1
MF3_HI               = 27               ; located in Bank 0, 1
MF3_FD               = 28               ; located in Bank 0, 1
ZR3               = 29               ; located in Bank 0, 1
ZR3_FD               = 30               ; located in Bank 0, 1
RAM               = 31               ; 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 MF1,F
               GOTO SYS_INT_LABEL_0
               INCF MF1_HI,F

SYS_INT_LABEL_0
               INCFSZ MF2,F
               GOTO SYS_INT_LABEL_1
               INCF MF2_HI,F

SYS_INT_LABEL_1
               INCFSZ MF3,F
               GOTO SYS_INT_LABEL_2
               INCF MF3_HI,F

SYS_INT_LABEL_2
               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'11111111'
               MOVWF TRISA

               MOVLW B'11111110'
               MOVWF TRISB

; init var

               CLRF MF1
               CLRF MF1_HI
               CLRF SYS_WSAV
               CLRF SYS_SSAV
               CLRF MF1_FD
               MOVLW B'00000001'
               MOVWF S0
               CLRF S1
               CLRF ZR1
               CLRF ZR1_FD
               CLRF S2
               CLRF MF2
               CLRF MF2_HI
               CLRF ZR2
               CLRF ZR2_FD
               CLRF MF3
               CLRF MF3_HI
               CLRF MF3_FD
               CLRF ZR3
               CLRF ZR3_FD

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

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

MAIN

;***************************************************
; Mono-Flop -> MF1
;***************************************************

; Test auf positive Flanke

               BTFSC MF1_FD,0
               GOTO LABEL_MF1_CHKTIME
               BCF STATUS,RP0               ; Bank 0
               BTFSS PORTA,0
               GOTO LABEL_MF1_CHKTIME


LABEL_MF1_RESET

               CLRF MF1
               CLRF MF1_HI
               BSF MF1_FD,1
               BCF S0,0

LABEL_MF1_CHKTIME

; Läuft der Impuls ?

               BTFSS MF1_FD,1
               GOTO LABEL_MF1_SETFD

               MOVLW 15
               SUBWF MF1_HI,W
               BTFSS STATUS,CARRY
               GOTO LABEL_MF1_SETFD
               MOVLW 66
               SUBWF MF1,W
               BTFSS STATUS,CARRY
               GOTO LABEL_MF1_SETFD
LABEL_MF1_TO

               BCF MF1_FD,1
               BSF S0,0

LABEL_MF1_SETFD

               BCF STATUS,RP0               ; Bank 0
               BTFSS PORTA,0
               GOTO LABEL_MF1_CLR
               BSF MF1_FD,0
               GOTO LABEL_MF1_ENDE
LABEL_MF1_CLR
               BCF MF1_FD,0

LABEL_MF1_ENDE

;***************************************************
; RS-FLIP-FLOP -> RS1
;***************************************************

               BTFSS PORTA,0
               GOTO LABEL_RS1_RESET
               BTFSS S0,0
               GOTO LABEL_RS1_ENDE
               BSF S0,1               ; Ausgang setzen
               GOTO LABEL_RS1_ENDE
LABEL_RS1_RESET
               BCF S0,1               ; Ausgang zurücksetzen
LABEL_RS1_ENDE

;***************************************************
; RS-FLIP-FLOP -> RS2
;***************************************************

               BTFSC S0,2
               GOTO LABEL_RS2_RESET
               BTFSS S0,3
               GOTO LABEL_RS2_ENDE
               BSF S0,4               ; Ausgang setzen
               GOTO LABEL_RS2_ENDE
LABEL_RS2_RESET
               BCF S0,4               ; Ausgang zurücksetzen
LABEL_RS2_ENDE

;***************************************************
; ODER - Gatter -> LG1
;***************************************************

LABEL_LG1_1
               BTFSC S0,1
               GOTO LABEL_LG1_TRUE
LABEL_LG1_2
               BTFSS S0,3
               GOTO LABEL_LG1_TRUE

LABEL_LG1_FALSE
               BCF S0,2
               GOTO LABEL_LG1_ENDE
LABEL_LG1_TRUE
               BSF S0,2
LABEL_LG1_ENDE
;***************************************************
; RS-FLIP-FLOP -> RS3
;***************************************************

               BTFSC S1,1
               GOTO LABEL_RS3_RESET
               BTFSS S0,4
               GOTO LABEL_RS3_ENDE
               BSF S1,3               ; Ausgang setzen
               GOTO LABEL_RS3_ENDE
LABEL_RS3_RESET
               BCF S1,3               ; Ausgang zurücksetzen
LABEL_RS3_ENDE

;***************************************************
; Zähler -> ZR1
;***************************************************

               BTFSS S1,6               ; Reset ?
               GOTO LABEL_ZR1_COUNT
               CLRF ZR1
               GOTO LABEL_ZR1_SETOUT

LABEL_ZR1_COUNT

; Test auf positive Flanke

               BTFSC ZR1_FD,0
               GOTO LABEL_ZR1_SETFD
               BTFSS S1,5
               GOTO LABEL_ZR1_SETFD

               INCF ZR1,F

LABEL_ZR1_SETOUT

; Output Q0

               BTFSS ZR1,0
               GOTO LABEL_ZR1_SETOUT0
               BSF S0,5
               GOTO LABEL_ZR1_SETOUT0_END
LABEL_ZR1_SETOUT0
               BCF S0,5
LABEL_ZR1_SETOUT0_END

; Output Q1

               BTFSS ZR1,1
               GOTO LABEL_ZR1_SETOUT1
               BSF S0,6
               GOTO LABEL_ZR1_SETOUT1_END
LABEL_ZR1_SETOUT1
               BCF S0,6
LABEL_ZR1_SETOUT1_END

; Output Q2

               BTFSS ZR1,2
               GOTO LABEL_ZR1_SETOUT2
               BSF S0,7
               GOTO LABEL_ZR1_SETOUT2_END
LABEL_ZR1_SETOUT2
               BCF S0,7
LABEL_ZR1_SETOUT2_END

; Output Q3

               BTFSS ZR1,3
               GOTO LABEL_ZR1_SETOUT3
               BSF S1,0
               GOTO LABEL_ZR1_SETOUT3_END
LABEL_ZR1_SETOUT3
               BCF S1,0
LABEL_ZR1_SETOUT3_END

; Output Q4

               BTFSS ZR1,4
               GOTO LABEL_ZR1_SETOUT4
               BSF S2,0
               GOTO LABEL_ZR1_SETOUT4_END
LABEL_ZR1_SETOUT4
               BCF S2,0
LABEL_ZR1_SETOUT4_END

; Output Q5

               BTFSS ZR1,5
               GOTO LABEL_ZR1_SETOUT5
               BSF S2,1
               GOTO LABEL_ZR1_SETOUT5_END
LABEL_ZR1_SETOUT5
               BCF S2,1
LABEL_ZR1_SETOUT5_END

LABEL_ZR1_SETFD

               BTFSS S1,5
               GOTO LABEL_ZR1_SETFD2
               BSF ZR1_FD,0
               GOTO LABEL_ZR1_END
LABEL_ZR1_SETFD2
               BCF ZR1_FD,0
LABEL_ZR1_END

;***************************************************
; UND - Gatter -> LG2
;***************************************************

LABEL_LG2_1
               BTFSS S0,5
               GOTO LABEL_LG2_FALSE
LABEL_LG2_2
               BTFSC S0,6
               GOTO LABEL_LG2_FALSE
LABEL_LG2_3
               BTFSC S0,7
               GOTO LABEL_LG2_FALSE
LABEL_LG2_4
               BTFSS S1,0
               GOTO LABEL_LG2_FALSE
LABEL_LG2_5
               BTFSS S2,0
               GOTO LABEL_LG2_FALSE
LABEL_LG2_6
               BTFSC S2,1
               GOTO LABEL_LG2_FALSE

LABEL_LG2_TRUE
               BSF S1,2
               GOTO LABEL_LG2_ENDE
LABEL_LG2_FALSE
               BCF S1,2
LABEL_LG2_ENDE
;***************************************************
; ODER - Gatter -> LG3
;***************************************************

LABEL_LG3_1
               BTFSC S1,2
               GOTO LABEL_LG3_TRUE
LABEL_LG3_2
               BTFSC S1,7
               GOTO LABEL_LG3_TRUE

LABEL_LG3_FALSE
               BCF S1,1
               GOTO LABEL_LG3_ENDE
LABEL_LG3_TRUE
               BSF S1,1
LABEL_LG3_ENDE
;***************************************************
; Abfall-Verzögerung -> MF2
;***************************************************

               BTFSS S1,4               ; Eingang auf High ?
               GOTO LABEL_MF2_CHKTIME               ; Nein

; RESET

               CLRF MF2
               CLRF MF2_HI
               BSF S1,5
               GOTO LABEL_MF2_EXIT               ; raus

LABEL_MF2_CHKTIME

               BTFSS S1,5               ; Ausgang schon auf Low ?
               GOTO LABEL_MF2_EXIT               ; Ja

               MOVLW 7
               SUBWF MF2_HI,W
               BTFSS STATUS,CARRY
               GOTO LABEL_MF2_EXIT

               MOVLW 161
               SUBWF MF2,W
               BTFSS STATUS,CARRY
               GOTO LABEL_MF2_EXIT

               BCF S1,5
LABEL_MF2_EXIT

;***************************************************
; UND - Gatter -> LG4
;***************************************************

LABEL_LG4_1
               BTFSS S1,3
               GOTO LABEL_LG4_FALSE
LABEL_LG4_2
               BTFSC S1,5
               GOTO LABEL_LG4_FALSE

LABEL_LG4_TRUE
               BSF S1,4
               GOTO LABEL_LG4_ENDE
LABEL_LG4_FALSE
               BCF S1,4
LABEL_LG4_ENDE
;***************************************************
; ODER - Gatter -> LG5
;***************************************************

LABEL_LG5_1
               BTFSC S1,1
               GOTO LABEL_LG5_TRUE
LABEL_LG5_2
               BTFSC S0,3
               GOTO LABEL_LG5_TRUE

LABEL_LG5_FALSE
               BCF S1,6
               GOTO LABEL_LG5_ENDE
LABEL_LG5_TRUE
               BSF S1,6
LABEL_LG5_ENDE
;***************************************************
; Zähler -> ZR2
;***************************************************

               BTFSC S2,2               ; Reset ?
               GOTO LABEL_ZR2_COUNT
               CLRF ZR2
               GOTO LABEL_ZR2_SETOUT

LABEL_ZR2_COUNT

; Test auf positive Flanke

               BTFSC ZR2_FD,0
               GOTO LABEL_ZR2_SETFD
               BTFSS S0,1
               GOTO LABEL_ZR2_SETFD

               INCF ZR2,F

LABEL_ZR2_SETOUT

; Output Q0

               BTFSS ZR2,0
               GOTO LABEL_ZR2_SETOUT0
               BSF S1,7
               GOTO LABEL_ZR2_SETOUT0_END
LABEL_ZR2_SETOUT0
               BCF S1,7
LABEL_ZR2_SETOUT0_END

LABEL_ZR2_SETFD

               BTFSS S0,1
               GOTO LABEL_ZR2_SETFD2
               BSF ZR2_FD,0
               GOTO LABEL_ZR2_END
LABEL_ZR2_SETFD2
               BCF ZR2_FD,0
LABEL_ZR2_END

;***************************************************
; Mono-Flop -> MF3
;***************************************************

; Läuft der Impuls ?

               BTFSC MF3_FD,1
               GOTO LABEL_MF3_CHKTIME

; Test auf positive Flanke

               BTFSC MF3_FD,0
               GOTO LABEL_MF3_SETFD
               BCF STATUS,RP0               ; Bank 0
               BTFSS PORTA,0
               GOTO LABEL_MF3_SETFD


LABEL_MF3_RESET

               CLRF MF3
               CLRF MF3_HI
               BSF MF3_FD,1
               BSF S0,3

LABEL_MF3_CHKTIME

               MOVLW 3
               SUBWF MF3_HI,W
               BTFSS STATUS,CARRY
               GOTO LABEL_MF3_SETFD
               MOVLW 13
               SUBWF MF3,W
               BTFSS STATUS,CARRY
               GOTO LABEL_MF3_SETFD
LABEL_MF3_TO

               BCF MF3_FD,1
               BCF S0,3

LABEL_MF3_SETFD

               BCF STATUS,RP0               ; Bank 0
               BTFSS PORTA,0
               GOTO LABEL_MF3_CLR
               BSF MF3_FD,0
               GOTO LABEL_MF3_ENDE
LABEL_MF3_CLR
               BCF MF3_FD,0

LABEL_MF3_ENDE

;***************************************************
; Zähler -> ZR3
;***************************************************

               BTFSS S1,2               ; Reset ?
               GOTO LABEL_ZR3_COUNT
               CLRF ZR3
               GOTO LABEL_ZR3_SETOUT

LABEL_ZR3_COUNT

; Test auf positive Flanke

               BTFSC ZR3_FD,0
               GOTO LABEL_ZR3_SETFD
               BTFSS S0,3
               GOTO LABEL_ZR3_SETFD

               INCF ZR3,F

LABEL_ZR3_SETOUT

; Output Q0

               BTFSS ZR3,0
               GOTO LABEL_ZR3_SETOUT0
               BSF S2,2
               GOTO LABEL_ZR3_SETOUT0_END
LABEL_ZR3_SETOUT0
               BCF S2,2
LABEL_ZR3_SETOUT0_END

LABEL_ZR3_SETFD

               BTFSS S0,3
               GOTO LABEL_ZR3_SETFD2
               BSF ZR3_FD,0
               GOTO LABEL_ZR3_END
LABEL_ZR3_SETFD2
               BCF ZR3_FD,0
LABEL_ZR3_END

;***************************************************
; RS-FLIP-FLOP -> RS4
;***************************************************

               BTFSC S1,1
               GOTO LABEL_RS4_RESET
               BTFSS S1,3
               GOTO LABEL_RS4_ENDE
               BSF S2,3               ; Ausgang setzen
               GOTO LABEL_RS4_ENDE
LABEL_RS4_RESET
               BCF S2,3               ; Ausgang zurücksetzen
LABEL_RS4_ENDE

;***************************************************
; UND - Gatter -> LG6
;***************************************************

LABEL_LG6_1
               BTFSS S2,2
               GOTO LABEL_LG6_FALSE
LABEL_LG6_2
               BTFSS S2,4
               GOTO LABEL_LG6_FALSE

LABEL_LG6_TRUE
               BCF STATUS,RP0               ; Bank 0
               BSF PORTB,0
               GOTO LABEL_LG6_ENDE
LABEL_LG6_FALSE
               BCF STATUS,RP0               ; Bank 0
               BCF PORTB,0
LABEL_LG6_ENDE
;***************************************************
; ODER - Gatter -> LG7
;***************************************************

LABEL_LG7_1
               BTFSC S1,7
               GOTO LABEL_LG7_TRUE
LABEL_LG7_2
               BTFSC S2,3
               GOTO LABEL_LG7_TRUE

LABEL_LG7_FALSE
               BCF S2,4
               GOTO LABEL_LG7_ENDE
LABEL_LG7_TRUE
               BSF S2,4
LABEL_LG7_ENDE
;****************************************


               GOTO MAIN


               END

