	INCLUDE		"P16F84.INC"
	LIST 		P=16F84, R=DEC


SWR	EQU		03h		;
PA	EQU		05h		;porty A
PB	EQU		06h		;porty B
PC	EQU		07h		;porty C
c1	EQU		12h		;pomocná proměnná pro čekání
c2	EQU		13h		;pomocná proměnná pro čekání
c3	EQU		14h		;pomocná proměnná pro čekání
cascek	EQU		15h		;
motor	EQU		16h		;směr otáčení motoru (bit 0)
laser	EQU		17h
efekt	EQU		18h		;číslo efektu
efekt_a	EQU		19h
efekt_b	EQU		20h

	ORG		00h
	GOTO		start

start	BSF		SWR,5
	MOVLW		255
	MOVWF		TRISA
	MOVLW		8
	MOVWF		TRISB
	BCF		SWR,5

	CLRF		PB
	CLRF		cascek

	BSF		PB,7		;zablikání a rozsvícení led optozávory
	CALL		cekani2
	BCF		PB,7
	CALL		cekani2
	BSF		PB,7
	CALL		cekani2
	BCF		PB,7
	CALL		cekani2
	BSF		PB,7
	CALL		cekani2
	BCF		PB,7
	CALL		cekani2
	BSF		PB,7

;----------------------------------------------------------------
; HLAVNÍ SMYČKA
;----------------------------------------------------------------

start2	CLRWDT

	INCF		efekt_a

	BTFSC		efekt_a,7
	GOTO		ef_plus
	GOTO		start3

ef_plus	INCF		efekt
	CLRF		efekt_a
	GOTO		start2

start3	BTFSC		efekt,0
	GOTO		efe_1x
	GOTO		efe_0x
;---------

efe_0x	BTFSC		efekt,1
	GOTO		efe_01
	GOTO		efe_00

efe_1x	BTFSC		efekt,1
	GOTO		efe_11
	GOTO		efe_10
;---------

efe_00	BTFSC		efekt,2
	GOTO		ef_0
	GOTO		ef_1

efe_01	BTFSC		efekt,2
	GOTO		ef_2
	GOTO		ef_3

efe_10	BTFSC		efekt,2
	GOTO		ef_4
	GOTO		ef_5

efe_11	BTFSC		efekt,2
	GOTO		ef_6
	GOTO		ef_7

	GOTO		start2

;----------------------------------------------------------------
; JEDNOTLIVÉ EFEKTY
;----------------------------------------------------------------

;---------------------------------- efekt 0

ef_0	BCF		PB,5

	CALL		cekani2

	INCF		motor
	BTFSC		motor,4
	BSF		PB,6		;vlevo
	BTFSS		motor,4
	BCF		PB,6		;vpravo

	BSF		PB,5

	BSF		PB,4
	CALL		cekani2
	CALL		cekani2
	CALL		cekani2

	GOTO		start2

;---------------------------------- efekt 1

ef_1	BTFSS		PB,3
	GOTO		ef_1
	INCF		laser

	BTFSC		laser,0
	BSF		PB,4

	BTFSS		laser,0
	BCF		PB,4

	GOTO		start2

;---------------------------------- efekt 2

ef_2	BSF		PB,5
	CALL		cekani3
	BCF		PB,5
	CALL		cekani3

	BTFSC		PB,3
	BSF		PB,4

	BTFSS		PB,3
	BCF		PB,4

	GOTO		start2

;---------------------------------- efekt 3

ef_3	BSF		PB,4

	BSF		PB,5
	CALL		cekani3
	BCF		PB,5
	CALL		cekani3
	CALL		cekani3

	GOTO		start2

;---------------------------------- efekt 4
ef_4	INCF		motor

	BTFSS		motor,3
	INCF		cascek
	BTFSC		motor,3
	DECF		cascek

	BSF		PB,4
	CALL		cekani1
	BCF		PB,4

	BSF		PB,5
	CALL		cekani2
	BCF		PB,5
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani2

	GOTO		start2

;---------------------------------- efekt 5

ef_5	BSF		PB,4

	MOVLW		5
	MOVWF		cascek
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1

	BCF		PB,4

	BSF		PB,5
	MOVLW		20
	MOVWF		cascek
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	BCF		PB,5
	MOVLW		40
	MOVWF		cascek
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1

	GOTO		start2

;---------------------------------- efekt 6

ef_6	BCF		PB,5

	BSF		PB,4
	BTFSS		PB,3
	GOTO		ef_6

	INCF		motor

	BTFSS		motor,7
	INCF		cascek
	BTFSC		motor,7
	DECF		cascek

	BCF		PB,4
	CALL		cekani1

	DECFSZ		laser
	GOTO		ef_6
	BSF		PB,5
	CALL		cekani2

	GOTO		start2

;---------------------------------- efekt 7

ef_7	BSF		PB,5
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	CALL		cekani1
	BCF		PB,5

	BSF		PB,4
	CALL		cekani2

	GOTO		start2

;---------------------------------- cekani

cekani1	MOVFW		cascek
	MOVWF		c2
cek2	MOVLW		20
	MOVWF		c1
cek1	DECFSZ		c1,1
	GOTO		cek1
	DECFSZ		c2,1
	GOTO		cek2
	CLRWDT				;vynulování Watch Dog
	RETURN

cekani2	MOVLW		160
	MOVWF		c2
cek5	MOVLW		200
	MOVWF		c1
cek4	DECFSZ		c1,1
	GOTO		cek4
	DECFSZ		c2,1
	GOTO		cek5
	CLRWDT				;vynulování Watch Dog
	RETURN

cekani3	MOVLW		20
	MOVWF		c1
cek7	DECFSZ		c1,1
	GOTO		cek7
	CLRWDT				;vynulování Watch Dog
	RETURN


	END






