; Source created with Parsic Version 3.x

; at              : 25.06.2004 00:35:16


; Project File    : c:\BELGEL~1\PARSIC\SAAT_24\SAAT_24.PIC

; Project Version : 1.0.14

; Created         : 15.05.2004 13:56:00

; Last change     : 25.06.2004 00:35:10

	PROCESSOR 16F84A

	INCLUDE P16F84A.INC

	RADIX DEC


	__IDLOCS H'0100'

	__CONFIG _CP_ON & _PWRTE_ON & _WDT_OFF & _XT_OSC

; Diverses

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


; Variable

ZV1	= 12	; located in Bank 0, 1
ZV1_FD	= 13	; located in Bank 0, 1
ZV2	= 14	; located in Bank 0, 1
ZV2_FD	= 15	; located in Bank 0, 1
ZV3	= 16	; located in Bank 0, 1
ZV3_FD	= 17	; located in Bank 0, 1
ZV4	= 18	; located in Bank 0, 1
ZV4_FD	= 19	; located in Bank 0, 1
ZV5	= 20	; located in Bank 0, 1
ZV5_FD	= 21	; located in Bank 0, 1
S8	= 22	; located in Bank 0, 1
SYS_WSAV	= 23	; located in Bank 0, 1
SYS_SSAV	= 24	; located in Bank 0, 1
TR1	= 25	; located in Bank 0, 1
TR1_HI	= 26	; located in Bank 0, 1
S10	= 27	; located in Bank 0, 1
S9	= 28	; located in Bank 0, 1
SYS_TMP1	= 29	; located in Bank 0, 1
S0	= 30	; located in Bank 0, 1
ZV6	= 31	; located in Bank 0, 1
ZV6_FD	= 32	; located in Bank 0, 1
S1	= 33	; located in Bank 0, 1
TR2	= 34	; located in Bank 0, 1
TR2_HI	= 35	; located in Bank 0, 1
ZV7	= 36	; located in Bank 0, 1
ZV7_FD	= 37	; located in Bank 0, 1
S2	= 38	; located in Bank 0, 1
S3	= 39	; located in Bank 0, 1
ZV8	= 40	; located in Bank 0, 1
ZV8_FD	= 41	; located in Bank 0, 1
S11	= 42	; located in Bank 0, 1
S4	= 43	; located in Bank 0, 1
S5	= 44	; located in Bank 0, 1
ZV9	= 45	; located in Bank 0, 1
ZV9_FD	= 46	; located in Bank 0, 1
ZV10	= 47	; located in Bank 0, 1
ZV10_FD	= 48	; located in Bank 0, 1
S7	= 49	; located in Bank 0, 1
S6	= 50	; located in Bank 0, 1
MF1	= 51	; located in Bank 0, 1
MF1_HI	= 52	; located in Bank 0, 1
MF1_FD	= 53	; located in Bank 0, 1
MF2	= 54	; located in Bank 0, 1
MF2_HI	= 55	; located in Bank 0, 1
MF2_FD	= 56	; located in Bank 0, 1
MF3	= 57	; located in Bank 0, 1
MF3_HI	= 58	; located in Bank 0, 1
MF3_FD	= 59	; located in Bank 0, 1
TR3	= 60	; located in Bank 0, 1
TR3_HI	= 61	; located in Bank 0, 1
RAM	= 62	; 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
	GOTO SYS_INIT
	NOP
	NOP

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

	MOVWF SYS_WSAV	; save register
	SWAPF STATUS,W
	CLRF STATUS	; bank 0
	MOVWF SYS_SSAV

	BCF INTCON,T0IF	; Interrupt quitieren

	INCFSZ TR1,F
	GOTO SYS_INT_LABEL_0
	INCF TR1_HI,F

SYS_INT_LABEL_0
	INCFSZ TR2,F
	GOTO SYS_INT_LABEL_1
	INCF TR2_HI,F

SYS_INT_LABEL_1
	INCFSZ MF1,F
	GOTO SYS_INT_LABEL_2
	INCF MF1_HI,F

SYS_INT_LABEL_2
	INCFSZ MF2,F
	GOTO SYS_INT_LABEL_3
	INCF MF2_HI,F

SYS_INT_LABEL_3
	INCFSZ MF3,F
	GOTO SYS_INT_LABEL_4
	INCF MF3_HI,F

SYS_INT_LABEL_4
	INCFSZ TR3,F
	GOTO SYS_INT_LABEL_5
	INCF TR3_HI,F

SYS_INT_LABEL_5

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
;****************************************


;****************************************
;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 143
	BSF STATUS,RP0	; Bank 1
	MOVWF OPTION_REG


