.INCLUDE "m16def.inc"

.DEF tmp = r16
.DEF tmp1 = r17

.CSEG

; Interrupts jumps
	jmp		reset
.ORG INT0addr
	jmp 	istub
.ORG INT1addr
	jmp 	istub
.ORG OC2addr
	jmp 	istub
.ORG OVF2addr
	jmp 	istub
.ORG ICP1addr
	jmp 	istub
.ORG OC1Aaddr
	jmp 	istub
.ORG OC1Baddr
	jmp 	istub
.ORG OVF1addr
	jmp		iT1OVF
.ORG OVF0addr
	jmp 	istub
.ORG SPIaddr
	jmp 	istub
.ORG URXCaddr
	jmp 	istub
.ORG UDREaddr
	jmp 	istub
.ORG UTXCaddr
	jmp 	istub
.ORG ADCCaddr
	jmp 	istub
.ORG ERDYaddr
	jmp 	istub
.ORG ACIaddr
	jmp 	istub
.ORG TWIaddr
	jmp 	istub
.ORG INT2addr
	jmp 	istub
.ORG OC0addr
	jmp 	istub
.ORG SPMRaddr
	jmp 	istub

.ORG 0x2A
reset:
; Init stack
	ldi		tmp, LOW(RAMEND)
	out		spl, tmp
	ldi		tmp, HIGH(RAMEND)
	out		sph, tmp

; Configure PORTA as output (LEDs)
	ldi		tmp, 0xFF
	out		DDRA, tmp

; Init PORTA with 0xFF (LEDs Off)
	ldi		tmp1, 0xFF
	out		PORTA, tmp1

; Configure T1
	cli
	ldi		tmp, (1<<CS11)|(1<<CS10)
	out		TCCR1B, tmp
	ldi		tmp, 0
	out		TCCR1A, tmp
	ldi		tmp, (1<<TOIE1)
	out		TIMSK, tmp
	sei

loop:
	jmp		loop




istub:
	reti


iT1OVF:
	com		tmp1
	out		PORTA, tmp1
	reti