; Quelltext erstellt mit Easy-PIC Version 2.16

; am : 10.06.1999 22:31:41


; Projekt Datei   : E:\DATEN\DELPHI\EPICWIN\INTERNET\BSP\EXAMP2.PIC

; Projekt Version : 1.0.4

; angelegt        : 14.03.1999 21:13:00

; letzte Änderung : 24.05.1999 16:03:00

	PROCESSOR 16C84

	RADIX DEC


	__IDLOCS H'0100'

	__CONFIG B'11101'

W EQU 0
F EQU 1

; Bit Belegung STATUS-Register

RP0   EQU 5 ; Register-Page 0
ZERO  EQU 2 ; ZERO-Flag
DC    EQU 1 ; HALF-CARRY-Flag
CARRY EQU 0 ; CARRY-Flag

; Bit Belegung INTCON-Register

GIE  EQU 7 ; Global  -Interrupt-Enable
EEIE EQU 6 ; EE-Write-Interrupt-Enable
TOIE EQU 5 ; Timer0  -Interrupt-Enable
INTE EQU 4 ; Extern  -Interrupt-Enable
RBIE EQU 3 ; Port B Changed-Interrupt-Enable
T0IF EQU 2 ; Timer0 Interrupt-Flag
INTF EQU 1 ; Extern-Interrupt-Flag
RBIF EQU 0 ; Port B-Interrupt-Flag

; RAM Bank 0

INDF   EQU 0
TMR0   EQU 1
PCL    EQU 2
STATUS EQU 3
FSR    EQU 4
RA     EQU 5
RB     EQU 6
EEDATA EQU 8
EEADR  EQU 9
PCLATH EQU 10
INTCON EQU 11

; RAM Bank 1

OPTIONR EQU 1
TRISA   EQU 5
TRISB   EQU 6
EECON1  EQU 8
EECON2  EQU 9

; Variable

	VARIABLE RAM = 12

SYS_WSAV	EQU RAM
RAM += 1

SYS_SSAV	EQU RAM
RAM += 1

TR1_LO	EQU RAM
RAM += 1

TR1_HI	EQU RAM
RAM += 1

S0	EQU RAM
RAM += 1

ZR1	EQU RAM
RAM += 1

ZR1_FD	EQU RAM
RAM += 1

MF1_LO	EQU RAM
RAM += 1

MF1_HI	EQU RAM
RAM += 1

MF1_FD	EQU RAM
RAM += 1

S1	EQU RAM
RAM += 1

MF2_LO	EQU RAM
RAM += 1

MF2_HI	EQU RAM
RAM += 1

MF2_FD	EQU RAM
RAM += 1



;****************************************
;Programmanfang
;****************************************

	ORG 0

	CLRF STATUS	; RAM-Bank 0
	BCF INTCON,GIE	; Interrupt sperren
	CLRWDT
	GOTO SYS_INIT

;****************************************
;Interrupt-Adresse (fest vorgegeben)
;****************************************

	ORG 4

	MOVWF SYS_WSAV	; Register sichern
	SWAPF STATUS,W
	BCF STATUS,RP0	; BANK0
	MOVWF SYS_SSAV

	INCFSZ TR1_LO,F
	GOTO SYS_INT_LABEL_0
	INCF TR1_HI,F

SYS_INT_LABEL_0
	INCFSZ MF1_LO,F
	GOTO SYS_INT_LABEL_1
	INCF MF1_HI,F

SYS_INT_LABEL_1
	INCFSZ MF2_LO,F
	GOTO SYS_INT_LABEL_2
	INCF MF2_HI,F

SYS_INT_LABEL_2
	BCF INTCON,T0IF	; Interrupt quitieren

	SWAPF SYS_SSAV,W	; Register zurück
	MOVWF STATUS
	SWAPF SYS_WSAV,F
	SWAPF SYS_WSAV,W

	RETFIE	; RETurn From Interrupt and Enable GIE


;****************************************
;Initialisierung
;****************************************


SYS_INIT

	MOVLW B'00100000'
	MOVWF INTCON

; Ausgangs-Pegel setzen, bevor die Richtung gesetzt wird

	MOVLW B'00010000'
	MOVWF RA

	MOVLW B'00000000'
	MOVWF RB

	BSF STATUS,RP0	; RAM-BANK 1

	MOVLW 8
	MOVWF OPTIONR


; Richtung setzen

	MOVLW B'11100111'
	MOVWF TRISA

	MOVLW B'11111110'
	MOVWF TRISB

	BCF STATUS,RP0	; RAM-BANK 0

; Variable initialisieren

	CLRF SYS_WSAV
	CLRF SYS_SSAV
	CLRF TR1_LO
	CLRF TR1_HI
	CLRF S0
	CLRF ZR1
	CLRF ZR1_FD
	CLRF MF1_LO
	CLRF MF1_HI
	CLRF MF1_FD
	CLRF S1
	CLRF MF2_LO
	CLRF MF2_HI
	CLRF MF2_FD

	CLRF TMR0
	BSF INTCON,GIE	; Interrupt freigeben

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

MAIN

	CLRWDT

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

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

LABEL_TR1_RESET
	CLRF TR1_LO	; Timer zurücksetzen
	CLRF TR1_HI	; Timer zurücksetzen

LABEL_TR1_SET	; Ausgang Toggeln
	BTFSC S0,7
	GOTO LABEL_TR1_CLR
	BSF S0,7
	GOTO LABEL_TR1_ENDE
LABEL_TR1_CLR
	BCF S0,7
LABEL_TR1_ENDE

	CLRWDT

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

	BTFSS S0,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 S0,6
	GOTO LABEL_ZR1_SETFD

	INCF ZR1,F

