; Source created with Parsic Version 3.x

; at              : 16.01.2000 15:37:31


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

; Project Version : 1.0.20

; Created         : 14.03.1999 21:14:00

; Last change     : 13.01.2000 03:33:00

	PROCESSOR 16F877

	INCLUDE P16F877.INC

	RADIX DEC


	__IDLOCS H'0100'

	__CONFIG _CP_OFF & _PWRTE_ON & _WDT_ON & _BODEN_ON & _XT_OSC & _LVP_OFF & _CPD_OFF & _DEBUG_OFF

; Diverses

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


; Variable

Z1	= 32	; located in Bank 0
Z1_FD	= 33	; located in Bank 0
S2	= 34	; located in Bank 0
S1	= 35	; located in Bank 0
Z10	= 36	; located in Bank 0
Z10_FD	= 37	; located in Bank 0
S3	= 38	; located in Bank 0
TR1	= 39	; located in Bank 0
TR1_HI	= 40	; located in Bank 0
S0	= 41	; located in Bank 0
Z100	= 42	; located in Bank 0
Z100_FD	= 43	; located in Bank 0
S4	= 44	; located in Bank 0
Z1000	= 45	; located in Bank 0
Z1000_FD	= 46	; located in Bank 0
TR2	= 47	; located in Bank 0
TR2_HI	= 48	; located in Bank 0
ZV1	= 49	; located in Bank 0
ZV1_FD	= 50	; located in Bank 0
S5	= 51	; located in Bank 0
RAM	= 52	; located in Bank 0
SYS_TMP1	= 118	; located in Bank 0, 1, 2, 3
SYS_WSAV	= 119	; located in Bank 0, 1, 2, 3
SYS_SSAV	= 120	; located in Bank 0, 1, 2, 3
SYS_PSAV	= 121	; located in Bank 0, 1, 2, 3

	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
	MOVFW PCLATH
	MOVWF SYS_PSAV
	CLRF PCLATH

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	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
	BCF INTCON,T0IF	; Interrupt quitieren

EXITINT
	MOVFW SYS_PSAV
	MOVWF PCLATH

	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
	BCF STATUS,RP1	; Bank 0
	MOVLW B'00000000'
	MOVWF PORTA

	MOVLW B'01111111'
	MOVWF PORTB

	MOVLW B'00000000'
	MOVWF PORTC

	MOVLW B'00000000'
	MOVWF PORTD

	MOVLW B'00000000'
	MOVWF PORTE

	MOVLW 143
	BSF STATUS,RP0	; Bank 1
	MOVWF OPTION_REG

	MOVLW 6	; all Digital
	MOVWF ADCON1

; Richtung setzen

	MOVLW B'11110000'
	MOVWF TRISA

	MOVLW B'10000000'
	MOVWF TRISB

	MOVLW B'11111111'
	MOVWF TRISC

	MOVLW B'11111111'
	MOVWF TRISD

	MOVLW B'00000111'
	MOVWF TRISE

; init var

	BCF STATUS,RP0	; Bank 0
	CLRF Z1
	CLRF Z1_FD
	CLRF S2
	CLRF S1
	CLRF SYS_TMP1
	CLRF Z10
	CLRF Z10_FD
	CLRF S3
	CLRF SYS_WSAV
	CLRF SYS_SSAV
	CLRF SYS_PSAV
	CLRF TR1
	CLRF TR1_HI
	CLRF S0
	CLRF Z100
	CLRF Z100_FD
	CLRF S4
	CLRF Z1000
	CLRF Z1000_FD
	CLRF TR2
	CLRF TR2_HI
	CLRF ZV1
	CLRF ZV1_FD
	CLRF S5

	CLRF TMR0
	BCF INTCON,T0IF
	BSF INTCON,GIE	; Interrupt freigeben

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

MAIN

	CLRWDT

;***************************************************
; Zähler -> Z1
;***************************************************

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSS S2,4	; Reset ?
	GOTO LABEL_Z1_COUNT
	CLRF Z1
	GOTO LABEL_Z1_SETOUT

LABEL_Z1_COUNT

; Test auf positive Flanke

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSC Z1_FD,0
	GOTO LABEL_Z1_SETFD
	BTFSS S2,5
	GOTO LABEL_Z1_SETFD

	INCF Z1,F

LABEL_Z1_SETOUT

