Difference between revisions of "AVR Embedded Tutorial - UART/de"
From Lazarus wiki
Jump to navigationJump to searchLine 3: | Line 3: | ||
===ATmega328p (Arduino uno/nano)=== | ===ATmega328p (Arduino uno/nano)=== | ||
Für die Seriele Ausgabe wird ein Terminal mit folgenden Einstellungen gebraucht: | Für die Seriele Ausgabe wird ein Terminal mit folgenden Einstellungen gebraucht: | ||
− | + | {| class="wikitable" | |
− | + | |- | |
− | + | |Baud Rate ||style="text-align:right"| 9600 | |
− | + | |- | |
− | + | | Bits ||style="text-align:right"| 8 | |
+ | |- | ||
+ | | Stopbits ||style="text-align:right"| 1 | ||
+ | |- | ||
+ | | Parity || none | ||
+ | |} | ||
+ | |||
+ | Bei betätigen non '''[space]''' im Terminal-Programm, sollte ein "Hello World !" zurück kommen. | ||
<syntaxhighlight lang="pascal">program Project1; | <syntaxhighlight lang="pascal">program Project1; | ||
Line 50: | Line 57: | ||
UARTInit; | UARTInit; | ||
repeat | repeat | ||
− | if UARTReadChar = #32 then begin | + | if UARTReadChar = #32 then begin // space |
− | UARTSendString('Hello World !'#13#10); | + | UARTSendString('Hello World !'#13#10); |
end; | end; | ||
until 1 = 2; | until 1 = 2; |
Revision as of 22:47, 3 November 2017
ATmega328p (Arduino uno/nano)
Für die Seriele Ausgabe wird ein Terminal mit folgenden Einstellungen gebraucht:
Baud Rate | 9600 |
Bits | 8 |
Stopbits | 1 |
Parity | none |
Bei betätigen non [space] im Terminal-Programm, sollte ein "Hello World !" zurück kommen.
program Project1;
const
CPU_Clock = 16000000; // Taktfrequenz Arduino, default 16MHz.
Baud = 9600; // Baudrate
Teiler = CPU_Clock div (16 * Baud) - 1;
procedure UARTInit;
begin
UBRR0 := Teiler;
UCSR0A := (0 shl U2X0);
UCSR0B := (1 shl TXEN0) or (1 shl RXEN0);
UCSR0C := (%011 shl UCSZ0);
end;
procedure UARTSendChar(c: char);
begin
while UCSR0A and (1 shl UDRE0) = 0 do begin
end;
UDR0 := byte(c);
end;
function UARTReadChar: char;
begin
while UCSR0A and (1 shl RXC0) = 0 do begin
end;
Result := char(UDR0);
end;
procedure UARTSendString(s: ShortString);
var
i: integer;
begin
for i := 1 to length(s) do begin
UARTSendChar(s[i]);
end;
end;
begin
UARTInit;
repeat
if UARTReadChar = #32 then begin // space
UARTSendString('Hello World !'#13#10);
end;
until 1 = 2;
end.
ATtiny2313
Beim ATtiny2313 habe die Register eine andere Bezeichnung als beim ATmega328p Meistens entfällt die 0 in der Bezeichnung. UBRR0 muss man in UBRRH und UBRRL zerlegen.
UBRRH := Teiler shr 8;
UBRRL := Byte(Teiler);
UCSRB := (1 shl TXEN) or (1 shl RXEN);
UCSRC := (%011 shl UCSZ);
(Der Code wurde nicht getestet)