LABEL_ZR1_SETOUT

; Ausgang Q0

	BTFSS ZR1,0
	BCF S0,0
	BTFSC ZR1,0
	BSF S0,0

; Ausgang Q1

	BTFSS ZR1,1
	BCF S0,1
	BTFSC ZR1,1
	BSF S0,1

; Ausgang Q2

	BTFSS ZR1,2
	BCF S0,5
	BTFSC ZR1,2
	BSF S0,5

LABEL_ZR1_SETFD

	BTFSS S0,6
	BCF ZR1_FD,0
	BTFSC S0,6
	BSF ZR1_FD,0

	CLRWDT

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

LABEL_UG1_1
	BTFSC S0,0
	GOTO LABEL_UG1_FALSE
LABEL_UG1_2
	BTFSC S0,1
	GOTO LABEL_UG1_FALSE

LABEL_UG1_TRUE
	BSF S0,2
	GOTO LABEL_UG1_ENDE
LABEL_UG1_FALSE
	BCF S0,2
LABEL_UG1_ENDE

	CLRWDT

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

LABEL_UG2_1
	BTFSS S0,0
	GOTO LABEL_UG2_FALSE
LABEL_UG2_2
	BTFSC S0,1
	GOTO LABEL_UG2_FALSE

LABEL_UG2_TRUE
	BSF S0,3
	GOTO LABEL_UG2_ENDE
LABEL_UG2_FALSE
	BCF S0,3
LABEL_UG2_ENDE

	CLRWDT

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

LABEL_UG3_1
	BTFSC S0,0
	GOTO LABEL_UG3_FALSE
LABEL_UG3_2
	BTFSS S0,1
	GOTO LABEL_UG3_FALSE

LABEL_UG3_TRUE
	BSF RA,3
	GOTO LABEL_UG3_ENDE
LABEL_UG3_FALSE
	BCF RA,3
LABEL_UG3_ENDE

	CLRWDT

;***************************************************
; UND - Gatter -> UG4
;***************************************************

LABEL_UG4_1
	BTFSS S0,0
	GOTO LABEL_UG4_FALSE
LABEL_UG4_2
	BTFSS S0,1
	GOTO LABEL_UG4_FALSE

LABEL_UG4_TRUE
	BSF S0,4
	GOTO LABEL_UG4_ENDE
LABEL_UG4_FALSE
	BCF S0,4
LABEL_UG4_ENDE

	CLRWDT

;***************************************************
; ODER - Gatter -> UG5
;***************************************************

LABEL_UG5_1
	BTFSC S0,2
	GOTO LABEL_UG5_TRUE
LABEL_UG5_2
	BTFSC S0,3
	GOTO LABEL_UG5_TRUE

LABEL_UG5_FALSE
	BCF RB,0
	GOTO LABEL_UG5_ENDE
LABEL_UG5_TRUE
	BSF RB,0
LABEL_UG5_ENDE

	CLRWDT

;***************************************************
; ODER - Gatter -> UG6
;***************************************************

LABEL_UG6_1
	BTFSC S0,3
	GOTO LABEL_UG6_TRUE
LABEL_UG6_2
	BTFSC S0,4
	GOTO LABEL_UG6_TRUE

LABEL_UG6_FALSE
	BSF RA,4
	GOTO LABEL_UG6_ENDE
LABEL_UG6_TRUE
	BCF RA,4
LABEL_UG6_ENDE

	CLRWDT

;***************************************************
; ODER - Gatter -> UG7
;***************************************************

LABEL_UG7_1
	BTFSC S0,7
	GOTO LABEL_UG7_TRUE
LABEL_UG7_2
	BTFSC S1,0
	GOTO LABEL_UG7_TRUE
LABEL_UG7_3
	BTFSC S1,1
	GOTO LABEL_UG7_TRUE

LABEL_UG7_FALSE
	BCF S0,6
	GOTO LABEL_UG7_ENDE
LABEL_UG7_TRUE
	BSF S0,6
LABEL_UG7_ENDE

	CLRWDT

;***************************************************
; Puls-Geber -> 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 RB,0
	GOTO LABEL_MF1_SETFD


LABEL_MF1_RESET

	CLRF MF1_LO
	CLRF MF1_HI
	BSF MF1_FD,1
	BSF S1,0

LABEL_MF1_CHKTIME

	MOVLW 76
	SUBWF MF1_HI,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF1_SETFD
	MOVLW 75
	SUBWF MF1_LO,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF1_SETFD
LABEL_MF1_TO

	BCF MF1_FD,1
	BCF S1,0

LABEL_MF1_SETFD

	BTFSS RB,0
	BCF MF1_FD,0
	BTFSC RB,0
	BSF MF1_FD,0

	CLRWDT

;***************************************************
; Puls-Geber -> 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 RA,3
	GOTO LABEL_MF2_SETFD


LABEL_MF2_RESET

	CLRF MF2_LO
	CLRF MF2_HI
	BSF MF2_FD,1
	BSF S1,1

LABEL_MF2_CHKTIME

	MOVLW 45
	SUBWF MF2_HI,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF2_SETFD
	MOVLW 199
	SUBWF MF2_LO,W
	BTFSS STATUS,CARRY
	GOTO LABEL_MF2_SETFD
LABEL_MF2_TO

	BCF MF2_FD,1
	BCF S1,1

LABEL_MF2_SETFD

	BTFSS RA,3
	BCF MF2_FD,0
	BTFSC RA,3
	BSF MF2_FD,0

	CLRWDT

	GOTO MAIN


	END