; Output Q0

	BTFSS Z1,0
	GOTO LABEL_Z1_SETOUT0
	BSF S2,0
	GOTO LABEL_Z1_SETOUT0_END
LABEL_Z1_SETOUT0
	BCF S2,0
LABEL_Z1_SETOUT0_END

; Output Q1

	BTFSS Z1,1
	GOTO LABEL_Z1_SETOUT1
	BSF S2,1
	GOTO LABEL_Z1_SETOUT1_END
LABEL_Z1_SETOUT1
	BCF S2,1
LABEL_Z1_SETOUT1_END

; Output Q2

	BTFSS Z1,2
	GOTO LABEL_Z1_SETOUT2
	BSF S2,2
	GOTO LABEL_Z1_SETOUT2_END
LABEL_Z1_SETOUT2
	BCF S2,2
LABEL_Z1_SETOUT2_END

; Output Q3

	BTFSS Z1,3
	GOTO LABEL_Z1_SETOUT3
	BSF S2,3
	GOTO LABEL_Z1_SETOUT3_END
LABEL_Z1_SETOUT3
	BCF S2,3
LABEL_Z1_SETOUT3_END

LABEL_Z1_SETFD

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSS S2,5
	GOTO LABEL_Z1_SETFD2
	BSF Z1_FD,0
	GOTO LABEL_Z1_END
LABEL_Z1_SETFD2
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF Z1_FD,0
LABEL_Z1_END

;***************************************************
; Unterprogramm BIN_TO_7SEG aufrufen
;***************************************************

	MOVLW HIGH BIN_TO_7SEG
	MOVWF PCLATH
	MOVFW S0

	CALL BIN_TO_7SEG

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	MOVWF S1

	MOVLW HIGH LABEL_CALL_BIN_TO_7SEG
	MOVWF PCLATH
LABEL_CALL_BIN_TO_7SEG

;***************************************************
; UND - Gatter -> UG1
;***************************************************

LABEL_UG1_1
	BTFSC S2,0
	GOTO LABEL_UG1_FALSE
LABEL_UG1_2
	BTFSS S2,1
	GOTO LABEL_UG1_FALSE
LABEL_UG1_3
	BTFSC S2,2
	GOTO LABEL_UG1_FALSE
LABEL_UG1_4
	BTFSS S2,3
	GOTO LABEL_UG1_FALSE

LABEL_UG1_TRUE
	BSF S2,4
	GOTO LABEL_UG1_ENDE
LABEL_UG1_FALSE
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF S2,4
LABEL_UG1_ENDE
;***************************************************
; Zähler -> Z10
;***************************************************

	BTFSS S3,2	; Reset ?
	GOTO LABEL_Z10_COUNT
	CLRF Z10
	GOTO LABEL_Z10_SETOUT

LABEL_Z10_COUNT

; Test auf positive Flanke

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSC Z10_FD,0
	GOTO LABEL_Z10_SETFD
	BTFSS S2,4
	GOTO LABEL_Z10_SETFD

	INCF Z10,F

LABEL_Z10_SETOUT

; Output Q0

	BTFSS Z10,0
	GOTO LABEL_Z10_SETOUT0
	BSF S2,6
	GOTO LABEL_Z10_SETOUT0_END
LABEL_Z10_SETOUT0
	BCF S2,6
LABEL_Z10_SETOUT0_END

; Output Q1

	BTFSS Z10,1
	GOTO LABEL_Z10_SETOUT1
	BSF S2,7
	GOTO LABEL_Z10_SETOUT1_END
LABEL_Z10_SETOUT1
	BCF S2,7
LABEL_Z10_SETOUT1_END

; Output Q2

	BTFSS Z10,2
	GOTO LABEL_Z10_SETOUT2
	BSF S3,0
	GOTO LABEL_Z10_SETOUT2_END
LABEL_Z10_SETOUT2
	BCF S3,0
LABEL_Z10_SETOUT2_END

; Output Q3

	BTFSS Z10,3
	GOTO LABEL_Z10_SETOUT3
	BSF S3,1
	GOTO LABEL_Z10_SETOUT3_END
LABEL_Z10_SETOUT3
	BCF S3,1
LABEL_Z10_SETOUT3_END

LABEL_Z10_SETFD

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSS S2,4
	GOTO LABEL_Z10_SETFD2
	BSF Z10_FD,0
	GOTO LABEL_Z10_END
