; Source created with Parsic Version 3.x

; at              : 25.06.2004 17:50:01


; Project File    : c:\BELGEL~1\PARSIC\YÜRÜYE~1\YÜRÜYEN.PIC

; Project Version : 1.0.2

; Created         : 27.05.2004 18:40:00

; Last change     : 25.06.2004 17:49:57

	PROCESSOR 16F84A

	INCLUDE P16F84A.INC

	RADIX DEC


	__IDLOCS H'0100'

	__CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC

; Diverses

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


; Variable

SR1	= 12	; located in Bank 0, 1
SR1_FD	= 13	; located in Bank 0, 1
SYS_WSAV	= 14	; located in Bank 0, 1
SYS_SSAV	= 15	; located in Bank 0, 1
TR1	= 16	; located in Bank 0, 1
TR1_HI	= 17	; located in Bank 0, 1
S0	= 18	; located in Bank 0, 1
RAM	= 19	; 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

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'11111111'
	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

;***************************************************
; Schieberegister -> SR1
;***************************************************

	BTFSS S0,1	; Reset ?
	GOTO LABEL_SR1_SHIFT
	CLRF SR1
	GOTO LABEL_SR1_SETOUT

LABEL_SR1_SHIFT

; Test auf positive Flanke

	BTFSC SR1_FD,0
	GOTO LABEL_SR1_SETFD
	BTFSS S0,0
	GOTO LABEL_SR1_SETFD
	BCF STATUS,CARRY
	BCF STATUS,RP0	; Bank 0
	BTFSS PORTB,0
	BSF STATUS,CARRY

	RLF SR1,F

LABEL_SR1_SETOUT

; Output Q0

	BTFSS SR1,0
	GOTO LABEL_SR1_SETOUT0
	BSF PORTB,7
	GOTO LABEL_SR1_SETOUT0_END
LABEL_SR1_SETOUT0
	BCF PORTB,7
LABEL_SR1_SETOUT0_END

; Output Q1

	BTFSS SR1,1
	GOTO LABEL_SR1_SETOUT1
	BSF PORTB,6
	GOTO LABEL_SR1_SETOUT1_END
LABEL_SR1_SETOUT1
	BCF PORTB,6
LABEL_SR1_SETOUT1_END

; Output Q2

	BTFSS SR1,2
	GOTO LABEL_SR1_SETOUT2
	BSF PORTB,5
	GOTO LABEL_SR1_SETOUT2_END
LABEL_SR1_SETOUT2
	BCF PORTB,5
LABEL_SR1_SETOUT2_END

; Output Q3

	BTFSS SR1,3
	GOTO LABEL_SR1_SETOUT3
	BSF PORTB,4
	GOTO LABEL_SR1_SETOUT3_END
LABEL_SR1_SETOUT3
	BCF PORTB,4
LABEL_SR1_SETOUT3_END

; Output Q4

	BTFSS SR1,4
	GOTO LABEL_SR1_SETOUT4
	BSF PORTB,3
	GOTO LABEL_SR1_SETOUT4_END
LABEL_SR1_SETOUT4
	BCF PORTB,3
LABEL_SR1_SETOUT4_END

; Output Q5

	BTFSS SR1,5
	GOTO LABEL_SR1_SETOUT5
	BSF PORTB,2
	GOTO LABEL_SR1_SETOUT5_END
LABEL_SR1_SETOUT5
	BCF PORTB,2
LABEL_SR1_SETOUT5_END

; Output Q6

	BTFSS SR1,6
	GOTO LABEL_SR1_SETOUT6
	BSF PORTB,1
	GOTO LABEL_SR1_SETOUT6_END
LABEL_SR1_SETOUT6
	BCF PORTB,1
LABEL_SR1_SETOUT6_END

; Output Q7

	BTFSS SR1,7
	GOTO LABEL_SR1_SETOUT7
	BSF PORTB,0
	GOTO LABEL_SR1_SETOUT7_END
LABEL_SR1_SETOUT7
	BCF PORTB,0
LABEL_SR1_SETOUT7_END

LABEL_SR1_SETFD

	BTFSS S0,0
	GOTO LABEL_SR1_SETFD2
	BSF SR1_FD,0
	GOTO LABEL_SR1_END
LABEL_SR1_SETFD2
	BCF SR1_FD,0
LABEL_SR1_END

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

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

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

LABEL_TR1_SET	; toggel output
	BTFSC S0,0
	GOTO LABEL_TR1_CLR
	BSF S0,0
	GOTO LABEL_TR1_ENDE
LABEL_TR1_CLR
	BCF S0,0
LABEL_TR1_ENDE

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

	BCF S0,1	; immer Low

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

	GOTO MAIN


	END

