; Source created with Parsic Version 3.x

; at              : 17.01.2000 01:01:14


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

; Project Version : 0.0.23

; Created         : 03.06.1999 20:39:00

; Last change     : 13.01.2000 03:47:00

	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

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
S1	= 16	; located in Bank 0, 1
MF2	= 17	; located in Bank 0, 1
MF2_HI	= 18	; located in Bank 0, 1
S2	= 19	; located in Bank 0, 1
ZV1	= 20	; located in Bank 0, 1
ZV1_FD	= 21	; located in Bank 0, 1
SYS_TMP1	= 22	; located in Bank 0, 1
S0	= 23	; located in Bank 0, 1
MF3	= 24	; located in Bank 0, 1
MF3_HI	= 25	; located in Bank 0, 1
MF3_FD	= 26	; located in Bank 0, 1
ZR1	= 27	; located in Bank 0, 1
ZR1_FD	= 28	; located in Bank 0, 1
MF4	= 29	; located in Bank 0, 1
MF4_HI	= 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
	INCFSZ MF4,F
	GOTO SYS_INT_LABEL_3
	INCF MF4_HI,F

SYS_INT_LABEL_3
	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'00001000'
	MOVWF PORTA

	MOVLW B'11111111'
	MOVWF PORTB

	MOVLW 143
	BSF STATUS,RP0	; Bank 1
	MOVWF OPTION_REG


; Richtung setzen

	MOVLW B'11110111'
	MOVWF TRISA

	MOVLW B'00000000'
	MOVWF TRISB

; init var

	CLRF MF1
	CLRF MF1_HI
	CLRF SYS_WSAV
	CLRF SYS_SSAV
	CLRF S1
	CLRF MF2
	CLRF MF2_HI
	CLRF S2
	CLRF ZV1
	CLRF ZV1_FD
	CLRF SYS_TMP1
	CLRF S0
	CLRF MF3
	CLRF MF3_HI
	CLRF MF3_FD
	CLRF ZR1
	CLRF ZR1_FD
	CLRF MF4
	CLRF MF4_HI

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

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

MAIN

	CLRWDT

;***************************************************
; Anzug-Verzögerung -> MF1
;***************************************************

	BTFSC S1,6	; Eingang auf High ?
	GOTO LABEL_MF1_CHKTIME	; Ja

; RESET

	CLRF MF1
	CLRF MF1_HI
	BCF S1,0
	GOTO LABEL_MF1_EXIT	; raus

LABEL_MF1_CHKTIME

	BTFSC S1,0	; Ausgang schon auf High ?
	GOTO LABEL_MF1_EXIT	; Ja

	MOVLW 3
	SUBWF MF1_HI,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF1_EXIT

	MOVLW 13
	SUBWF MF1,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF1_EXIT

	BSF S1,0
LABEL_MF1_EXIT

;***************************************************
; Anzug-Verzögerung -> MF2
;***************************************************

	BTFSC S1,7	; Eingang auf High ?
	GOTO LABEL_MF2_CHKTIME	; Ja

; RESET

	CLRF MF2
	CLRF MF2_HI
	BCF S1,1
	GOTO LABEL_MF2_EXIT	; raus

LABEL_MF2_CHKTIME

	BTFSC S1,1	; Ausgang schon auf High ?
	GOTO LABEL_MF2_EXIT	; Ja

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

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

	BSF S1,1
LABEL_MF2_EXIT

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

LABEL_UG1_1
	BTFSC S1,0
	GOTO LABEL_UG1_TRUE
LABEL_UG1_2
	BTFSC S1,1
	GOTO LABEL_UG1_TRUE

LABEL_UG1_FALSE
	BCF S2,0
	GOTO LABEL_UG1_ENDE
LABEL_UG1_TRUE
	BSF S2,0
LABEL_UG1_ENDE
;***************************************************
; Zähler -> ZV1
;***************************************************

	BTFSS S1,3	; Reset ?
	GOTO LABEL_ZV1_COUNT
	CLRF ZV1
	GOTO LABEL_ZV1_SETOUT

LABEL_ZV1_COUNT