LABEL_Z10_SETFD2
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF Z10_FD,0
LABEL_Z10_END

;***************************************************
; UND - Gatter -> UG9
;***************************************************

LABEL_UG9_1
	BTFSC S2,6
	GOTO LABEL_UG9_FALSE
LABEL_UG9_2
	BTFSS S2,7
	GOTO LABEL_UG9_FALSE
LABEL_UG9_3
	BTFSC S3,0
	GOTO LABEL_UG9_FALSE
LABEL_UG9_4
	BTFSS S3,1
	GOTO LABEL_UG9_FALSE

LABEL_UG9_TRUE
	BSF S3,2
	GOTO LABEL_UG9_ENDE
LABEL_UG9_FALSE
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF S3,2
LABEL_UG9_ENDE
;***************************************************
; Timer -> TR1
;***************************************************

	MOVLW 0	; Test auf >=
	SUBWF TR1_HI,W	;F-W -> W
	BTFSS STATUS,CARRY
	GOTO LABEL_TR1_ENDE
	MOVLW 8
	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

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

	CLRF SYS_TMP1
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	MOVFW ZV1
	BTFSS STATUS,ZERO
	GOTO LABEL_MX1_CHECKCONTROL1

	MOVFW Z1
	MOVWF S0
	GOTO LABEL_MX1_END

LABEL_MX1_CHECKCONTROL1
	INCF SYS_TMP1,F
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	MOVFW ZV1
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX1_CHECKCONTROL2

	MOVFW Z10
	MOVWF S0
	GOTO LABEL_MX1_END

LABEL_MX1_CHECKCONTROL2
	INCF SYS_TMP1,F
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	MOVFW ZV1
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX1_CHECKCONTROL3

	MOVFW Z100
	MOVWF S0
	GOTO LABEL_MX1_END

LABEL_MX1_CHECKCONTROL3
	INCF SYS_TMP1,F
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	MOVFW ZV1
	SUBWF SYS_TMP1,W
	BTFSS STATUS,ZERO
	GOTO LABEL_MX1_CHECKCONTROL4

	MOVFW Z1000
	MOVWF S0
	GOTO LABEL_MX1_END

LABEL_MX1_CHECKCONTROL4

LABEL_MX1_END

;***************************************************
; Zähler -> Z100
;***************************************************

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSS S4,0	; Reset ?
	GOTO LABEL_Z100_COUNT
	CLRF Z100
	GOTO LABEL_Z100_SETOUT

LABEL_Z100_COUNT

; Test auf positive Flanke

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSC Z100_FD,0
	GOTO LABEL_Z100_SETFD
	BTFSS S3,2
	GOTO LABEL_Z100_SETFD

	INCF Z100,F

LABEL_Z100_SETOUT

; Output Q0

	BTFSS Z100,0
	GOTO LABEL_Z100_SETOUT0
	BSF S3,4
	GOTO LABEL_Z100_SETOUT0_END
LABEL_Z100_SETOUT0
	BCF S3,4
LABEL_Z100_SETOUT0_END

; Output Q1

	BTFSS Z100,1
	GOTO LABEL_Z100_SETOUT1
	BSF S3,5
	GOTO LABEL_Z100_SETOUT1_END
LABEL_Z100_SETOUT1
	BCF S3,5
LABEL_Z100_SETOUT1_END

; Output Q2

	BTFSS Z100,2
	GOTO LABEL_Z100_SETOUT2
	BSF S3,6
	GOTO LABEL_Z100_SETOUT2_END
LABEL_Z100_SETOUT2
	BCF S3,6
LABEL_Z100_SETOUT2_END

; Output Q3

	BTFSS Z100,3
	GOTO LABEL_Z100_SETOUT3
	BSF S3,7
	GOTO LABEL_Z100_SETOUT3_END
LABEL_Z100_SETOUT3
	BCF S3,7
LABEL_Z100_SETOUT3_END

LABEL_Z100_SETFD

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSS S3,2
	GOTO LABEL_Z100_SETFD2
	BSF Z100_FD,0
	GOTO LABEL_Z100_END
LABEL_Z100_SETFD2
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF Z100_FD,0
LABEL_Z100_END

;***************************************************
; UND - Gatter -> UG10
;***************************************************

