



.include "1200def.inc"

.def temp 		= r20
.def register_status 	= r21

.def i			= r17
.def j			= r18
.def k			= r19

.cseg

.org 0

	rjmp reset			; Powerup und reset
	rjmp lampean			; Interrupt 0
	reti 				; Interrupt 1, unused
	reti				; Interrupt 2, unused
	
	
reset:
	ldi temp, 0x00
	out DDRD, temp			; Port D Input
	
	ldi temp, 0xff
	out DDRB, temp			; Port B Output
	
	rcall reaktion			; Blinken zur Initialisierung
	rcall reaktion	

	ldi temp, 0b00110011		; Power down mode, Interrupt bei steigender Flanke
	out MCUCR, temp			; 
	
	sbi ACSR, ACD			; Analog Comparator out
	
	ldi temp, 0b01000000		; Int 0 enable
	out GIMSK, temp
	
	sei				; Interrupt enable
main:	

	
;	sleep				; Rücksprungadresse nach Int0 Routine lampean
	ldi temp, 0b01000000		; Int 0 enable
	out GIMSK, temp

	; Nachbereitung Interrupt
	
;	rcall reaktion			; Blinken, wenn ATmel wieder wach
	rjmp main
	




	
lampean:
	in  register_status, SREG
	
	ldi temp, 0b00000000		; lange Blinken bei Interrupt
	out PORTB, temp
	rcall warte300ms	
	rcall warte300ms	
	
	ldi temp, 0b11111111
	out PORTB, temp
	rcall warte300ms	
	rcall warte300ms	
	
	ldi temp, 0b00000000		
	out PORTB, temp
	rcall warte300ms	
	rcall warte300ms	
	
	ldi temp, 0b11111111
	out PORTB, temp
	rcall warte300ms	
	rcall warte300ms	
	

	

	ldi temp, 0
	out GIMSK, temp			; Disable external Interrupt
		
	out SREG, register_status
reti	





reaktion:
	ldi temp, 0b00000000		; Blinken, wenn ATmel wieder wach
	out PORTB, temp
	rcall warte300ms	
	
	ldi temp, 0b11111111
	out PORTB, temp
	rcall warte300ms	
	
	ldi temp, 0b00000000
	out PORTB, temp
	rcall warte300ms	
	
	ldi temp, 0b11111111
	out PORTB, temp
	rcall warte300ms	
ret	






warte300ms:
          ldi  i, $09
WGLOOP0:  ldi  j, $37
WGLOOP1:  ldi  k, $C9
WGLOOP2:  dec  k
          brne WGLOOP2
          dec  j
          brne WGLOOP1
          dec  i
          brne WGLOOP0
ret





