; Source created with Parsic Version 3.x

; at              : 16.01.2000 14:36:20


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

; Project Version : 1.0.144

; Created         : 19.08.1999 14:25:00

; Last change     : 16.01.2000 14:36:15

	PROCESSOR 16C84

	INCLUDE P16C84.INC

	RADIX DEC


	__IDLOCS H'0100'

	__CONFIG _CP_OFF & _PWRTE_ON & _WDT_ON & _XT_OSC

; Diverses

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


; Variable

ZR1	= 12	; located in Bank 0, 1
ZR1_FD	= 13	; located in Bank 0, 1
S1	= 14	; located in Bank 0, 1
S3	= 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
ZV1	= 20	; located in Bank 0, 1
ZV1_HI	= 21	; located in Bank 0, 1
ZV1_FD	= 22	; located in Bank 0, 1
MF1	= 23	; located in Bank 0, 1
MF1_HI	= 24	; located in Bank 0, 1
MF1_FD	= 25	; located in Bank 0, 1
S2	= 26	; located in Bank 0, 1
MF2	= 27	; located in Bank 0, 1
MF2_HI	= 28	; located in Bank 0, 1
MF2_FD	= 29	; located in Bank 0, 1
TR2	= 30	; located in Bank 0, 1
TR2_HI	= 31	; located in Bank 0, 1
ZV2	= 32	; located in Bank 0, 1
ZV2_HI	= 33	; located in Bank 0, 1
ZV2_FD	= 34	; located in Bank 0, 1
S0	= 35	; located in Bank 0, 1
S0_HI	= 36	; located in Bank 0, 1
SYS_TMP1	= 37	; located in Bank 0, 1
SYS_TMP2	= 38	; located in Bank 0, 1
SYS_TMP3	= 39	; located in Bank 0, 1
SYS_TMP4	= 40	; located in Bank 0, 1
SYS_TMP5	= 41	; located in Bank 0, 1
SYS_TMP6	= 42	; located in Bank 0, 1
SYS_TMP7	= 43	; located in Bank 0, 1
MF3	= 44	; located in Bank 0, 1
MF3_HI	= 45	; located in Bank 0, 1
MF3_FD	= 46	; located in Bank 0, 1
RAM	= 47	; 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
	INCFSZ MF1,F
	GOTO SYS_INT_LABEL_1
	INCF MF1_HI,F

SYS_INT_LABEL_1
	INCFSZ MF2,F
	GOTO SYS_INT_LABEL_2
	INCF MF2_HI,F

SYS_INT_LABEL_2
	INCFSZ TR2,F
	GOTO SYS_INT_LABEL_3
	INCF TR2_HI,F

SYS_INT_LABEL_3
	INCFSZ MF3,F
	GOTO SYS_INT_LABEL_4
	INCF MF3_HI,F

SYS_INT_LABEL_4
	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


;****************************************
; Division 16 - Bit
; OP1 = SYS_TMP1,2
; OP2 = SYS_TMP3,4
;****************************************

SYSDIV16
	MOVFW SYS_TMP3	; Division durch 0 ?
	IORWF SYS_TMP4,W
	BTFSC STATUS,ZERO
	GOTO SYSDIV16_ERROR

	CLRF SYS_TMP5	; Ergebnis löschen
	CLRF SYS_TMP6
	MOVLW 1
	MOVWF SYS_TMP7
SYSDIV16_0
	BTFSC SYS_TMP4,7	; OP2 linksbündig
	GOTO SYSDIV16_1
	INCF SYS_TMP7,F
	BCF STATUS,CARRY
	RLF SYS_TMP3,F
	RLF SYS_TMP4,F
	GOTO SYSDIV16_0

SYSDIV16_1
	MOVFW SYS_TMP4	; OP1 und OP2 vergleichen
	SUBWF SYS_TMP2,W	; F-W -> W
	BTFSS STATUS,ZERO
	GOTO SYSDIV16_2
	MOVFW SYS_TMP3
	SUBWF SYS_TMP1,W	; F-W -> W

