Sign in Join
Wiki copytemporary

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

Revision 1 to 2. 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-<table>
6261<thead>
63-<tr>
64-<th></th>
65-<th colspan="2">INT1</th>
66-<th></th>
67-<th colspan="2">INT0</th>
68-<th></th>
69-</tr>
62+
7063</thead>
7164<tbody>
72-<tr>
73-<td>Bit</td>
74-<td>3</td>
75-<td>2</td>
76-<td></td>
77-<td>1</td>
78-<td>0</td>
79-<td></td>
80-</tr>
81-<tr>
82-<td></td>
83-<td>0</td>
84-<td>0</td>
85-<td></td>
86-<td>0</td>
87-<td>0</td>
88-<td>Low Level am Pin</td>
89-</tr>
90-<tr>
91-<td></td>
92-<td>0</td>
93-<td>1</td>
94-<td></td>
95-<td>0</td>
96-<td>1</td>
97-<td>Jede Änderung</td>
98-</tr>
99-<tr>
100-<td></td>
101-<td>1</td>
102-<td>0</td>
103-<td></td>
104-<td>1</td>
105-<td>0</td>
106-<td>Pin auf LOW</td>
107-</tr>
108-<tr>
109-<td></td>
110-<td>1</td>
111-<td>1</td>
112-<td></td>
113-<td>1</td>
114-<td>1</td>
115-<td>Pin auf HIGH</td>
116-</tr>
65+
11766</tbody>
118-</table>
11967
12068### INT1
12169
12270Der INT1 muss folgendermassen eingestellt werden.
12371
12472``` pascal
12573 EICRA := %1100; // INT1 wird ausgelöst, wen der Pin auf HIGH geht.
12674 EIMSK := %10; // INT1 aktivieren.
12775```
12876
12977Für den **INT1** muss man die ISR-Procedure für den **INT1** nehmen **(INT1_ISR)**.
13078
13179``` pascal
13280procedure Int1_Interrupt; public Name 'INT1_ISR'; interrupt;
13381begin
13482 // mache Irgendwas
13583end;
13684```
13785
13886## Pin Change Interrupt
13987
14088Dieses Beispiel ist für einen Arduino Nano (Atmega328p).
14189
14290### Terminal Ausgabe
14391
14492Gibt den Pin-Status auf einem Terminal aus.
14593
14694``` pascal
14795 procedure WritePort(p: byte);
14896 begin
14997 UARTSendString('PB' + char(p + 48) + ' : ');
15098 if PinB and (1 shl p) = (1 shl p) then begin
15199 UARTSendString('HIGH ');
152100 end else begin
153101 UARTSendString('LOW ');
154102 end;
155103 end;
156104```
157105
158106### Interrupt Routine
159107
160108Wird bei einer Änderung eines Pines ausgelöst.
161109
162110``` pascal
163111 procedure PC_Int0_Interrupt; public Name 'PCINT0_ISR'; interrupt;
164112 var
165113 i: byte;
166114 begin
167115 UARTSendString(#27'[0;0H'); // Cursor home
168116 for i := 0 to 3 do begin
169117 WritePort(i);
170118 end;
171119 end;
172120```
173121
174122### Pin Change GPIO deklarieren
175123
176124PB0, PB1, PB2 und BP3 für Interrupt aktivieren.
177125
178126``` pascal
179127const
180128 inPortsB = %00001111; // PCINT0 + PCINT1 + PCINT2 + PCINT3
181129```
182130
183131### Pin Change Interrupt aktivieren
184132
185133Die Parameter sind in der Tabelle weiter unten beschrieben.
186134
187135``` pascal
188136begin
189137 DDRB := 0;
190138 PORTB := inPortsB; // PullUp
191139
192140 // UART inizialisieren
193141 UARTInit;
194142
195143 // PCINT0_ISR aktivieren
196144 PCICR := %001; // Nur auf PORTB
197145 PCMSK0 := inPortsB;
198146
199147 // Interrupt aktivieren
200148 asm Sei end;
201149
202150 // Hauptschleife
203151 repeat
204152 // mache Irgendwas
205153 until 1 = 2;
206154end.
207155```
208156
209157### Register für den Atmega328p
210158
211159Folgende Register sind für die Aktivierung der Ports / Pins zuständig:
212160
213161- **PCICR**: Ports, welche einem Interrupt auslösen.
214162- **PCMSKx**: Die einzelnen Pins.
215163
216164Tabelle für **PCICR**:
217165
218166| Bit | 2 | 1 | 0 |
219167|-------|-------|-------|-------|
220168| PCICR | PORTD | PORTC | PORTB |
221169
222170Tabelle für die Pins von **PCMSKx**:
223171
224172| Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
225173|--------|---------|---------|---------|---------|---------|---------|---------|--------|
226174| PCMSK0 | PCINT7 | PCINT6 | PCINT5 | PCINT4 | PCINT3 | PCINT2 | PCINT1 | PCINT0 |
227175| PCMSK1 | | PCINT14 | PCINT13 | PCINT12 | PCINT11 | PCINT10 | PCINT9 | PCINT8 |
228176| PCMSK2 | PCINT23 | PCINT22 | PCINT21 | PCINT20 | PCINT19 | PCINT18 | PCINT17 | PCINT6 |
229177
230178### Beispiel für PORTB und PORTC
231179
232180``` pascal
233181 // PCINT0_ISR und PCINT1_ISR aktivieren
234182 PCICR := %011; // PORTB und PORTC
235183 PCMSK0 := %11000000 // Pin 6 + 7 von PORTB;
236184 PCMSK1 := %00000011 // Pin 0 + 1 von PORTC;
237185```
238186
239187Fü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.
240188
241189``` pascal
242190 procedure PC_Int1_Interrupt; public Name 'PCINT1_ISR'; interrupt;
243191 begin
244192 // mache Irgendwas
245193 end;
246194```
247195
248196# Siehe auch
249197
250198- Übersichtseite [[AVR Embedded Tutorial/de|AVR Embedded Tutorial]]
251199
252200Autor: Mathias
253201
254202---
255203*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).*
256204Category: AVR/de
257205Category: Arduino/de
258206Category: Deutsch
259207Category: Embedded/de
260208Category: Tutorials/de

Back to history