; Richtung setzen

	MOVLW B'11111110'
	MOVWF TRISA

	MOVLW B'00000000'
	MOVWF TRISB

; init vars


; Clear RAM

	MOVLW 12
	MOVWF FSR
CR1
	CLRF INDF
	INCF FSR,F
	MOVFW FSR
	SUBLW 80
	BTFSS STATUS,ZERO
	GOTO CR1


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

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

MAIN

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

	BTFSS S8,6	; Reset ?
	GOTO LABEL_ZV1_COUNT
	CLRF ZV1
	GOTO LABEL_ZV1_SETOUT

LABEL_ZV1_COUNT

; Test auf positive Flanke

	BTFSS S8,5
	GOTO LABEL_ZV1_SETFD
	BTFSC ZV1_FD,0
	GOTO LABEL_ZV1_SETFD

	BSF ZV1_FD,0


	BTFSC S8,4	; Vorwärts oder Rückwärts ?
	GOTO LABEL_ZV1_BACKWARD

	INCF ZV1,F
	GOTO LABEL_ZV1_SETOUT

LABEL_ZV1_BACKWARD
	DECF ZV1,F

LABEL_ZV1_SETOUT


LABEL_ZV1_SETFD

; Test auf negative Flanke

	BTFSC S8,5
	GOTO LABEL_ZV1_EXIT
	BCF ZV1_FD,0

LABEL_ZV1_EXIT

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

	BTFSS S9,5	; Reset ?
	GOTO LABEL_ZV2_COUNT
	CLRF ZV2
	GOTO LABEL_ZV2_SETOUT

LABEL_ZV2_COUNT

; Test auf positive Flanke

	BTFSS S8,7
	GOTO LABEL_ZV2_SETFD
	BTFSC ZV2_FD,0
	GOTO LABEL_ZV2_SETFD

	BSF ZV2_FD,0


	BTFSC S8,3	; Vorwärts oder Rückwärts ?
	GOTO LABEL_ZV2_BACKWARD

	INCF ZV2,F
	GOTO LABEL_ZV2_SETOUT

LABEL_ZV2_BACKWARD
	DECF ZV2,F

LABEL_ZV2_SETOUT


LABEL_ZV2_SETFD

; Test auf negative Flanke

	BTFSC S8,7
	GOTO LABEL_ZV2_EXIT
	BCF ZV2_FD,0

LABEL_ZV2_EXIT

;***************************************************
; Zähler -> ZV3
;***************************************************

	BTFSS S9,4	; Reset ?
	GOTO LABEL_ZV3_COUNT
	CLRF ZV3
	GOTO LABEL_ZV3_SETOUT

LABEL_ZV3_COUNT

; Test auf positive Flanke

	BTFSS S9,1
	GOTO LABEL_ZV3_SETFD
	BTFSC ZV3_FD,0
	GOTO LABEL_ZV3_SETFD

	BSF ZV3_FD,0


	BTFSC S8,2	; Vorwärts oder Rückwärts ?
	GOTO LABEL_ZV3_BACKWARD

	INCF ZV3,F
	GOTO LABEL_ZV3_SETOUT

LABEL_ZV3_BACKWARD
	DECF ZV3,F

LABEL_ZV3_SETOUT


LABEL_ZV3_SETFD

; Test auf negative Flanke

	BTFSC S9,1
	GOTO LABEL_ZV3_EXIT
	BCF ZV3_FD,0

LABEL_ZV3_EXIT

;***************************************************
; Zähler -> ZV4
;***************************************************

	BTFSS S10,0	; Reset ?
	GOTO LABEL_ZV4_COUNT
	CLRF ZV4
	GOTO LABEL_ZV4_SETOUT

LABEL_ZV4_COUNT

; Test auf positive Flanke

	BTFSS S10,6
	GOTO LABEL_ZV4_SETFD
	BTFSC ZV4_FD,0
	GOTO LABEL_ZV4_SETFD

	BSF ZV4_FD,0


	BTFSC S8,1	; Vorwärts oder Rückwärts ?
	GOTO LABEL_ZV4_BACKWARD

	INCF ZV4,F
	GOTO LABEL_ZV4_SETOUT

LABEL_ZV4_BACKWARD
	DECF ZV4,F

LABEL_ZV4_SETOUT


LABEL_ZV4_SETFD

; Test auf negative Flanke

	BTFSC S10,6
	GOTO LABEL_ZV4_EXIT
	BCF ZV4_FD,0

LABEL_ZV4_EXIT

;***************************************************
; Zähler -> ZV5
;***************************************************

	BTFSS S9,6	; Reset ?
	GOTO LABEL_ZV5_COUNT
	CLRF ZV5
	GOTO LABEL_ZV5_SETOUT