SYSDIV16_2
	BTFSS STATUS,CARRY
	GOTO SYSDIV16_3
	MOVFW SYS_TMP4	; OP1-OP2
	SUBWF SYS_TMP2,F	; F-W -> F
	MOVFW SYS_TMP3
	SUBWF SYS_TMP1,F	; F-W -> F
	BTFSS STATUS,CARRY
	DECF SYS_TMP2,F
	BSF STATUS,CARRY
SYSDIV16_3
	RLF SYS_TMP5,F	; Ergebnis aktualisieren
	RLF SYS_TMP6,F
	RRF SYS_TMP4,F	; OP2 nach rechts schieben
	RRF SYS_TMP3,F
	DECFSZ SYS_TMP7,F	; Zähler -1
	GOTO SYSDIV16_1

	RETURN

SYSDIV16_ERROR
	MOVLW 255
	MOVWF SYS_TMP5
	MOVWF SYS_TMP6
	RETURN


;****************************************
; 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'11110110'
	MOVWF TRISA

	MOVLW B'00011111'
	MOVWF TRISB

; init var

	CLRF ZR1
	CLRF ZR1_FD
	CLRF S1
	CLRF S3
	CLRF SYS_WSAV
	CLRF SYS_SSAV
	CLRF TR1
	CLRF TR1_HI
	CLRF ZV1
	CLRF ZV1_HI
	CLRF ZV1_FD
	CLRF MF1
	CLRF MF1_HI
	CLRF MF1_FD
	CLRF S2
	CLRF MF2
	CLRF MF2_HI
	CLRF MF2_FD
	CLRF TR2
	CLRF TR2_HI
	CLRF ZV2
	CLRF ZV2_HI
	CLRF ZV2_FD
	CLRF S0
	CLRF S0_HI
	CLRF SYS_TMP1
	CLRF SYS_TMP2
	CLRF SYS_TMP3
	CLRF SYS_TMP4
	CLRF SYS_TMP5
	CLRF SYS_TMP6
	CLRF SYS_TMP7
	CLRF MF3
	CLRF MF3_HI
	CLRF MF3_FD

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

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

MAIN

	CLRWDT

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

	BTFSS S2,3	; 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 S2,7
	GOTO LABEL_ZR1_SETFD

	INCF ZR1,F

LABEL_ZR1_SETOUT

; Output Q0

	BTFSS ZR1,0
	GOTO LABEL_ZR1_SETOUT0
	BSF S1,0
	GOTO LABEL_ZR1_SETOUT0_END
LABEL_ZR1_SETOUT0
	BCF S1,0
LABEL_ZR1_SETOUT0_END

; Output Q1

	BTFSS ZR1,1
	GOTO LABEL_ZR1_SETOUT1
	BSF S1,1
	GOTO LABEL_ZR1_SETOUT1_END
LABEL_ZR1_SETOUT1
	BCF S1,1
LABEL_ZR1_SETOUT1_END

; Output Q2

	BTFSS ZR1,2
	GOTO LABEL_ZR1_SETOUT2
	BSF S1,2
	GOTO LABEL_ZR1_SETOUT2_END
LABEL_ZR1_SETOUT2
	BCF S1,2
LABEL_ZR1_SETOUT2_END

LABEL_ZR1_SETFD

	BTFSS S2,7
	GOTO LABEL_ZR1_SETFD2
	BSF ZR1_FD,0
	GOTO LABEL_ZR1_END
LABEL_ZR1_SETFD2
	BCF ZR1_FD,0
LABEL_ZR1_END

;***************************************************
; UND - Gatter -> UG3
;***************************************************

LABEL_UG3_1
	BTFSS S1,0
	GOTO LABEL_UG3_FALSE
