![](/media/cache/profiles/nikki.png.50x50_q85.jpg)
Definisanje vise prekidnih rutina
main.cpp@1:4b541496f679, 2021-11-11 (annotated)
- Committer:
- tzwell
- Date:
- Thu Nov 11 19:17:33 2021 +0000
- Revision:
- 1:4b541496f679
- Parent:
- 0:bda289aee5eb
Added interrupt priority demonstration;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tzwell | 0:bda289aee5eb | 1 | /* |
tzwell | 0:bda289aee5eb | 2 | * Primer koriscenja prekida za STM32L476RG, napisan |
tzwell | 0:bda289aee5eb | 3 | * koristeci mbed.h biblioteku. |
tzwell | 0:bda289aee5eb | 4 | * |
tzwell | 0:bda289aee5eb | 5 | * Katedra za Elektroniku i digitalne sisteme |
tzwell | 0:bda289aee5eb | 6 | * Elektrotehnicki fakultet |
tzwell | 0:bda289aee5eb | 7 | * Beograd |
tzwell | 0:bda289aee5eb | 8 | * |
tzwell | 0:bda289aee5eb | 9 | * Oktobar 2021. |
tzwell | 0:bda289aee5eb | 10 | * |
tzwell | 0:bda289aee5eb | 11 | */ |
tzwell | 0:bda289aee5eb | 12 | |
tzwell | 0:bda289aee5eb | 13 | /* |
tzwell | 0:bda289aee5eb | 14 | * Biblioteke za uvoz: |
tzwell | 0:bda289aee5eb | 15 | */ |
tzwell | 0:bda289aee5eb | 16 | #include "mbed.h" |
tzwell | 0:bda289aee5eb | 17 | |
tzwell | 0:bda289aee5eb | 18 | /* |
tzwell | 0:bda289aee5eb | 19 | * Definisanje makroa: |
tzwell | 0:bda289aee5eb | 20 | */ |
tzwell | 1:4b541496f679 | 21 | |
tzwell | 1:4b541496f679 | 22 | // Sledeci kod otkomentarisati |
tzwell | 1:4b541496f679 | 23 | // da bi se videla demonstracija prioriteta prekida. |
tzwell | 1:4b541496f679 | 24 | /* |
tzwell | 1:4b541496f679 | 25 | #define ON_TIME 2 |
tzwell | 1:4b541496f679 | 26 | #define LED_ON 1 |
tzwell | 1:4b541496f679 | 27 | #define LED_OFF 0 |
tzwell | 1:4b541496f679 | 28 | */ |
tzwell | 0:bda289aee5eb | 29 | |
tzwell | 0:bda289aee5eb | 30 | /* |
tzwell | 0:bda289aee5eb | 31 | * Globalne promenljive: |
tzwell | 0:bda289aee5eb | 32 | */ |
tzwell | 0:bda289aee5eb | 33 | InterruptIn button_sw2 (PC_8); // Kreiranje promenljive tastera SW2 |
tzwell | 0:bda289aee5eb | 34 | InterruptIn button_sw1 (PC_9); // Kreiranje promenljive tastera SW1 |
tzwell | 0:bda289aee5eb | 35 | DigitalOut led2_mb (PB_15); // Kreiranje promenljive diode LED2 |
tzwell | 0:bda289aee5eb | 36 | DigitalOut led1_mb (PA_11); // Kreiranje promenljive diode LED1 |
tzwell | 0:bda289aee5eb | 37 | |
tzwell | 0:bda289aee5eb | 38 | /* |
tzwell | 0:bda289aee5eb | 39 | * Deklaracija funkcija: |
tzwell | 0:bda289aee5eb | 40 | */ |
tzwell | 0:bda289aee5eb | 41 | void ISR_button_sw1 (void); |
tzwell | 0:bda289aee5eb | 42 | void ISR_button_sw2 (void); |
tzwell | 0:bda289aee5eb | 43 | |
tzwell | 0:bda289aee5eb | 44 | /* |
tzwell | 0:bda289aee5eb | 45 | * Glavna funkcija: |
tzwell | 0:bda289aee5eb | 46 | */ |
tzwell | 0:bda289aee5eb | 47 | int main() |
tzwell | 0:bda289aee5eb | 48 | { |
tzwell | 0:bda289aee5eb | 49 | // Inicijalizacija lokalnih promenljivih: |
tzwell | 0:bda289aee5eb | 50 | // Ukljucivanje prekida na silaznu ivicu pinova tastera SW1 i SW2: |
tzwell | 0:bda289aee5eb | 51 | button_sw2.fall(&ISR_button_sw2); |
tzwell | 0:bda289aee5eb | 52 | button_sw1.fall(&ISR_button_sw1); |
tzwell | 0:bda289aee5eb | 53 | |
tzwell | 0:bda289aee5eb | 54 | // Funkcije koje se jedanput izvrsavaju: |
tzwell | 0:bda289aee5eb | 55 | |
tzwell | 0:bda289aee5eb | 56 | // Glavna petlja: |
tzwell | 0:bda289aee5eb | 57 | while(true); |
tzwell | 0:bda289aee5eb | 58 | } |
tzwell | 0:bda289aee5eb | 59 | |
tzwell | 0:bda289aee5eb | 60 | |
tzwell | 0:bda289aee5eb | 61 | /* |
tzwell | 0:bda289aee5eb | 62 | * Definicija funkcija: |
tzwell | 0:bda289aee5eb | 63 | */ |
tzwell | 0:bda289aee5eb | 64 | // Prekidna rutina tastera: |
tzwell | 0:bda289aee5eb | 65 | void ISR_button_sw1() |
tzwell | 0:bda289aee5eb | 66 | { |
tzwell | 0:bda289aee5eb | 67 | led1_mb = !led1_mb; |
tzwell | 1:4b541496f679 | 68 | // Prethodnu liniju zakomentarisati, a sledeci kod otkomentarisati |
tzwell | 1:4b541496f679 | 69 | // da bi se videla demonstracija prioriteta prekida. |
tzwell | 1:4b541496f679 | 70 | /* |
tzwell | 1:4b541496f679 | 71 | led1_mb.write(LED_ON); |
tzwell | 1:4b541496f679 | 72 | wait(ON_TIME); |
tzwell | 1:4b541496f679 | 73 | led1_mb.write(LED_OFF); |
tzwell | 1:4b541496f679 | 74 | */ |
tzwell | 0:bda289aee5eb | 75 | } |
tzwell | 0:bda289aee5eb | 76 | void ISR_button_sw2() |
tzwell | 0:bda289aee5eb | 77 | { |
tzwell | 0:bda289aee5eb | 78 | led2_mb = !led2_mb; |
tzwell | 1:4b541496f679 | 79 | // Prethodnu liniju zakomentarisati, a sledeci kod otkomentarisati |
tzwell | 1:4b541496f679 | 80 | // da bi se videla demonstracija prioriteta prekida. |
tzwell | 1:4b541496f679 | 81 | /* |
tzwell | 1:4b541496f679 | 82 | led2_mb.write(LED_ON); |
tzwell | 1:4b541496f679 | 83 | wait(ON_TIME); |
tzwell | 1:4b541496f679 | 84 | led2_mb.write(LED_OFF); |
tzwell | 1:4b541496f679 | 85 | */ |
tzwell | 0:bda289aee5eb | 86 | } |