LABEL_ZV5_COUNT

; Test auf positive Flanke

	BTFSS S9,3
	GOTO LABEL_ZV5_SETFD
	BTFSC ZV5_FD,0
	GOTO LABEL_ZV5_SETFD

	BSF ZV5_FD,0


	BTFSC S8,0	; Vorwärts oder Rückwärts ?
	GOTO LABEL_ZV5_BACKWARD

	INCF ZV5,F
	GOTO LABEL_ZV5_SETOUT

LABEL_ZV5_BACKWARD
	DECF ZV5,F

LABEL_ZV5_SETOUT


LABEL_ZV5_SETFD

; Test auf negative Flanke

	BTFSC S9,3
	GOTO LABEL_ZV5_EXIT
	BCF ZV5_FD,0

LABEL_ZV5_EXIT

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

	BCF S8,4	; immer Low

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

	BCF S8,3	; immer Low

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

	BCF S8,2	; immer Low

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

	BCF S8,1	; immer Low

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

	BCF S8,0	; immer Low

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

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

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

LABEL_TR1_SET	; toggel output
	BTFSC S8,5
	GOTO LABEL_TR1_CLR
	BSF S8,5
	GOTO LABEL_TR1_ENDE
LABEL_TR1_CLR
	BCF S8,5
LABEL_TR1_ENDE

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

LABEL_LG1_1
	BTFSC S9,4
	GOTO LABEL_LG1_TRUE
LABEL_LG1_2
	BTFSC S10,5
	GOTO LABEL_LG1_TRUE

LABEL_LG1_FALSE
	BCF S10,6
	GOTO LABEL_LG1_ENDE
LABEL_LG1_TRUE
	BSF S10,6
LABEL_LG1_ENDE
;***************************************************
; ODER - Gatter -> LG2
;***************************************************

LABEL_LG2_1
	BTFSC S9,5
	GOTO LABEL_LG2_TRUE
LABEL_LG2_2
	BTFSC S9,2
	GOTO LABEL_LG2_TRUE

LABEL_LG2_FALSE
	BCF S9,1
	GOTO LABEL_LG2_ENDE
LABEL_LG2_TRUE
	BSF S9,1
LABEL_LG2_ENDE
;***************************************************
; ODER - Gatter -> LG3
;***************************************************

LABEL_LG3_1
	BTFSC S8,6
	GOTO LABEL_LG3_TRUE
LABEL_LG3_2
	BTFSC S9,0
	GOTO LABEL_LG3_TRUE

LABEL_LG3_FALSE
	BCF S8,7
	GOTO LABEL_LG3_ENDE
LABEL_LG3_TRUE
	BSF S8,7
LABEL_LG3_ENDE
;***************************************************
; Vergleich -> IF1
;***************************************************

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

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

LABEL_IF1_TRUE
	BSF S8,6
	GOTO LABEL_IF1_EXIT

LABEL_IF1_FALSE
	BCF S8,6

LABEL_IF1_EXIT
;***************************************************
; Vergleich -> IF2
;***************************************************

	MOVLW 9
	SUBWF ZV2,W	; F - W -> W

LABEL_IF2_CHECK
	BTFSS STATUS,CARRY	; Test auf -> >
	GOTO LABEL_IF2_FALSE
	BTFSC STATUS,ZERO
	GOTO LABEL_IF2_FALSE

LABEL_IF2_TRUE
	BSF S9,5
	GOTO LABEL_IF2_EXIT

LABEL_IF2_FALSE
	BCF S9,5

LABEL_IF2_EXIT
;***************************************************
; Vergleich -> IF3
;***************************************************

	MOVLW 5
	SUBWF ZV3,W	; F - W -> W

LABEL_IF3_CHECK
	BTFSS STATUS,CARRY	; Test auf -> >
	GOTO LABEL_IF3_FALSE
	BTFSC STATUS,ZERO
	GOTO LABEL_IF3_FALSE

LABEL_IF3_TRUE
	BSF S9,4
	GOTO LABEL_IF3_EXIT

LABEL_IF3_FALSE
	BCF S9,4

LABEL_IF3_EXIT
;***************************************************
; Vergleich -> IF4
;***************************************************

	MOVFW S0
	SUBWF ZV4,W	; F - W -> W

LABEL_IF4_CHECK
	BTFSS STATUS,CARRY	; Test auf -> >
	GOTO LABEL_IF4_FALSE
	BTFSC STATUS,ZERO
	GOTO LABEL_IF4_FALSE

LABEL_IF4_TRUE
	BSF S9,3
	GOTO LABEL_IF4_EXIT

LABEL_IF4_FALSE
	BCF S9,3