LABEL_UG3_2
	BTFSC S1,1
	GOTO LABEL_UG3_FALSE
LABEL_UG3_3
	BCF STATUS,RP0	; Bank 0
	BTFSC PORTB,1
	GOTO LABEL_UG3_FALSE
LABEL_UG3_4
	BTFSC PORTB,7
	GOTO LABEL_UG3_FALSE
LABEL_UG3_5
	BTFSC PORTB,4
	GOTO LABEL_UG3_FALSE

LABEL_UG3_TRUE
	BSF S1,3
	GOTO LABEL_UG3_ENDE
LABEL_UG3_FALSE
	BCF S1,3
LABEL_UG3_ENDE
;***************************************************
; UND - Gatter -> UG4
;***************************************************

LABEL_UG4_1
	BTFSS S1,0
	GOTO LABEL_UG4_FALSE
LABEL_UG4_2
	BTFSS S1,1
	GOTO LABEL_UG4_FALSE
LABEL_UG4_3
	BCF STATUS,RP0	; Bank 0
	BTFSC PORTB,2
	GOTO LABEL_UG4_FALSE
LABEL_UG4_4
	BTFSC PORTB,6
	GOTO LABEL_UG4_FALSE
LABEL_UG4_5
	BTFSC PORTB,4
	GOTO LABEL_UG4_FALSE
LABEL_UG4_6
	BTFSC S1,4
	GOTO LABEL_UG4_FALSE

LABEL_UG4_TRUE
	BSF PORTB,7
	GOTO LABEL_UG4_ENDE
LABEL_UG4_FALSE
	BCF STATUS,RP0	; Bank 0
	BCF PORTB,7
LABEL_UG4_ENDE
;***************************************************
; ODER - Gatter -> UG5
;***************************************************

LABEL_UG5_1
	BTFSC S1,3
	GOTO LABEL_UG5_TRUE
LABEL_UG5_2
	BTFSC S1,4
	GOTO LABEL_UG5_TRUE

LABEL_UG5_FALSE
	BCF PORTB,6
	GOTO LABEL_UG5_ENDE
LABEL_UG5_TRUE
	BCF STATUS,RP0	; Bank 0
	BSF PORTB,6
LABEL_UG5_ENDE
;***************************************************
; ODER - Gatter -> UG6
;***************************************************

LABEL_UG6_1
	BTFSC PORTB,6
	GOTO LABEL_UG6_TRUE
LABEL_UG6_2
	BTFSC PORTB,7
	GOTO LABEL_UG6_TRUE

LABEL_UG6_FALSE
	BCF S3,1
	GOTO LABEL_UG6_ENDE
LABEL_UG6_TRUE
	BSF S3,1
LABEL_UG6_ENDE
;***************************************************
; Timer -> TR1
;***************************************************

	MOVLW 3	; Test auf >=
	SUBWF TR1_HI,W	;F-W -> W
	BTFSS STATUS,CARRY
	GOTO LABEL_TR1_ENDE
	MOVLW 209
	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 S3,3
	GOTO LABEL_TR1_CLR
	BSF S3,3
	GOTO LABEL_TR1_ENDE
LABEL_TR1_CLR
	BCF S3,3
LABEL_TR1_ENDE

;***************************************************
; UND - Gatter -> UG7
;***************************************************

LABEL_UG7_1
	BTFSS S3,1
	GOTO LABEL_UG7_FALSE
LABEL_UG7_2
	BTFSS S3,3
	GOTO LABEL_UG7_FALSE

LABEL_UG7_TRUE
	BCF STATUS,RP0	; Bank 0
	BSF PORTB,5
	GOTO LABEL_UG7_ENDE
LABEL_UG7_FALSE
	BCF STATUS,RP0	; Bank 0
	BCF PORTB,5
