;----------------------------------------------------------------------
; Titel		: myAVR Beispiel "Blinklicht" für den ATmega88
;----------------------------------------------------------------------
; Funktion		: Ein Register wird inkrementiert und verzögert an
;		: PORTB ausgegeben.
; Schaltung		: PORTB.0=LED1, PORTB.1=LED2, PORTB.2=LED3
;----------------------------------------------------------------------
; Prozessor		: ATmega88
; Takt		: 3,6864 MHz
; Sprache		: Assembler
; Datum		: 09.11.2007
; Version		: 1.0
; Autor		: Stephan Hänsel
;----------------------------------------------------------------------
.include	"AVR.H"
;------------------------------------------------------------------------
;Reset and Interruptvectoren	;VNr.	Beschreibung
begin:
	rjmp	main	;  1 Reset Handler
	reti		;  2 EXT_INT0 IRQ0 Handler
	reti		;  3 EXT_INT1 IRQ1 Handler
	reti		;  4 PCINT0 PCINT0 Handler
	reti		;  5 PCINT1 PCINT1 Handler
	reti		;  6 PCINT2 PCINT2 Handler
	reti		;  7 WDT Watchdog Timer Handler
	reti		;  8 TIM2_COMPA Timer2 Compare A Handler
	reti		;  9 TIM2_COMPB Timer2 Compare B Handler
	reti		; 10 TIM2_OVF Timer2 Overflow Handler
	reti		; 11 TIM1_CAPT Timer1 Capture Handler
	reti		; 12 TIM1_COMPA Timer1 Compare A Handler
	reti		; 13 TIM1_COMPB Timer1 Compare B Handler
	reti		; 14 TIM1_OVF Timer1 Overflow Handler
	reti		; 15 TIM0_COMPA Timer0 Compare A Handler
	reti		; 16 TIM0_COMPB Timer0 Compare B Handler
	reti		; 17 TIM0_OVF Timer0 Overflow Handler
	reti		; 18 SPI_STC SPI Transfer Complete Handler
	reti		; 19 USART_RXC USART, RX Complete Handler
	reti		; 20 USART_UDRE USART, UDR Empty Handler
	reti		; 21 USART_TXC USART, TX Complete Handler
	reti		; 22 ADC ADC Conversion Complete Handler
	reti		; 23 EE_RDY EEPROM Ready Handler
	reti		; 24 ANA_COMP Analog Comparator Handler
	reti		; 25 TWI 2-wire Serial Interface Handler
	reti		; 26 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	;PORTB auf Ausgang
	out	DDRB,r16
	ldi	r16,0b00000000	;alle Bits auf Low
	out	PORTB,r16
	ldi	r18,0b00000001	;1 Lauflicht-Bit
;------------------------------------------------------------------------
mainloop:
	wdr
	rcall	myWait_20ms
	rcall	myWait_20ms
	rcall	myWait_20ms
	inc	r18	;Bits "blinken" lassen
	out	PORTB,r18	;Ausgabe
	rjmp	mainloop
;--------------------------------------------------------------------
; Warte-Routine für 20 ms
; die Routine wartet inclusive Aufruf 19,9 ms
;--------------------------------------------------------------------
myWait_20ms:
	push	r16
	ldi	r16,1
myWait_20ms_3:
	push	r16
	ldi	r16,95
myWait_20ms_2:
	push	r16
	ldi	r16,255
myWait_20ms_1:
	dec	r16
	brne	myWait_20ms_1
	pop	r16
	dec	r16
	brne	myWait_20ms_2
	pop	r16
	dec	r16
	brne	myWait_20ms_3
	pop	r16
	ret
;----------------------------------------------------------------------