LABEL_UG10_1
	BTFSC S3,4
	GOTO LABEL_UG10_FALSE
LABEL_UG10_2
	BTFSS S3,5
	GOTO LABEL_UG10_FALSE
LABEL_UG10_3
	BTFSC S3,6
	GOTO LABEL_UG10_FALSE
LABEL_UG10_4
	BTFSS S3,7
	GOTO LABEL_UG10_FALSE

LABEL_UG10_TRUE
	BSF S4,0
	GOTO LABEL_UG10_ENDE
LABEL_UG10_FALSE
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF S4,0
LABEL_UG10_ENDE
;***************************************************
; Zähler -> Z1000
;***************************************************

	BTFSS S4,5	; Reset ?
	GOTO LABEL_Z1000_COUNT
	CLRF Z1000
	GOTO LABEL_Z1000_SETOUT

LABEL_Z1000_COUNT

; Test auf positive Flanke

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSC Z1000_FD,0
	GOTO LABEL_Z1000_SETFD
	BTFSS S4,0
	GOTO LABEL_Z1000_SETFD

	INCF Z1000,F

LABEL_Z1000_SETOUT

; Output Q0

	BTFSS Z1000,0
	GOTO LABEL_Z1000_SETOUT0
	BSF S4,1
	GOTO LABEL_Z1000_SETOUT0_END
LABEL_Z1000_SETOUT0
	BCF S4,1
LABEL_Z1000_SETOUT0_END

; Output Q1

	BTFSS Z1000,1
	GOTO LABEL_Z1000_SETOUT1
	BSF S4,2
	GOTO LABEL_Z1000_SETOUT1_END
LABEL_Z1000_SETOUT1
	BCF S4,2
LABEL_Z1000_SETOUT1_END

; Output Q2

	BTFSS Z1000,2
	GOTO LABEL_Z1000_SETOUT2
	BSF S4,3
	GOTO LABEL_Z1000_SETOUT2_END
LABEL_Z1000_SETOUT2
	BCF S4,3
LABEL_Z1000_SETOUT2_END

; Output Q3

	BTFSS Z1000,3
	GOTO LABEL_Z1000_SETOUT3
	BSF S4,4
	GOTO LABEL_Z1000_SETOUT3_END
LABEL_Z1000_SETOUT3
	BCF S4,4
LABEL_Z1000_SETOUT3_END

LABEL_Z1000_SETFD

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSS S4,0
	GOTO LABEL_Z1000_SETFD2
	BSF Z1000_FD,0
	GOTO LABEL_Z1000_END
LABEL_Z1000_SETFD2
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF Z1000_FD,0
LABEL_Z1000_END

;***************************************************
; UND - Gatter -> UG11
;***************************************************

LABEL_UG11_1
	BTFSC S4,1
	GOTO LABEL_UG11_FALSE
LABEL_UG11_2
	BTFSS S4,2
	GOTO LABEL_UG11_FALSE
LABEL_UG11_3
	BTFSC S4,3
	GOTO LABEL_UG11_FALSE
LABEL_UG11_4
	BTFSS S4,4
	GOTO LABEL_UG11_FALSE

LABEL_UG11_TRUE
	BSF S4,5
	GOTO LABEL_UG11_ENDE
LABEL_UG11_FALSE
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF S4,5
LABEL_UG11_ENDE
;***************************************************
; UND - Gatter -> UG12
;***************************************************

LABEL_UG12_1
	BTFSC S4,6
	GOTO LABEL_UG12_FALSE
LABEL_UG12_2
	BTFSC S4,7
	GOTO LABEL_UG12_FALSE

LABEL_UG12_TRUE
	BSF PORTA,0
	GOTO LABEL_UG12_ENDE
LABEL_UG12_FALSE
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF PORTA,0
LABEL_UG12_ENDE
;***************************************************
; UND - Gatter -> UG13
;***************************************************

LABEL_UG13_1
	BTFSS S4,6
	GOTO LABEL_UG13_FALSE
LABEL_UG13_2
	BTFSC S4,7
	GOTO LABEL_UG13_FALSE

LABEL_UG13_TRUE
	BSF PORTA,1
	GOTO LABEL_UG13_ENDE
LABEL_UG13_FALSE
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF PORTA,1
LABEL_UG13_ENDE
;***************************************************
; UND - Gatter -> UG14
;***************************************************