LABEL_UG7_ENDE
;***************************************************
; Vergleich -> IF1
;***************************************************

	MOVLW HIGH 600
	SUBWF ZV1_HI,W	; F - W -> W

	BTFSS STATUS,ZERO	; Wenn ZERO gesetzt LOW-Byte testen
	GOTO LABEL_IF1_CHECK
	MOVLW LOW 600
	SUBWF ZV1,W	; F - W -> W

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

LABEL_IF1_TRUE
	BSF S3,2
	GOTO LABEL_IF1_EXIT

LABEL_IF1_FALSE
	BCF S3,2

LABEL_IF1_EXIT
;***************************************************
; Zähler -> ZV1
;***************************************************

	BCF STATUS,RP0	; Bank 0
	BTFSC PORTA,0	; Reset ?
	GOTO LABEL_ZV1_COUNT
	CLRF ZV1
	CLRF ZV1_HI
	GOTO LABEL_ZV1_SETOUT

LABEL_ZV1_COUNT

; Test auf positive Flanke

	BTFSS S1,6
	GOTO LABEL_ZV1_SETFD
	BTFSC ZV1_FD,0
	GOTO LABEL_ZV1_SETFD

	BSF ZV1_FD,0


	BTFSC S1,5	; 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 S1,6
	GOTO LABEL_ZV1_EXIT
	BCF ZV1_FD,0

LABEL_ZV1_EXIT

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

	BTFSC S3,2
	GOTO LABEL_RS1_RESET
	BTFSS S1,7
	GOTO LABEL_RS1_ENDE
	BCF STATUS,RP0	; Bank 0
	BSF PORTA,0	; Ausgang setzen
	GOTO LABEL_RS1_ENDE
LABEL_RS1_RESET
	BCF STATUS,RP0	; Bank 0
	BCF PORTA,0	; Ausgang zurücksetzen
LABEL_RS1_ENDE

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

	BTFSC PORTB,1
	GOTO LABEL_RS2_RESET
	BTFSS PORTB,3
	GOTO LABEL_RS2_ENDE
	BSF S1,4	; Ausgang setzen
	GOTO LABEL_RS2_ENDE
LABEL_RS2_RESET
	BCF S1,4	; Ausgang zurücksetzen
LABEL_RS2_ENDE

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

; Läuft der Impuls ?

	BTFSC MF1_FD,1
	GOTO LABEL_MF1_CHKTIME

; Test auf positive Flanke

	BTFSC MF1_FD,0
	GOTO LABEL_MF1_SETFD
	BTFSS S1,4
	GOTO LABEL_MF1_SETFD


LABEL_MF1_RESET

	CLRF MF1
	CLRF MF1_HI
	BSF MF1_FD,1
	BSF S2,4

LABEL_MF1_CHKTIME

	MOVLW 0
	SUBWF MF1_HI,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF1_SETFD
	MOVLW 78
	SUBWF MF1,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF1_SETFD
LABEL_MF1_TO

	BCF MF1_FD,1
	BCF S2,4

LABEL_MF1_SETFD

	BTFSS S1,4
	GOTO LABEL_MF1_CLR
	BSF MF1_FD,0
	GOTO LABEL_MF1_ENDE
LABEL_MF1_CLR
	BCF MF1_FD,0

LABEL_MF1_ENDE

;***************************************************
; GND
;***************************************************

	BCF S1,5	; immer Low

;***************************************************
; ODER - Gatter -> UG8
;***************************************************

LABEL_UG8_1
	BTFSC S3,1
	GOTO LABEL_UG8_TRUE
LABEL_UG8_2
	BTFSC S3,3
	GOTO LABEL_UG8_TRUE

LABEL_UG8_FALSE
	BCF S1,6
	GOTO LABEL_UG8_ENDE
LABEL_UG8_TRUE
	BSF S1,6
LABEL_UG8_ENDE
;***************************************************
; Mono-Flop -> MF2
;***************************************************

