Sign in Join
Wiki copytemporary

AVR Embedded Tutorial - GPIO-Interrupt/de: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11# GPIO Interrupt
22
33## Vorwort
44
55Wie man die GPIO und UART ansteuert, steht hier:
66
77- [[AVR Embedded Tutorial - Simple GPIO on and off output/de|GPIO]]
88- [[AVR Embedded Tutorial - UART/de|UART]] *UARTInit* und *UARTSendString(...*
99
1010## Externe Interrupt
1111
1212Interrupt Pin-Belegung beim ATmega328:
1313
1414- INT0: PD2
1515- INT1: PD3
1616
1717### Interrupt Routine
1818
1919Diese Beispiel zeigt wie dies beim INT0 geht. Wann der Interrupt ausgelöst wird, gibt man mit **EICRA** an. Siehe Tabelle weiter unten. Man kann auch **INT0** und **INT1** gleichzeitig aktivieren.
2020
2121``` pascal
2222procedure Int0_Interrupt; public Name 'INT0_ISR'; interrupt;
2323begin
2424 UARTSendString('INT0'); // Identify interrupt
2525end;
2626```
2727
2828### Interrupt aktivieren
2929
3030Die Parameter sind in der Tabelle weiter unten beschrieben.
3131
3232``` pascal
3333begin
3434 PORTD := %00001100; // PullUp Pin 2 + 3
3535
3636 // UART inizialisieren
3737 UARTInit;
3838
3939 // INT0 aktivieren
4040 EICRA := %11; // INT0 wird ausgelöst, wen der Pin auf HIGH geht.
4141 EIMSK := %01; // INT0 aktivieren.
4242
4343 // Interrupt aktivieren
4444 asm Sei end;
4545
4646 // Hauptschleife
4747 repeat
4848 until 1 = 2;
4949end.
5050```
5151
5252### Register für den Atmega328p
5353
5454Folgende Register sind für die Aktivierung der Ports / Pins zuständig:
5555
5656- **EICRA**: Funktion des Interrupt.
5757- **EIMSK**: INT0 und/oder INT1 aktivieren.
5858
5959Tabelle für **EICRA**, sie zeigt, bei was für einer Aktion am Pin ein Interrupt ausgelöst wird.
6060
61-<thead>
62-
63-</thead>
64-<tbody>
65-
66-</tbody>
61+| | INT1 | | | INT0 | | |
62+|---|---|---|---|---|---|---|
63+| Bit | 3 | 2 | | 1 | 0 | |
64+| | 0 | 0 | | 0 | 0 | Low Level am Pin |
65+| | 0 | 1 | | 0 | 1 | Jede Änderung |
66+| | 1 | 0 | | 1 | 0 | Pin auf LOW |
67+| | 1 | 1 | | 1 | 1 | Pin auf HIGH |
6768
6869### INT1
6970
7071Der INT1 muss folgendermassen eingestellt werden.
7172
7273``` pascal
7374 EICRA := %1100; // INT1 wird ausgelöst, wen der Pin auf HIGH geht.
7475 EIMSK := %10; // INT1 aktivieren.
7576```
7677
7778Für den **INT1** muss man die ISR-Procedure für den **INT1** nehmen **(INT1_ISR)**.
7879
7980``` pascal
8081procedure Int1_Interrupt; public Name 'INT1_ISR'; interrupt;
8182begin
8283 // mache Irgendwas
8384end;
8485```
8586
8687## Pin Change Interrupt
8788
8889Dieses Beispiel ist für einen Arduino Nano (Atmega328p).
8990
9091### Terminal Ausgabe
9192
9293Gibt den Pin-Status auf einem Terminal aus.
9394
9495``` pascal
9596 procedure WritePort(p: byte);
9697 begin
9798 UARTSendString('PB' + char(p + 48) + ' : ');
9899 if PinB and (1 shl p) = (1 shl p) then begin
99100 UARTSendString('HIGH ');
100101 end else begin
101102 UARTSendString('LOW ');
102103 end;
103104 end;
104105```
105106
106107### Interrupt Routine
107108
108109Wird bei einer Änderung eines Pines ausgelöst.
109110
110111``` pascal
111112 procedure PC_Int0_Interrupt; public Name 'PCINT0_ISR'; interrupt;
112113 var
113114 i: byte;
114115 begin
115116 UARTSendString(#27'[0;0H'); // Cursor home
116117 for i := 0 to 3 do begin
117118 WritePort(i);
118119 end;
119120 end;
120121```
121122
122123### Pin Change GPIO deklarieren
123124
124125PB0, PB1, PB2 und BP3 für Interrupt aktivieren.
125126
126127``` pascal
127128const
128129 inPortsB = %00001111; // PCINT0 + PCINT1 + PCINT2 + PCINT3
129130```
130131
131132### Pin Change Interrupt aktivieren
132133
133134Die Parameter sind in der Tabelle weiter unten beschrieben.
134135
135136``` pascal
136137begin
137138 DDRB := 0;
138139 PORTB := inPortsB; // PullUp
139140
140141 // UART inizialisieren
141142 UARTInit;
142143
143144 // PCINT0_ISR aktivieren
144145 PCICR := %001; // Nur auf PORTB
145146 PCMSK0 := inPortsB;
146147
147148 // Interrupt aktivieren
148149 asm Sei end;
149150
150151 // Hauptschleife
151152 repeat
152153 // mache Irgendwas
153154 until 1 = 2;
154155end.
155156```
156157
157158### Register für den Atmega328p
158159
159160Folgende Register sind für die Aktivierung der Ports / Pins zuständig:
160161
161162- **PCICR**: Ports, welche einem Interrupt auslösen.
162163- **PCMSKx**: Die einzelnen Pins.
163164
164165Tabelle für **PCICR**:
165166
166167| Bit | 2 | 1 | 0 |
167168|-------|-------|-------|-------|
168169| PCICR | PORTD | PORTC | PORTB |
169170
170171Tabelle für die Pins von **PCMSKx**:
171172
172173| Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
173174|--------|---------|---------|---------|---------|---------|---------|---------|--------|
174175| PCMSK0 | PCINT7 | PCINT6 | PCINT5 | PCINT4 | PCINT3 | PCINT2 | PCINT1 | PCINT0 |
175176| PCMSK1 | | PCINT14 | PCINT13 | PCINT12 | PCINT11 | PCINT10 | PCINT9 | PCINT8 |
176177| PCMSK2 | PCINT23 | PCINT22 | PCINT21 | PCINT20 | PCINT19 | PCINT18 | PCINT17 | PCINT6 |
177178
178179### Beispiel für PORTB und PORTC
179180
180181``` pascal
181182 // PCINT0_ISR und PCINT1_ISR aktivieren
182183 PCICR := %011; // PORTB und PORTC
183184 PCMSK0 := %11000000 // Pin 6 + 7 von PORTB;
184185 PCMSK1 := %00000011 // Pin 0 + 1 von PORTC;
185186```
186187
187188Fü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.
188189
189190``` pascal
190191 procedure PC_Int1_Interrupt; public Name 'PCINT1_ISR'; interrupt;
191192 begin
192193 // mache Irgendwas
193194 end;
194195```
195196
196197# Siehe auch
197198
198199- Übersichtseite [[AVR Embedded Tutorial/de|AVR Embedded Tutorial]]
199200
200201Autor: Mathias
201202
202203---
203204*From the Free Pascal wiki, page "AVR Embedded Tutorial - GPIO-Interrupt/de", as it stood on 2020-01-23 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
204205Category: AVR/de
205206Category: Arduino/de
206207Category: Deutsch
207208Category: Embedded/de
208209Category: Tutorials/de

Back to history