
; Ausgabe eines Textes über die serielle Schnittstelle
; Programm beinhaltet Taster-LED-Kopplung als Lebenzeichen
;
; Achim Walther, www.voidpointer.de, 20.11.2004

.include "m8def.inc"

.def temp = r16
.equ CLOCK = 8000000
.equ BAUD = 9600
.equ UBRRVAL = CLOCK/(BAUD*16)-1

	; Taster und LED init

	ldi temp, 0xFF
	out DDRC, temp		;Port C durch Ausgabe von 0xFF ins
				;Richtungsregister DDRC als Ausgang konfigurieren
	ldi temp, 0x00
	out DDRD, temp		;Port D durch Ausgabe von 0x00 ins
				;Richtungsregister DDRD als Eingang konfigurieren
	ldi temp, 0xFF
	out PORTC, temp	;PORTC auf 0xFF setzen -> alle LEDs aus

	; Stackpointer initialisieren
	ldi temp, LOW(RAMEND)
	out SPL, temp
	ldi temp, HIGH(RAMEND)
	out SPH, temp

	; Baudrate einstellen
	ldi temp, LOW(UBRRVAL)
	out UBRRL, temp
	ldi temp, HIGH(UBRRVAL)
	out UBRRH, temp

	; Frame-Format: 8 Bit
	ldi temp, (1<<URSEL)|(3<<UCSZ0)
	out UCSRC, temp

	sbi UCSRB,TXEN		; TX aktivieren

loop:   ldi temp, 'T'
	rcall serout		; Unterprogramm aufrufen
	ldi temp, 'e'
	rcall serout		; Unterprogramm aufrufen
	ldi temp, 's'
	rcall serout
	ldi temp, 't'
	rcall serout
	ldi temp, '!'
	rcall serout
	ldi temp, 10
	rcall serout
	ldi temp, 13
	rcall serout
	sbis PIND, 7		;"skip if bit set", nächsten Befehl überspringen,
				; wenn Taste nicht gedrückt, keine LED an

	cbi PORTC, 0		;Bit 0 im IO-Register PORTB auf 0 setzen -> 1. LED an

	sbic PIND, 7		; wenn Taste gedrückt nichts tun
	sbi PORTC, 0		; LED aus

	rjmp loop

serout:
	sbis UCSRA,UDRE		; Warten bis UDR für das nächste
				; Byte bereit ist
	rjmp serout
	out UDR, temp
	ret			; zurück zum Hauptprogramm