Gast
#277704
Hallo,
ich hab einen ATMega16.
Wollt nun einmal das Tutorial durcharbeiten. Bin beim UART-angelangt.
Im Datenblatt zum AtMega16 steht, dass sich bei UART-Funktionen im
Sinne von der Registerbelegung usw. nichts geändert hat.
Defacto müsste bei folgendem Code ja auch auf einem PC über ein
Terminal-Programm etwas zu lesen sein. Bei mir kommen aber nur
kryptische Zeichen an.
.include "m16def.inc"
.def temp = r16
.equ CLOCK = 1000000
.equ BAUD = 9600
.equ UBRRVAL = CLOCK/(BAUD*16)-1
; 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
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
Für ein paar Tipps wäre ich sehr dankbar!