Difference between revisions of "AVR Embedded Tutorial - GPIO-Interrupt/de"
From Free Pascal wiki
Jump to navigationJump to searchLine 43: | Line 43: | ||
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===Pin Change GPIO deklarieren=== | ===Pin Change GPIO deklarieren=== | ||
Line 97: | Line 73: | ||
end. | end. | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | ===Register für den Atmega328p=== | ||
+ | Folgende Register sind für die Aktivierung der Ports / Pins zuständig: | ||
+ | * '''PCICR''': Ports, welche einem Interrupt auslösen. | ||
+ | * '''PCMSKx''': Die einzelnen Pins. | ||
+ | |||
+ | Tabelle für '''PCICR''': | ||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | !Bit !! 2 !! 1 !! 0 | ||
+ | |- | ||
+ | |PCICR || PORTD || PORTC || PORTB | ||
+ | |} | ||
+ | |||
+ | Tabelle für '''PCMSKx''': | ||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | !Bit !! 7 !! 6 !! 5 !! 4 !! 3 !! 2 !! 1 !! 0 | ||
+ | |- | ||
+ | |PCMSK0 || PCINT7 || PCINT6 || PCINT5 || PCINT4 || PCINT3 || PCINT2 || PCINT1 || PCINT0 | ||
+ | |- | ||
+ | |PCMSK1 || || PCINT14|| PCINT13|| PCINT12|| PCINT11|| PCINT10|| PCINT9 || PCINT8 | ||
+ | |- | ||
+ | |PCMSK2 || PCINT23|| PCINT22|| PCINT21|| PCINT20|| PCINT19|| PCINT18|| PCINT17|| PCINT6 | ||
+ | |} | ||
[[Category:AVR]] {{AutoCategory}} | [[Category:AVR]] {{AutoCategory}} |
Revision as of 18:21, 12 November 2017
GPIO Interrupt
Vorwort
Wie man die GPIO und UART ansteuert, steht hier:
INT0 + INT1
kommt noch
Pin Change Interrupt
Dieses Beispiel ist für einen Arduino Nano (Atmega328p).
Terminal Ausgabe
Gibt den Pin-Status auf einem Terminal aus.
procedure WritePort(p: byte);
begin
UARTSendString('PB' + char(p + 48) + ' : ');
if PinB and (1 shl p) = (1 shl p) then begin
UARTSendString('HIGH ');
end else begin
UARTSendString('LOW ');
end;
end;
Interrupt
Wird bei einer Änderung eines Pines ausgelöst.
procedure PC_Int0_Interrupt; public Name 'PCINT0_ISR'; interrupt;
var
i: byte;
begin
UARTSendString(#27'[0;0H'); // Cursor home
for i := 0 to 3 do begin
WritePort(i);
end;
end;
Pin Change GPIO deklarieren
PB0, PB1, PB2 und BP3 für Interrupt aktivieren.
const
inPortsB = %00001111; // PCINT0 + PCINT1 + PCINT2 + PCINT3
Pin Change Interrupt aktivieren
begin
DDRB := 0;
PORTB := inPortsB; // PullUp
// UART inizialisieren
UARTInit;
// PC_INT0 aktivieren
PCICR := %001; // Nur auf PORTB
PCMSK0 := inPortsB;
// Interrupt aktivieren
asm Sei end;
// Hauptschleife
repeat
// mache Irgendwas
until 1 = 2;
end.
Register für den Atmega328p
Folgende Register sind für die Aktivierung der Ports / Pins zuständig:
- PCICR: Ports, welche einem Interrupt auslösen.
- PCMSKx: Die einzelnen Pins.
Tabelle für PCICR:
Bit | 2 | 1 | 0 |
---|---|---|---|
PCICR | PORTD | PORTC | PORTB |
Tabelle für PCMSKx:
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
PCMSK0 | PCINT7 | PCINT6 | PCINT5 | PCINT4 | PCINT3 | PCINT2 | PCINT1 | PCINT0 |
PCMSK1 | PCINT14 | PCINT13 | PCINT12 | PCINT11 | PCINT10 | PCINT9 | PCINT8 | |
PCMSK2 | PCINT23 | PCINT22 | PCINT21 | PCINT20 | PCINT19 | PCINT18 | PCINT17 | PCINT6 |