.include "tn2313def.inc"

.org 0x0000
rjmp START

//EXT_INT1
.org 0x0002
;rjmp ADATCSERE

.def temp				=R16
.def temp2				=R17

#define SCK			DDRB,7
#define MISO		DDRB,6
#define MOSI		DDRB,5

#define	RTC			PIND,3

START:
	ldi temp,low(ramend)
	out SPL,temp

	clr temp
	out DDRD,temp
	out DDRB,temp
	
INT_INIT:
	ldi temp,0b00001100;rising edge
	out MCUCR,temp
	ldi temp,0b10000000;INT1_enabled
	out GIMSK,temp

	;sei
	
LOOP:
	sbis RTC	
	rjmp LOOP
	
	ldi temp,'c'
	out USIDR,temp
	rcall FOGADKULD
	
	rjmp LOOP
	
;------------------------------------------------------------------------------------------------------------------------
FOGADKULD:
	sbi USISR,USIOIF
	ldi temp,0b00011011;USIWM0,USICS1,USICLK,USITC
FOGADKULD1:
	out USICR,temp
	sbis USISR,USIOIF
	rjmp FOGADKULD1
	in temp,USIDR
	ld temp,z+
	ret


