Difference between revisions of "AVR Embedded Tutorial - UART/de"
From Lazarus wiki
Jump to navigationJump to searchm (Mathias moved page UART/de to AVR Embedded Tutorial - UART/de) |
|||
Line 65: | Line 65: | ||
===ATtiny2313=== | ===ATtiny2313=== | ||
Beim ATtiny2313 haben die Register eine andere Bezeichnung als beim ATmega328p. | Beim ATtiny2313 haben die Register eine andere Bezeichnung als beim ATmega328p. | ||
− | + | * Die '''0''' entfällt in der Bezeichnung. | |
− | '''UBRR0''' muss man in '''UBRRH''' und '''UBRRL''' zerlegen. | + | * '''UBRR0''' muss man in '''UBRRH''' und '''UBRRL''' zerlegen. |
+ | Das sieht dann so aus: | ||
− | <syntaxhighlight lang="pascal">UBRRH := Teiler shr 8; | + | <syntaxhighlight lang="pascal"> |
+ | UBRRH := Teiler shr 8; | ||
UBRRL := Byte(Teiler); | UBRRL := Byte(Teiler); | ||
UCSRB := (1 shl TXEN) or (1 shl RXEN); | UCSRB := (1 shl TXEN) or (1 shl RXEN); | ||
− | UCSRC := (%011 shl UCSZ);</syntaxhighlight> | + | UCSRC := (%011 shl UCSZ); |
+ | </syntaxhighlight> | ||
(Der Code wurde nicht getestet) | (Der Code wurde nicht getestet) | ||
− | |||
[[Category:AVR]] {{AutoCategory}} | [[Category:AVR]] {{AutoCategory}} |
Revision as of 18:57, 11 November 2017
ATmega328p (Arduino uno/nano)
Für die serielle Ausgabe wird ein Terminal mit folgenden Einstellungen gebraucht:
Baud Rate | 9600 |
Bits | 8 |
Stopbits | 1 |
Parity | none |
Beim Betätigen von [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 haben die Register eine andere Bezeichnung als beim ATmega328p.
- Die 0 entfällt in der Bezeichnung.
- UBRR0 muss man in UBRRH und UBRRL zerlegen.
Das sieht dann so aus:
UBRRH := Teiler shr 8;
UBRRL := Byte(Teiler);
UCSRB := (1 shl TXEN) or (1 shl RXEN);
UCSRC := (%011 shl UCSZ);
(Der Code wurde nicht getestet)