PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : kommunizieren mit atmega8535



Exodus
14.07.2006, 07:47
Hallo!

Ich will von meinem ATMEGA8535 aus eine Zeichenkette verschicken an den PC! funktioniert aber nicht Warum? Kann mir da wer helfen?

Der code wäre so:

.include "mm8535def.inc"

.def temp = r16
.equ CLOCK = 4000000
.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


MFG
Exodus

PicNick
14.07.2006, 08:26
Rechne mal nach und schau, ob der Wert wirklich stimmt
UBRRVAL = CLOCK/(BAUD*16)-1

Beim C isses besser zu schreiben: 16L , also
UBRRVAL = CLOCK/(BAUD*16L)-1