; Läuft der Impuls ?

	BTFSC MF2_FD,1
	GOTO LABEL_MF2_CHKTIME

; Test auf positive Flanke

	BTFSC MF2_FD,0
	GOTO LABEL_MF2_SETFD
	BTFSS S3,0
	GOTO LABEL_MF2_SETFD


LABEL_MF2_RESET

	CLRF MF2
	CLRF MF2_HI
	BSF MF2_FD,1
	BSF S2,5

LABEL_MF2_CHKTIME

	MOVLW 0
	SUBWF MF2_HI,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF2_SETFD
	MOVLW 78
	SUBWF MF2,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF2_SETFD
LABEL_MF2_TO

	BCF MF2_FD,1
	BCF S2,5

LABEL_MF2_SETFD

	BTFSS S3,0
	GOTO LABEL_MF2_CLR
	BSF MF2_FD,0
	GOTO LABEL_MF2_ENDE
LABEL_MF2_CLR
	BCF MF2_FD,0

LABEL_MF2_ENDE

;***************************************************
; ODER - Gatter -> UG9
;***************************************************

LABEL_UG9_1
	BCF STATUS,RP0	; Bank 0
	BTFSC PORTB,5
	GOTO LABEL_UG9_TRUE
LABEL_UG9_2
	BTFSC PORTA,1
	GOTO LABEL_UG9_TRUE

LABEL_UG9_FALSE
	BCF S1,7
	GOTO LABEL_UG9_ENDE
LABEL_UG9_TRUE
	BSF S1,7
LABEL_UG9_ENDE
;***************************************************
; UND - Gatter -> UG10
;***************************************************

LABEL_UG10_1
	BTFSS S3,1
	GOTO LABEL_UG10_FALSE
LABEL_UG10_2
	BTFSS S2,0
	GOTO LABEL_UG10_FALSE

LABEL_UG10_TRUE
	BSF S2,1
	GOTO LABEL_UG10_ENDE
LABEL_UG10_FALSE
	BCF S2,1
LABEL_UG10_ENDE
;***************************************************
; Timer -> TR2
;***************************************************

	MOVLW 7	; Test auf >=
	SUBWF TR2_HI,W	;F-W -> W
	BTFSS STATUS,CARRY
	GOTO LABEL_TR2_ENDE
	MOVLW 161
	SUBWF TR2,W	;F-W -> W
	BTFSS STATUS,CARRY
	GOTO LABEL_TR2_ENDE

LABEL_TR2_RESET
	CLRF TR2	; reset time
	CLRF TR2_HI	; reset time

LABEL_TR2_SET	; toggel output
	BTFSC S2,0
	GOTO LABEL_TR2_CLR
	BSF S2,0
	GOTO LABEL_TR2_ENDE
LABEL_TR2_CLR
	BCF S2,0
LABEL_TR2_ENDE

;***************************************************
; Zähler -> ZV2
;***************************************************

	BCF STATUS,RP0	; Bank 0
	BTFSS PORTA,2	; Reset ?
	GOTO LABEL_ZV2_COUNT
	CLRF ZV2
	CLRF ZV2_HI
	GOTO LABEL_ZV2_SETOUT

LABEL_ZV2_COUNT

; Test auf positive Flanke

	BTFSS S2,1
	GOTO LABEL_ZV2_SETFD
	BTFSC ZV2_FD,0
	GOTO LABEL_ZV2_SETFD

	BSF ZV2_FD,0


	BTFSC S2,2	; Vorwärts oder Rückwärts ?
	GOTO LABEL_ZV2_BACKWARD

	INCFSZ ZV2,F
	GOTO LABEL_ZV2_SETOUT
	INCF ZV2_HI,F
	GOTO LABEL_ZV2_SETOUT

LABEL_ZV2_BACKWARD
	DECF ZV2,F
	INCFSZ ZV2,W
	GOTO LABEL_ZV2_SETOUT
	DECF ZV2_HI,F

