Difference between revisions of "AVR Embedded Tutorial - GPIO-Interrupt/de"

From Free Pascal wiki
Jump to navigationJump to search
Line 55: Line 55:
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
 
begin
 
begin
   DDRB := 0;
+
   DDRB := 0;
 
   PORTB := inPortsB; // PullUp
 
   PORTB := inPortsB; // PullUp
  
Line 61: Line 61:
 
   UARTInit;
 
   UARTInit;
  
   // PC_INT0 aktivieren
+
   // PCINT0_ISR aktivieren
 
   PCICR := %001; // Nur auf PORTB
 
   PCICR := %001; // Nur auf PORTB
 
   PCMSK0 := inPortsB;
 
   PCMSK0 := inPortsB;
Line 88: Line 88:
 
|}
 
|}
  
Tabelle für '''PCMSKx''':
+
Tabelle für die Pins von '''PCMSKx''':
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 99: Line 99:
 
|PCMSK2 || PCINT23|| PCINT22|| PCINT21|| PCINT20|| PCINT19|| PCINT18|| PCINT17|| PCINT6
 
|PCMSK2 || PCINT23|| PCINT22|| PCINT21|| PCINT20|| PCINT19|| PCINT18|| PCINT17|| PCINT6
 
|}
 
|}
 +
 +
===Beispiel für PORTB und PORTC===
 +
<syntaxhighlight lang="pascal">
 +
  // PCINT0_ISR und PCINT1_ISR aktivieren
 +
  PCICR  := %011;    // PORTB und PORTC
 +
  PCMSK0 := %11000000 // Pin 6 + 7 von PORTB;
 +
  PCMSK1 := %00000011 // Pin 0 + 1 von PORTC;
 +
 +
  // Interrupt aktivieren
 +
  asm Sei end;
 +
 +
  // Hauptschleife
 +
  repeat
 +
    // mache Irgendwas
 +
  until 1 = 2;
 +
end.
 +
</syntaxhighlight>
 +
 +
Für den '''PCINT1_ISR''' kommt noch eine 2. ISR-Procedure dazu. Wen man PORTD auch noch verwenden würde, dann würde noch eine Procedure mit 'PCINT2_ISR' dazukommen.
 +
<syntaxhighlight lang="pascal">
 +
  procedure PC_Int1_Interrupt; public Name 'PCINT1_ISR'; interrupt;
 +
  begin
 +
    // mache Irgendwas
 +
  end;
 +
</syntaxhighlight>
 +
  
 
[[Category:AVR]] {{AutoCategory}}
 
[[Category:AVR]] {{AutoCategory}}

Revision as of 18:32, 12 November 2017

Template:Translate

Warning-icon.png

Warnung: In Arbeit

GPIO Interrupt

Vorwort

Wie man die GPIO und UART ansteuert, steht hier:

  • GPIO
  • UART UARTInit und UARTSendString(...

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

Die Parameter sind in der Tabelle weiter unten beschrieben.

begin
  DDRB  := 0;
  PORTB := inPortsB; // PullUp

  // UART inizialisieren
  UARTInit;

  // PCINT0_ISR 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 die Pins von 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

Beispiel für PORTB und PORTC

  // PCINT0_ISR und PCINT1_ISR aktivieren
  PCICR  := %011;     // PORTB und PORTC
  PCMSK0 := %11000000 // Pin 6 + 7 von PORTB;
  PCMSK1 := %00000011 // Pin 0 + 1 von PORTC;

  // Interrupt aktivieren
  asm Sei end;

  // Hauptschleife
  repeat
    // mache Irgendwas
  until 1 = 2;
end.

Für den PCINT1_ISR kommt noch eine 2. ISR-Procedure dazu. Wen man PORTD auch noch verwenden würde, dann würde noch eine Procedure mit 'PCINT2_ISR' dazukommen.

  procedure PC_Int1_Interrupt; public Name 'PCINT1_ISR'; interrupt;
  begin
    // mache Irgendwas
  end;