; ATmega8, 1MHz interny RC
; prerusenie

.nolist
.include "m8def.inc"
.list


.cseg
.org 0x0000
		rjmp RESET
.org INT0addr
		rjmp INT0_vect


RESET: 
		.def TEMP=R16
		.equ F_CPU=1000000

		ldi TEMP, low (ramend)
		out SPL, TEMP
		ldi TEMP, high (ramend)
		out SPH, TEMP

		; nastav PB1 vystupny
		ldi TEMP, 1<<DDB1
		out DDRB, TEMP
		
		; nastav PD2 vstupny, pull-up rezistor
		ldi TEMP, 1<<PD2
		out PORTD, TEMP

		; external interrupt INT0
		ldi TEMP, 1<<ISC01
		out MCUCR, TEMP

		; povolenie prerusenia INT0
		ldi TEMP, 1<<INT0
		out GICR, TEMP

		sei
FURT:
		nop
		rjmp FURT


INT0_vect:
		push TEMP
		in TEMP, SREG
		push TEMP

		in TEMP, PINB
		com TEMP
		out PORTB, TEMP

		pop TEMP
		out SREG, TEMP
		pop TEMP

		
