.NOLIST
.INCLUDE "M16DEF.INC"
.LIST
.DEF JEDEN =R17
.DEF DWA =R18
.DEF SZYBKOSC =R19

LDI SZYBKOSC,40
LDI R26,0XFF
OUT DDRB,R26
LDI R27,0
OUT SPH,R27
OUT SPL,R26

POCZ:
	
	LDI R31,0
	LDI R30,0X60
LOOP:
	LPM R16,Z+
	OUT PORTB,R16
	CALL OPOZNIENIE
	CALL KLAWISZ
	CPI R30,0XC2
	BREQ POCZ
	JMP LOOP

KLAWISZ:
	MOV R28,R29
	IN R29,PIND
	CPSE R28,R29
	CALL E1
	RET
E1:
	CPI R29,0X7F
	BREQ INCR
	CPI R29,0XFE
	BREQ DECR
EXIT:
	RET
INCR:
	CPI SZYBKOSC,255
	BREQ EXIT
	INC SZYBKOSC
	JMP EXIT
DECR:
	CPI SZYBKOSC,1
	BREQ EXIT
	DEC SZYBKOSC
	JMP EXIT


OPOZNIENIE:
	MOV JEDEN,SZYBKOSC
OP2:
	LDI DWA,2
OP:
	DEC DWA
	BRNE OP
	DEC JEDEN
	BRNE OP2
	RET


TABELA:
.ORG 0X30
.DB 0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250
.DB 250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250
.DB 240,230,220,210,200,190,180,170,160,150,140,130,120,110,100,90,80,70,60,50,40,30,20,10,0
.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