LABEL_IF4_EXIT
;***************************************************
; Vergleich -> IF5
;***************************************************

	MOVLW 2
	SUBWF ZV5,W	; F - W -> W

LABEL_IF5_CHECK
	BTFSS STATUS,CARRY	; Test auf -> >
	GOTO LABEL_IF5_FALSE
	BTFSC STATUS,ZERO
	GOTO LABEL_IF5_FALSE

LABEL_IF5_TRUE
	BSF S9,6
	GOTO LABEL_IF5_EXIT

LABEL_IF5_FALSE
	BCF S9,6

LABEL_IF5_EXIT
;***************************************************
; Multiplexer -> MX1
;***************************************************

	CLRF SYS_TMP1
	MOVFW ZV6
	BTFSS STATUS,ZERO
	GOTO LABEL_MX1_CHECKCONTROL1

	MOVLW 9
	MOVWF S0
	GOTO LABEL_MX1_END

LABEL_MX1_CHECKCONTROL1
	INCF SYS_TMP1,F
	MOVFW ZV6
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX1_CHECKCONTROL2

	MOVLW 9
	MOVWF S0
	GOTO LABEL_MX1_END

LABEL_MX1_CHECKCONTROL2
	INCF SYS_TMP1,F
	MOVFW ZV6
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX1_CHECKCONTROL3

	MOVLW 3
	MOVWF S0
	GOTO LABEL_MX1_END

LABEL_MX1_CHECKCONTROL3
	INCF SYS_TMP1,F
	MOVFW ZV6
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX1_CHECKCONTROL4

	MOVLW 9
	MOVWF S0
	GOTO LABEL_MX1_END

LABEL_MX1_CHECKCONTROL4

LABEL_MX1_END

;***************************************************
; Vergleich -> IF6
;***************************************************

	MOVLW 3
	SUBWF ZV6,W	; F - W -> W

LABEL_IF6_CHECK
	BTFSS STATUS,ZERO	; Test auf -> =
	GOTO LABEL_IF6_FALSE

LABEL_IF6_TRUE
	BSF S9,7
	GOTO LABEL_IF6_EXIT

LABEL_IF6_FALSE
	BCF S9,7

LABEL_IF6_EXIT
;***************************************************
; Zähler -> ZV6
;***************************************************

	BTFSS S9,7	; Reset ?
	GOTO LABEL_ZV6_COUNT
	CLRF ZV6
	GOTO LABEL_ZV6_SETOUT

LABEL_ZV6_COUNT

; Test auf positive Flanke

	BTFSS S9,3
	GOTO LABEL_ZV6_SETFD
	BTFSC ZV6_FD,0
	GOTO LABEL_ZV6_SETFD

	BSF ZV6_FD,0


	BTFSC S10,1	; Vorwärts oder Rückwärts ?
	GOTO LABEL_ZV6_BACKWARD

	INCF ZV6,F
	GOTO LABEL_ZV6_SETOUT

LABEL_ZV6_BACKWARD
	DECF ZV6,F

LABEL_ZV6_SETOUT


LABEL_ZV6_SETFD

; Test auf negative Flanke

	BTFSC S9,3
	GOTO LABEL_ZV6_EXIT
	BCF ZV6_FD,0

LABEL_ZV6_EXIT

;***************************************************
; ODER - Gatter -> LG4
;***************************************************

LABEL_LG4_1
	BTFSC S9,3
	GOTO LABEL_LG4_TRUE
LABEL_LG4_2
	BTFSC S9,7
	GOTO LABEL_LG4_TRUE

LABEL_LG4_FALSE
	BCF S10,0
	GOTO LABEL_LG4_ENDE
LABEL_LG4_TRUE
	BSF S10,0
LABEL_LG4_ENDE
;***************************************************
; Multiplexer -> MX2
;***************************************************

	CLRF SYS_TMP1
	MOVFW ZV7
	BTFSS STATUS,ZERO
	GOTO LABEL_MX2_CHECKCONTROL1

	MOVFW ZV2
	MOVWF S1
	GOTO LABEL_MX2_END

LABEL_MX2_CHECKCONTROL1
	INCF SYS_TMP1,F
	MOVFW ZV7
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX2_CHECKCONTROL2

	MOVFW ZV3
	MOVWF S1
	GOTO LABEL_MX2_END

LABEL_MX2_CHECKCONTROL2
	INCF SYS_TMP1,F
	MOVFW ZV7
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX2_CHECKCONTROL3

	MOVFW ZV4
	MOVWF S1
	GOTO LABEL_MX2_END

LABEL_MX2_CHECKCONTROL3
	INCF SYS_TMP1,F
	MOVFW ZV7
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX2_CHECKCONTROL4

	MOVFW ZV5
	MOVWF S1
	GOTO LABEL_MX2_END