LABEL_UG14_1
	BTFSC S4,6
	GOTO LABEL_UG14_FALSE
LABEL_UG14_2
	BTFSS S4,7
	GOTO LABEL_UG14_FALSE

LABEL_UG14_TRUE
	BSF PORTA,2
	GOTO LABEL_UG14_ENDE
LABEL_UG14_FALSE
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF PORTA,2
LABEL_UG14_ENDE
;***************************************************
; UND - Gatter -> UG15
;***************************************************

LABEL_UG15_1
	BTFSS S4,6
	GOTO LABEL_UG15_FALSE
LABEL_UG15_2
	BTFSS S4,7
	GOTO LABEL_UG15_FALSE

LABEL_UG15_TRUE
	BSF PORTA,3
	GOTO LABEL_UG15_ENDE
LABEL_UG15_FALSE
	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BCF PORTA,3
LABEL_UG15_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,5
	GOTO LABEL_TR2_CLR
	BSF S2,5
	GOTO LABEL_TR2_ENDE
LABEL_TR2_CLR
	BCF S2,5
LABEL_TR2_ENDE

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

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

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

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

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

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

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

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

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

	BTFSC S1,4
	GOTO LABEL_BV1_4
	BSF PORTB,4
	GOTO LABEL_BV1_4_END
LABEL_BV1_4
	BCF PORTB,4
LABEL_BV1_4_END

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

	BTFSC S1,5
	GOTO LABEL_BV1_5
	BSF PORTB,5
	GOTO LABEL_BV1_5_END
LABEL_BV1_5
	BCF PORTB,5
LABEL_BV1_5_END

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

	BTFSC S1,6
	GOTO LABEL_BV1_6
	BSF PORTB,6
	GOTO LABEL_BV1_6_END
LABEL_BV1_6
	BCF PORTB,6
LABEL_BV1_6_END

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


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

	BTFSS S5,0	; Reset ?
	GOTO LABEL_ZV1_COUNT
	CLRF ZV1
	GOTO LABEL_ZV1_SETOUT

LABEL_ZV1_COUNT

; Test auf positive Flanke

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSS S3,3
	GOTO LABEL_ZV1_SETFD
	BTFSC ZV1_FD,0
	GOTO LABEL_ZV1_SETFD

	BSF ZV1_FD,0


	BTFSC S5,1	; 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

; Output Q0

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSS ZV1,0
	GOTO LABEL_ZV1_SETOUT0
	BSF S4,6
	GOTO LABEL_ZV1_SETOUT0_END
LABEL_ZV1_SETOUT0
	BCF S4,6
LABEL_ZV1_SETOUT0_END

; Output Q1

	BTFSS ZV1,1
	GOTO LABEL_ZV1_SETOUT1
	BSF S4,7
	GOTO LABEL_ZV1_SETOUT1_END
LABEL_ZV1_SETOUT1
	BCF S4,7
LABEL_ZV1_SETOUT1_END

; Output Q2

	BTFSS ZV1,2
	GOTO LABEL_ZV1_SETOUT2
	BSF S5,0
	GOTO LABEL_ZV1_SETOUT2_END
LABEL_ZV1_SETOUT2
	BCF S5,0
LABEL_ZV1_SETOUT2_END


LABEL_ZV1_SETFD

; Test auf negative Flanke

	BCF STATUS,RP0	; Bank 0
	BCF STATUS,RP1	; Bank 0
	BTFSC S3,3
	GOTO LABEL_ZV1_EXIT
	BCF ZV1_FD,0

LABEL_ZV1_EXIT

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

	BCF S5,1	; immer Low

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

	MOVLW HIGH MAIN
	MOVWF PCLATH

	GOTO MAIN

	ORG 8176
;***************************************************
;Table -> BIN_TO_7SEG
;***************************************************

BIN_TO_7SEG

	MOVWF SYS_TMP1
	MOVLW HIGH BIN_TO_7SEG_WERTE
	MOVWF PCLATH
	MOVFW SYS_TMP1
	ADDWF PCL,F

BIN_TO_7SEG_WERTE

	RETLW 63
	RETLW 6
	RETLW 91
	RETLW 79
	RETLW 102
	RETLW 109
	RETLW 125
	RETLW 7
	RETLW 127
	RETLW 111
	RETLW 63


	END

