.include "tn15def.inc"
.cseg
.org	0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_1:	
	rcall	_200ms
	rcall	_200ms
	rcall	_200ms
	rcall	_200ms
	rcall	_200ms
	rcall	_200ms
	rcall	_200ms
;	rcall	_200ms
	ldi	r16,$00
	out	ddrb,r16
	ldi	r16,$3f
	out	portb,r16
	ldi	r27,1
	rcall	_wait
	in	r16,pinb
	andi	r16,$1f
	bst	r16,0
	brts	_2
;	sbrs	r16,0;D-gnd
	rjmp	_dupla
_2:	ldi	r27,2
	rcall	_wait
	in	r16,pinb
	andi	r16,$1f
	bst	r16,3
	brts	_3
;	sbrs	r16,3;C-gnd
	rjmp	_dupla
_3:	ldi	r27,3
	rcall	_wait
	in	r16,pinb
	andi	r16,$1f
	bst	r16,1
	brts	_4
;	sbrs	r16,1;B-gnd
	rjmp	_dupla
_4:	ldi	r27,4
	rcall	_wait
	in	r16,pinb
	andi	r16,$1f
	bst	r16,4
	brts	_5
;	sbrs	r16,4;A-gnd
	rjmp	_dupla
_5:	ldi	r16,$01
	out	ddrb,r16
	ldi	r16,$3e
	out	portb,r16
	ldi	r27,5
	rcall	_wait
	in	r16,pinb
	andi	r16,$1f
	bst	r16,3
	brts	_6
;	sbrs	r16,3;C-D
	rjmp	_dupla
_6:	ldi	r27,6
	rcall	_wait
	in	r16,pinb
	andi	r16,$1f
	bst	r16,1
	brts	_7
;	sbrs	r16,1;B-D
	rjmp	_dupla
_7:	ldi	r27,7
	rcall	_wait
	in	r16,pinb
	andi	r16,$1f
	bst	r16,4
	brts	_8
;	sbrs	r16,4;A-D
	rjmp	_dupla
_8:	ldi	r16,$08
	out	ddrb,r16
	ldi	r16,$37
	out	portb,r16
	ldi	r27,8
	rcall	_wait
	in	r16,pinb
	andi	r16,$1f
	bst	r16,1
	brts	_9
;	sbrs	r16,1;B-C
	rjmp	_dupla
_9:	ldi	r27,9
	rcall	_wait
	in	r16,pinb
	andi	r16,$1f
	bst	r16,4
	brts	_10
;	sbrs	r16,4;A-C
	rjmp	_dupla
_10:	ldi	r16,$02
	out	ddrb,r16
	ldi	r16,$3d
	out	portb,r16
	ldi	r27,10
	rcall	_wait
	in	r16,pinb
	andi	r16,$1f
	bst	r16,4
	brts	_semmi
;	sbrs	r16,4;A-B
	rjmp	_dupla
_semmi:	rjmp	_1
_dupla:	ldi	r16,$00
	out	ddrb,r16
	ldi	r16,$3f
	out	portb,r16
	ldi	r17,10
	rcall	_wait
	in	r16,pinb
	sbic	pinb,2;X
	add	r27,r17
	rcall	_villog
	rjmp	_1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_villog:;r27 alapján darabszám
	rcall	_led
	dec	r27
	cpi	r27,0
	brne	_villog
;	rcall	_200ms
	ldi	r16,$00
	out	ddrb,r16
	ldi	r16,$1f
	out	portb,r16
	in	r16,pinb
	ret
;.......
_led:	ldi	r16,0x20
	out	ddrb,r16
	clr	r21
_led200:
	clr	r20;3+1
	nop;1
	nop;1
_led1:	inc	r20;1
	nop;1
	cpi	r20,198;1
	brne	_led1;2
	inc	r21
	cpi	r21,200
	brne	_led200
	ldi	r16,0x00
	out	ddrb,r16
	ldi	r16,$1f
	out	portb,r16
	in	r16,pinb
;.......
_200ms:
	clr	r21
_200e:	clr	r20;3+1
	nop;1
	nop;1
_1e:	inc	r20;1
	nop;1
	cpi	r20,198;1
	brne	_1e;2
	inc	r21
	cpi	r21,200
	brne	_200e
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_wait:	
	clr	r20
_wait_:	inc	r20
.dw	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.dw	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	cpi	r20,250
	brne	_wait_
	ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