LABEL_MX2_CHECKCONTROL4

LABEL_MX2_END

;***************************************************
; Verteiler -> BV1
;***************************************************

	BTFSC S1,0
	GOTO LABEL_BV1_0
	BCF STATUS,RP0	; Bank 0
	BCF PORTB,4
	GOTO LABEL_BV1_0_END
LABEL_BV1_0
	BCF STATUS,RP0	; Bank 0
	BSF PORTB,4
LABEL_BV1_0_END

;**********************************************

	BTFSC S1,1
	GOTO LABEL_BV1_1
	BCF PORTB,7
	GOTO LABEL_BV1_1_END
LABEL_BV1_1
	BSF PORTB,7
LABEL_BV1_1_END

;**********************************************

	BTFSC S1,2
	GOTO LABEL_BV1_2
	BCF PORTB,6
	GOTO LABEL_BV1_2_END
LABEL_BV1_2
	BSF PORTB,6
LABEL_BV1_2_END

;**********************************************

	BTFSC S1,3
	GOTO LABEL_BV1_3
	BCF PORTB,5
	GOTO LABEL_BV1_3_END
LABEL_BV1_3
	BSF PORTB,5
LABEL_BV1_3_END

;**********************************************


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

	BCF S10,1	; immer Low

;***************************************************
; Timer -> TR2
;***************************************************

	MOVLW 0	; Test auf >=
	SUBWF TR2_HI,W	;F-W -> W
	BTFSS STATUS,ZERO
	GOTO LABEL_TR2_CHECK
	MOVLW 4
	SUBWF TR2,W	;F-W -> W
LABEL_TR2_CHECK
	BTFSS STATUS,CARRY
	GOTO LABEL_TR2_ENDE

LABEL_TR2_RESET
	MOVLW 0	; Test auf >=
	SUBWF TR2_HI,F	;F-W -> F
	MOVLW 4
	SUBWF TR2,F	;F-W -> F
	BTFSS STATUS,CARRY
	DECF TR2_HI,F

LABEL_TR2_SET	; toggel output
	BTFSC S10,2
	GOTO LABEL_TR2_CLR
	BSF S10,2
	GOTO LABEL_TR2_ENDE
LABEL_TR2_CLR
	BCF S10,2
LABEL_TR2_ENDE

;***************************************************
; Zähler -> ZV7
;***************************************************

	BTFSS S10,3	; Reset ?
	GOTO LABEL_ZV7_COUNT
	CLRF ZV7
	GOTO LABEL_ZV7_SETOUT

LABEL_ZV7_COUNT

; Test auf positive Flanke

	BTFSS S10,2
	GOTO LABEL_ZV7_SETFD
	BTFSC ZV7_FD,0
	GOTO LABEL_ZV7_SETFD

	BSF ZV7_FD,0


	BTFSC S10,4	; Vorwärts oder Rückwärts ?
	GOTO LABEL_ZV7_BACKWARD

	INCF ZV7,F
	GOTO LABEL_ZV7_SETOUT

LABEL_ZV7_BACKWARD
	DECF ZV7,F

LABEL_ZV7_SETOUT


LABEL_ZV7_SETFD

; Test auf negative Flanke

	BTFSC S10,2
	GOTO LABEL_ZV7_EXIT
	BCF ZV7_FD,0

LABEL_ZV7_EXIT

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

	BCF S10,4	; immer Low

;***************************************************
; Multiplexer -> MX3
;***************************************************

	CLRF SYS_TMP1
	MOVFW S3
	BTFSS STATUS,ZERO
	GOTO LABEL_MX3_CHECKCONTROL1

	MOVFW S2
	MOVWF S2
	GOTO LABEL_MX3_END

LABEL_MX3_CHECKCONTROL1
	INCF SYS_TMP1,F
	MOVFW S3
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX3_CHECKCONTROL2

	MOVFW ZV8
	MOVWF S2
	GOTO LABEL_MX3_END

LABEL_MX3_CHECKCONTROL2

LABEL_MX3_END

;***************************************************
; Verteiler -> BV2
;***************************************************

	MOVLW 0 
	BCF STATUS,RP0	; Bank 0
	BTFSC PORTA,1	; IN0
	IORLW 1
	MOVWF S3	; OUT

;***************************************************
; Vergleich -> IF7
;***************************************************

	MOVFW S2
	SUBWF ZV8,W	; F - W -> W

LABEL_IF7_CHECK
	BTFSS STATUS,ZERO	; Test auf -> =
	GOTO LABEL_IF7_FALSE

