////simulace impulsu DO Atmegy5 z Atmeg1-4

.include "m8def.inc"

////////////////////////////////////////////////////////////
//hlavni program
//////////////////////////////////////

zac:  	ldi R16, HIGH(RAMEND) // inicializace STACK POINTERu
		out SPH, R16
		ldi R16, LOW(RAMEND)
		out SPL, R16

		ldi R16, 0xFF	//B vystupni - impulsy strel z terce
		out DDRB, R16
		ldi R16, 0xFF	//vystupni  - TSOP    
		out DDRC, R16		// C5 vstupni komunikace s atmegou5
		ldi R16, 0x00	//D0-D7 vstupni
		out DDRD, R16
		ldi R16, 0xFF
		out PORTD,R16
		ldi R17, 0 

	
	
tlacitka:		in R16, PIND				//podle stisknutého tlačítka 
				cpi R16, 0b11111110
				breq start
				cpi R16, 0b11111101
				breq start
				cpi R16, 0b11111011
				breq start
				cpi R16, 0b11110111
				breq start
				cpi R16, 0b11101111
				breq start
				cpi R16, 0b11011111
				breq start
				cpi R16, 0b10111111
				breq start
				cpi R16, 0b01111111
				breq start
				rjmp tlacitka

start:	rcall cekej1
	
		//rcall cekej1		//počká 3 sekundy
		ldi R16, 0xFF
		
		out PORTC, R16


		out PORTB, R16		//střela(0)
		rcall cekej400
		out PORTB, R17
		rcall cekej400

		out PORTB, R16		//střela(1)
		rcall cekej400
		out PORTB, R17
		rcall cekej400

		out PORTC, R17

		out PORTB, R16		//střela(2)
		rcall cekej400
		out PORTB, R17
		rcall cekej400
		
		out PORTB, R16		//střela(3)
		rcall cekej400
		out PORTB, R17
		rcall cekej400
		
		out PORTB, R16		//střela(4)
		rcall cekej400
		out PORTB, R17
		rcall cekej400

		
		rcall cekej1
		rcall cekej1
		rcall cekej1		//2 sekundy do dalsi střely		




////////////////////////////2 vystrel/////////////////

		out PORTC, R16

		out PORTB, R16		//střela(0)
		rcall cekej400
		out PORTB, R17
		rcall cekej400	

		out PORTB, R16		//střela(1)
		rcall cekej400
		out PORTB, R17
		rcall cekej400

		out PORTC, R17

		out PORTB, R16		//střela(2)
		rcall cekej400
		out PORTB, R17
		rcall cekej400
		
		out PORTB, R16		//střela(3)
		rcall cekej400
		out PORTB, R17
		rcall cekej400

	

///////////3 vystřel
		
		rcall cekej1
		rcall cekej1
		rcall cekej1		//2 sekundy do dalsi střely		

		out PORTC, R16
		
		out PORTB, R16		//střela(0)
		rcall cekej400
		out PORTB, R17
		rcall cekej400	

		out PORTB, R16		//střela(1)
		rcall cekej400
		out PORTB, R17
		rcall cekej400

			out PORTC, R17		

		out PORTB, R16		//střela(2)
		rcall cekej400
		out PORTB, R17
		rcall cekej400
		
		out PORTB, R16		//střela(3)
		rcall cekej400
		out PORTB, R17
		rcall cekej400

	

		out PORTB, R16		//střela(4)
		rcall cekej400
		out PORTB, R17
		rcall cekej400

		out PORTB, R16		//střela(5)
		rcall cekej400
		out PORTB, R17
		rcall cekej400
		
		out PORTB, R16		//střela(6)
		rcall cekej400
		out PORTB, R17
		rcall cekej400

		out PORTB, R16		//střela(7)
		rcall cekej400
		out PORTB, R17
		rcall cekej400

		out PORTB, R16		//střela(8)
		rcall cekej400
		out PORTB, R17
		rcall cekej400
		
	

			rcall cekej1
			rcall cekej1

			rjmp tlacitka		//počká a skočí na start



/////////////delay////

cekej1:
			ldi R20, 5			//cca 1s (R17 5)
	d1:		ldi R18, 0
	d2:		ldi R19, 0
	d3:		dec R19
		
			brne d3
			dec R18
			brne d2
			dec R20
			brne d1
	
				ret

cekej200:	
			
			ldi R18, 0
	b1:		ldi R19, 0
	b2:		dec R19
		
			brne b2
			dec R18
			brne b1
			cli
				ret

cekej2ms:
			 						//cca 24mss (R17 neni)
			ldi R18, 3
	c1:		ldi R19, 220
	c2:		dec R19
		
			brne c2
			dec R18
			brne c1
			ret

cekej400:
			 						//cca 216us (R19 = 72)
			ldi R19, 130
	w1:		dec R19
			brne w1
			ret


