;+----------------------------------------------------------------------
;| Titel		: myAVR Beispiel "Lauflicht" für den ATmega168
;+----------------------------------------------------------------------
;| Funktion		: Ein Register wird inkrementiert und verzögert an
;|		: PORTD ausgegeben.
;| Schaltung	: PORTD2=Summer, PORTD3=LED1, PORTD4=LED2, PORTD5=LED3
;+----------------------------------------------------------------------
;| Prozessor	: ATmega168
;| Takt		: 3,6864 MHz
;| Sprache		: Assembler
;| Datum		: 09.10.2005
;| Version		: 0.9
;| Autor		: Dipl. Ing. Päd. Alexander Huwaldt
;+----------------------------------------------------------------------
.include	"AVR.H"
;------------------------------------------------------------------------
;Reset and Interrupt vector             ;VNr.  Beschreibung
begin:	nop
	rjmp	main	; Reset Handler
	nop
	reti		; EXT_INT0 IRQ0 Handler
	nop
	reti		; EXT_INT1 IRQ1 Handler
	nop
	reti		; PCINT0 PCINT0 Handler
	nop
	reti		; PCINT1 PCINT1 Handler
	nop
	reti		; PCINT2 PCINT2 Handler
	nop
	reti		; WDT Watchdog Timer Handler
	nop
	reti		; TIM2_COMPA Timer2 Compare A Handler
	nop
	reti		; TIM2_COMPB Timer2 Compare B Handler
	nop
	reti		; TIM2_OVF Timer2 Overflow Handler
	nop
	reti		; TIM1_CAPT Timer1 Capture Handler
	nop
	reti		; TIM1_COMPA Timer1 Compare A Handler
	nop
	reti		; TIM1_COMPB Timer1 Compare B Handler
	nop
	reti		; TIM1_OVF Timer1 Overflow Handler
	nop
	reti		; TIM0_COMPA Timer0 Compare A Handler
	nop
	reti		; TIM0_COMPB Timer0 Compare B Handler
	nop
	reti		; TIM0_OVF Timer0 Overflow Handler
	nop
	reti		; SPI_STC SPI Transfer Complete Handler
	nop
	reti		; USART_RXC USART, RX Complete Handler
	nop
	reti		; USART_UDRE USART, UDR Empty Handler
	nop
	reti		; USART_TXC USART, TX Complete Handler
	nop
	reti		; ADC ADC Conversion Complete Handler
	nop
	reti		; EE_RDY EEPROM Ready Handler
	nop
	reti		; ANA_COMP Analog Comparator Handler
	nop
	reti		; TWI 2-wire Serial Interface Handler
	nop
	reti		; SPM_RDY Store Program Memory Ready Handler
;------------------------------------------------------------------------
;Start, Power ON, Reset
main:	ldi	r16,lo8(RAMEND)
	out	SPL,r16
	ldi	r16,hi8(RAMEND)
	out	SPH,r16	;Init Stackpointer
	ldi	r16,0b11111111	;PORTD auf Ausgang
	out	DDRD,r16
	ldi	r16,0b00000000	;alle Bits auf Low
	out	PORTD,r16
	ldi	r17,0b00000000
	ldi	r18,0b00000001	;1 Lauflicht-Bit
;------------------------------------------------------------------------
mainloop:	wdr
	inc	r16	;wait
	brne	skip
	inc	r17	;wait
	brne	skip
	rcall	run	;Lauflicht
skip:	rjmp	mainloop
;------------------------------------------------------------------------
run:	rol	r18	;Bit-Rotation
	out	PORTD,r18	;Ausgabe
	ret		;Rücksprung
;------------------------------------------------------------------------