LABEL_IF7_TRUE
	BSF S10,7
	GOTO LABEL_IF7_EXIT

LABEL_IF7_FALSE
	BCF S10,7

LABEL_IF7_EXIT
;***************************************************
; Zähler -> ZV8
;***************************************************

	BTFSS S11,0	; Reset ?
	GOTO LABEL_ZV8_COUNT
	CLRF ZV8
	GOTO LABEL_ZV8_SETOUT

LABEL_ZV8_COUNT

; Test auf positive Flanke

	BTFSS S10,6
	GOTO LABEL_ZV8_SETFD
	BTFSC ZV8_FD,0
	GOTO LABEL_ZV8_SETFD

	BSF ZV8_FD,0


	BTFSC S11,1	; Vorwärts oder Rückwärts ?
	GOTO LABEL_ZV8_BACKWARD

	INCF ZV8,F
	GOTO LABEL_ZV8_SETOUT

LABEL_ZV8_BACKWARD
	DECF ZV8,F

LABEL_ZV8_SETOUT


LABEL_ZV8_SETFD

; Test auf negative Flanke

	BTFSC S10,6
	GOTO LABEL_ZV8_EXIT
	BCF ZV8_FD,0

LABEL_ZV8_EXIT

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

	BCF S11,1	; immer Low

;***************************************************
; Multiplexer -> MX4
;***************************************************

	CLRF SYS_TMP1
	MOVFW S5
	BTFSS STATUS,ZERO
	GOTO LABEL_MX4_CHECKCONTROL1

	MOVFW S4
	MOVWF S4
	GOTO LABEL_MX4_END

LABEL_MX4_CHECKCONTROL1
	INCF SYS_TMP1,F
	MOVFW S5
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX4_CHECKCONTROL2

	MOVFW ZV9
	MOVWF S4
	GOTO LABEL_MX4_END

LABEL_MX4_CHECKCONTROL2

LABEL_MX4_END

;***************************************************
; Verteiler -> BV3
;***************************************************

	MOVLW 0 
	BCF STATUS,RP0	; Bank 0
	BTFSC PORTA,1	; IN0
	IORLW 1
	MOVWF S5	; OUT

;***************************************************
; Zähler -> ZV9
;***************************************************

	BTFSS S9,5	; Reset ?
	GOTO LABEL_ZV9_COUNT
	CLRF ZV9
	GOTO LABEL_ZV9_SETOUT

LABEL_ZV9_COUNT

; Test auf positive Flanke

	BTFSS S8,7
	GOTO LABEL_ZV9_SETFD
	BTFSC ZV9_FD,0
	GOTO LABEL_ZV9_SETFD

	BSF ZV9_FD,0


	BTFSC S11,2	; Vorwärts oder Rückwärts ?
	GOTO LABEL_ZV9_BACKWARD

	INCF ZV9,F
	GOTO LABEL_ZV9_SETOUT

LABEL_ZV9_BACKWARD
	DECF ZV9,F

LABEL_ZV9_SETOUT


LABEL_ZV9_SETFD

; Test auf negative Flanke

	BTFSC S8,7
	GOTO LABEL_ZV9_EXIT
	BCF ZV9_FD,0

LABEL_ZV9_EXIT

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

	BCF S11,2	; immer Low

;***************************************************
; Vergleich -> IF8
;***************************************************

	MOVFW ZV9
	SUBWF S4,W	; F - W -> W

LABEL_IF8_CHECK
	BTFSS STATUS,ZERO	; Test auf -> =
	GOTO LABEL_IF8_FALSE

LABEL_IF8_TRUE
	BSF S11,3
	GOTO LABEL_IF8_EXIT

LABEL_IF8_FALSE
	BCF S11,3

LABEL_IF8_EXIT
;***************************************************
; UND - Gatter -> LG5
;***************************************************

LABEL_LG5_1
	BTFSS S10,7
	GOTO LABEL_LG5_FALSE
LABEL_LG5_2
	BTFSS S11,3
	GOTO LABEL_LG5_FALSE
LABEL_LG5_3
	BTFSS S11,6
	GOTO LABEL_LG5_FALSE

LABEL_LG5_TRUE
	BSF S11,4
	GOTO LABEL_LG5_ENDE
LABEL_LG5_FALSE
	BCF S11,4
LABEL_LG5_ENDE
;***************************************************
; Zähler -> ZV10
;***************************************************

	BTFSS S9,4	; Reset ?
	GOTO LABEL_ZV10_COUNT
	CLRF ZV10
	GOTO LABEL_ZV10_SETOUT

LABEL_ZV10_COUNT