; Test auf positive Flanke

	BTFSS S2,1
	GOTO LABEL_ZV1_SETFD
	BTFSC ZV1_FD,0
	GOTO LABEL_ZV1_SETFD

	BSF ZV1_FD,0


	BTFSS S1,2	; 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 S2,1
	GOTO LABEL_ZV1_EXIT
	BCF ZV1_FD,0

LABEL_ZV1_EXIT

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

	BCF S1,3	; immer Low

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

	MOVFW ZV1

	CALL BIN_TO_7SEG

	MOVWF S0

;***************************************************
; 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 S1,4

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 S1,4

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

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

	BTFSS S1,5	; 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,4
	GOTO LABEL_ZR1_SETFD

	INCF ZR1,F

LABEL_ZR1_SETOUT

; Output Q0

	BTFSS ZR1,0
	GOTO LABEL_ZR1_SETOUT0
	BCF STATUS,RP0	; Bank 0
	BCF PORTA,3
	GOTO LABEL_ZR1_SETOUT0_END
LABEL_ZR1_SETOUT0
	BCF STATUS,RP0	; Bank 0
	BSF PORTA,3
LABEL_ZR1_SETOUT0_END

LABEL_ZR1_SETFD

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

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

	BCF S1,5	; immer Low

;***************************************************
; UND - Gatter -> UG2
;***************************************************

LABEL_UG2_1
	BTFSS S2,3
	GOTO LABEL_UG2_FALSE
LABEL_UG2_2
	BCF STATUS,RP0	; Bank 0
	BTFSS PORTA,0
	GOTO LABEL_UG2_FALSE

LABEL_UG2_TRUE
	BSF S1,6
	GOTO LABEL_UG2_ENDE
LABEL_UG2_FALSE
	BCF S1,6
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 S2,2
	GOTO LABEL_UG3_FALSE

LABEL_UG3_TRUE
	BSF S1,7
	GOTO LABEL_UG3_ENDE
LABEL_UG3_FALSE
	BCF S1,7
LABEL_UG3_ENDE
;***************************************************
; Vergleich -> IF1
;***************************************************

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

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

LABEL_IF1_TRUE
	BSF S2,3
	GOTO LABEL_IF1_EXIT

LABEL_IF1_FALSE
	BCF S2,3

LABEL_IF1_EXIT
;***************************************************
; Anzug-Verzögerung -> MF4
;***************************************************

	BTFSC S2,0	; Eingang auf High ?
	GOTO LABEL_MF4_CHKTIME	; Ja

; RESET

	CLRF MF4
	CLRF MF4_HI
	BCF S2,1
	GOTO LABEL_MF4_EXIT	; raus

LABEL_MF4_CHKTIME

	BTFSC S2,1	; Ausgang schon auf High ?
	GOTO LABEL_MF4_EXIT	; Ja

	MOVLW 1
	SUBWF MF4_HI,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF4_EXIT

	MOVLW 135
	SUBWF MF4,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF4_EXIT

	BSF S2,1
LABEL_MF4_EXIT

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

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

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

LABEL_IF2_TRUE
	BSF S2,2
	GOTO LABEL_IF2_EXIT

LABEL_IF2_FALSE
	BCF S2,2

LABEL_IF2_EXIT
;***************************************************
; UND - Gatter -> UG12
;***************************************************

LABEL_UG12_1
	BTFSS S1,0
	GOTO LABEL_UG12_FALSE
LABEL_UG12_2
	BTFSC S1,1
	GOTO LABEL_UG12_FALSE

LABEL_UG12_TRUE
	BSF S1,2
	GOTO LABEL_UG12_ENDE
LABEL_UG12_FALSE
	BCF S1,2
LABEL_UG12_ENDE
;***************************************************
; Verteiler -> BV1
;***************************************************

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	BTFSC S0,7
	GOTO LABEL_BV1_7
	BSF PORTB,7
	GOTO LABEL_BV1_7_END
LABEL_BV1_7
	BCF PORTB,7
LABEL_BV1_7_END

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


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


	GOTO MAIN

	ORG 1002
;***************************************************
;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 119
	RETLW 124
	RETLW 57
	RETLW 94
	RETLW 121
	RETLW 113
	RETLW 128


	END