LABEL_ZV2_SETOUT


LABEL_ZV2_SETFD

; Test auf negative Flanke

	BTFSC S2,1
	GOTO LABEL_ZV2_EXIT
	BCF ZV2_FD,0

LABEL_ZV2_EXIT

;***************************************************
; GND
;***************************************************

	BCF S2,2	; immer Low

;***************************************************
;AF1
;***************************************************

	MOVFW ZV2
	MOVWF SYS_TMP1
	MOVFW ZV2_HI
	MOVWF SYS_TMP2
	MOVLW LOW 3600
	MOVWF SYS_TMP3
	MOVLW HIGH 3600
	MOVWF SYS_TMP4
	CALL SYSDIV16
	MOVFW SYS_TMP5
	MOVWF S0
	MOVFW SYS_TMP6
	MOVWF S0_HI

LABEL_AF1_EXIT
;***************************************************
; Vergleich -> IF2
;***************************************************

	MOVLW HIGH 500
	SUBWF S0_HI,W	; F - W -> W

	BTFSS STATUS,ZERO	; Wenn ZERO gesetzt LOW-Byte testen
	GOTO LABEL_IF2_CHECK
	MOVLW LOW 500
	SUBWF S0,W	; F - W -> W

LABEL_IF2_CHECK
	BCF STATUS,RP0	; Bank 0
	BTFSS STATUS,CARRY	; Test auf -> >
	GOTO LABEL_IF2_FALSE
	BTFSC STATUS,ZERO
	GOTO LABEL_IF2_FALSE

LABEL_IF2_TRUE
	BSF PORTA,3
	GOTO LABEL_IF2_EXIT

LABEL_IF2_FALSE
	BCF PORTA,3

LABEL_IF2_EXIT
;***************************************************
; ODER - Gatter -> LG9
;***************************************************

LABEL_LG9_1
	BTFSC S1,2
	GOTO LABEL_LG9_TRUE
LABEL_LG9_2
	BTFSC S2,4
	GOTO LABEL_LG9_TRUE

LABEL_LG9_FALSE
	BCF S2,3
	GOTO LABEL_LG9_ENDE
LABEL_LG9_TRUE
	BSF S2,3
LABEL_LG9_ENDE
;***************************************************
; 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 PORTB,0
	GOTO LABEL_MF3_SETFD


LABEL_MF3_RESET

	CLRF MF3
	CLRF MF3_HI
	BSF MF3_FD,1
	BSF S2,6

LABEL_MF3_CHKTIME

	MOVLW 0
	SUBWF MF3_HI,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF3_SETFD
	MOVLW 78
	SUBWF MF3,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF3_SETFD
LABEL_MF3_TO

	BCF MF3_FD,1
	BCF S2,6

LABEL_MF3_SETFD

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

LABEL_MF3_ENDE

;***************************************************
; ODER - Gatter -> LG10
;***************************************************

LABEL_LG10_1
	BTFSC S2,6
	GOTO LABEL_LG10_TRUE
LABEL_LG10_2
	BTFSC S2,5
	GOTO LABEL_LG10_TRUE

LABEL_LG10_FALSE
	BCF S2,7
	GOTO LABEL_LG10_ENDE
LABEL_LG10_TRUE
	BSF S2,7
LABEL_LG10_ENDE
;***************************************************
; ODER - Gatter -> LG11
;***************************************************

LABEL_LG11_1
	BCF STATUS,RP0	; Bank 0
	BTFSC PORTB,2
	GOTO LABEL_LG11_TRUE
LABEL_LG11_2
	BTFSC PORTB,1
	GOTO LABEL_LG11_TRUE

LABEL_LG11_FALSE
	BCF S3,0
	GOTO LABEL_LG11_ENDE
LABEL_LG11_TRUE
	BSF S3,0
LABEL_LG11_ENDE
;****************************************


	GOTO MAIN


	END