; Test auf positive Flanke

	BTFSS S9,1
	GOTO LABEL_ZV10_SETFD
	BTFSC ZV10_FD,0
	GOTO LABEL_ZV10_SETFD

	BSF ZV10_FD,0


	BTFSC S11,5	; Vorwärts oder Rückwärts ?
	GOTO LABEL_ZV10_BACKWARD

	INCF ZV10,F
	GOTO LABEL_ZV10_SETOUT

LABEL_ZV10_BACKWARD
	DECF ZV10,F

LABEL_ZV10_SETOUT


LABEL_ZV10_SETFD

; Test auf negative Flanke

	BTFSC S9,1
	GOTO LABEL_ZV10_EXIT
	BCF ZV10_FD,0

LABEL_ZV10_EXIT

;***************************************************
; Multiplexer -> MX5
;***************************************************

	CLRF SYS_TMP1
	MOVFW S6
	BTFSS STATUS,ZERO
	GOTO LABEL_MX5_CHECKCONTROL1

	MOVFW S7
	MOVWF S7
	GOTO LABEL_MX5_END

LABEL_MX5_CHECKCONTROL1
	INCF SYS_TMP1,F
	MOVFW S6
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX5_CHECKCONTROL2

	MOVFW ZV10
	MOVWF S7
	GOTO LABEL_MX5_END

LABEL_MX5_CHECKCONTROL2

LABEL_MX5_END

;***************************************************
; Verteiler -> BV4
;***************************************************

	MOVLW 0 
	BCF STATUS,RP0	; Bank 0
	BTFSC PORTA,1	; IN0
	IORLW 1
	MOVWF S6	; OUT

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

	BCF S11,5	; immer Low

;***************************************************
; Vergleich -> IF9
;***************************************************

	MOVFW ZV10
	SUBWF S7,W	; F - W -> W

LABEL_IF9_CHECK
	BTFSS STATUS,ZERO	; Test auf -> =
	GOTO LABEL_IF9_FALSE

LABEL_IF9_TRUE
	BSF S11,6
	GOTO LABEL_IF9_EXIT

LABEL_IF9_FALSE
	BCF S11,6

LABEL_IF9_EXIT
;***************************************************
; Vergleich -> IF10
;***************************************************

	MOVLW 23
	SUBWF ZV8,W	; F - W -> W

LABEL_IF10_CHECK
	BTFSS STATUS,CARRY	; Test auf -> >
	GOTO LABEL_IF10_FALSE
	BTFSC STATUS,ZERO
	GOTO LABEL_IF10_FALSE

LABEL_IF10_TRUE
	BSF S11,0
	GOTO LABEL_IF10_EXIT

LABEL_IF10_FALSE
	BCF S11,0

LABEL_IF10_EXIT
;***************************************************
; 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
	BCF STATUS,RP0	; Bank 0
	BTFSS PORTA,4
	GOTO LABEL_MF1_SETFD


LABEL_MF1_RESET

	CLRF MF1
	CLRF MF1_HI
	BSF MF1_FD,1
	BSF S9,0

LABEL_MF1_CHKTIME

	MOVLW 0
	SUBWF MF1_HI,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MF1_CHECK
	MOVLW 195
	SUBWF MF1,W
LABEL_MF1_CHECK
	BTFSS STATUS,CARRY
	GOTO LABEL_MF1_SETFD
LABEL_MF1_TO

	BCF MF1_FD,1
	BCF S9,0

LABEL_MF1_SETFD

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

LABEL_MF1_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
	BCF STATUS,RP0	; Bank 0
	BTFSS PORTA,3
	GOTO LABEL_MF2_SETFD


LABEL_MF2_RESET

	CLRF MF2
	CLRF MF2_HI
	BSF MF2_FD,1
	BSF S9,2

LABEL_MF2_CHKTIME

	MOVLW 0
	SUBWF MF2_HI,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MF2_CHECK
	MOVLW 195
	SUBWF MF2,W
LABEL_MF2_CHECK
	BTFSS STATUS,CARRY
	GOTO LABEL_MF2_SETFD
LABEL_MF2_TO

	BCF MF2_FD,1
	BCF S9,2

LABEL_MF2_SETFD

	BCF STATUS,RP0	; Bank 0
	BTFSS PORTA,3
	GOTO LABEL_MF2_CLR
	BSF MF2_FD,0
	GOTO LABEL_MF2_ENDE
LABEL_MF2_CLR
	BCF MF2_FD,0

LABEL_MF2_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 PORTA,2
	GOTO LABEL_MF3_SETFD


LABEL_MF3_RESET

	CLRF MF3
	CLRF MF3_HI
	BSF MF3_FD,1
	BSF S10,5

LABEL_MF3_CHKTIME

	MOVLW 0
	SUBWF MF3_HI,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MF3_CHECK
	MOVLW 195
	SUBWF MF3,W
LABEL_MF3_CHECK
	BTFSS STATUS,CARRY
	GOTO LABEL_MF3_SETFD
LABEL_MF3_TO

	BCF MF3_FD,1
	BCF S10,5

LABEL_MF3_SETFD

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

LABEL_MF3_ENDE

;***************************************************
; Timer -> TR3
;***************************************************

	MOVLW 15	; Test auf >=
	SUBWF TR3_HI,W	;F-W -> W
	BTFSS STATUS,ZERO
	GOTO LABEL_TR3_CHECK
	MOVLW 66
	SUBWF TR3,W	;F-W -> W
LABEL_TR3_CHECK
	BTFSS STATUS,CARRY
	GOTO LABEL_TR3_ENDE

LABEL_TR3_RESET
	MOVLW 15	; Test auf >=
	SUBWF TR3_HI,F	;F-W -> F
	MOVLW 66
	SUBWF TR3,F	;F-W -> F
	BTFSS STATUS,CARRY
	DECF TR3_HI,F

LABEL_TR3_SET	; toggel output
	BTFSC S11,7
	GOTO LABEL_TR3_CLR
	BSF S11,7
	GOTO LABEL_TR3_ENDE
LABEL_TR3_CLR
	BCF S11,7
LABEL_TR3_ENDE

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

LABEL_LG6_1
	BTFSS S11,4
	GOTO LABEL_LG6_FALSE
LABEL_LG6_2
	BTFSS S11,7
	GOTO LABEL_LG6_FALSE

LABEL_LG6_TRUE
	BCF STATUS,RP0	; Bank 0
	BSF PORTA,0
	GOTO LABEL_LG6_ENDE
LABEL_LG6_FALSE
	BCF STATUS,RP0	; Bank 0
	BCF PORTA,0
LABEL_LG6_ENDE
;***************************************************
; Vergleich -> IF11
;***************************************************

	MOVLW 3
	SUBWF ZV7,W	; F - W -> W

LABEL_IF11_CHECK
	BTFSS STATUS,CARRY	; Test auf -> >
	GOTO LABEL_IF11_FALSE
	BTFSC STATUS,ZERO
	GOTO LABEL_IF11_FALSE

LABEL_IF11_TRUE
	BSF S10,3
	GOTO LABEL_IF11_EXIT

LABEL_IF11_FALSE
	BCF S10,3

LABEL_IF11_EXIT
;***************************************************
; Vergleich -> IF12
;***************************************************

	MOVLW 0
	SUBWF ZV7,W	; F - W -> W

LABEL_IF12_CHECK
	BCF STATUS,RP0	; Bank 0
	BTFSS STATUS,ZERO	; Test auf -> =
	GOTO LABEL_IF12_FALSE

LABEL_IF12_TRUE
	BSF PORTB,0
	GOTO LABEL_IF12_EXIT

LABEL_IF12_FALSE
	BCF PORTB,0

LABEL_IF12_EXIT
;***************************************************
; Vergleich -> IF13
;***************************************************

	MOVLW 1
	SUBWF ZV7,W	; F - W -> W

LABEL_IF13_CHECK
	BCF STATUS,RP0	; Bank 0
	BTFSS STATUS,ZERO	; Test auf -> =
	GOTO LABEL_IF13_FALSE

LABEL_IF13_TRUE
	BSF PORTB,1
	GOTO LABEL_IF13_EXIT

LABEL_IF13_FALSE
	BCF PORTB,1

LABEL_IF13_EXIT
;***************************************************
; Vergleich -> IF14
;***************************************************

	MOVLW 2
	SUBWF ZV7,W	; F - W -> W

LABEL_IF14_CHECK
	BCF STATUS,RP0	; Bank 0
	BTFSS STATUS,ZERO	; Test auf -> =
	GOTO LABEL_IF14_FALSE

LABEL_IF14_TRUE
	BSF PORTB,3
	GOTO LABEL_IF14_EXIT

LABEL_IF14_FALSE
	BCF PORTB,3

LABEL_IF14_EXIT
;***************************************************
; Vergleich -> IF15
;***************************************************

	MOVLW 3
	SUBWF ZV7,W	; F - W -> W

LABEL_IF15_CHECK
	BCF STATUS,RP0	; Bank 0
	BTFSS STATUS,ZERO	; Test auf -> =
	GOTO LABEL_IF15_FALSE

LABEL_IF15_TRUE
	BSF PORTB,2
	GOTO LABEL_IF15_EXIT

LABEL_IF15_FALSE
	BCF PORTB,2

LABEL_IF15_EXIT
;****************************************

	GOTO MAIN


	END

