![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
2 Tasten steuern 2 Interrupts welche 2 4bit Counter bedienen
main.cpp@1:62778ff59cc8, 2019-11-22 (annotated)
- Committer:
- heseg
- Date:
- Fri Nov 22 15:03:43 2019 +0000
- Revision:
- 1:62778ff59cc8
- Parent:
- 0:7a20a6aa1f5e
2 Tasten, 2 Interrupts, 2 Counter (4bit)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
heseg | 1:62778ff59cc8 | 1 | /* ********************************************************** */ |
heseg | 1:62778ff59cc8 | 2 | /* *************** Projekt: BuNuc_Interrupt_Taste *********** */ |
heseg | 1:62778ff59cc8 | 3 | /* BULME Graz, Abteilung Elektronik und Technische Informatik */ |
heseg | 1:62778ff59cc8 | 4 | /* ********************************************************** */ |
heseg | 1:62778ff59cc8 | 5 | // 2 Tasten bedienen je einen 4 bit Zähler, Visualisierung durch LED |
mbed_official | 0:7a20a6aa1f5e | 6 | #include "mbed.h" |
mbed_official | 0:7a20a6aa1f5e | 7 | |
heseg | 1:62778ff59cc8 | 8 | InterruptIn taste1 (A1); |
heseg | 1:62778ff59cc8 | 9 | InterruptIn taste2 (A2); |
heseg | 1:62778ff59cc8 | 10 | BusOut vtaste1(D11, D12, A6, D13); |
heseg | 1:62778ff59cc8 | 11 | BusOut vtaste2(D2, D3, D6, D9); |
heseg | 1:62778ff59cc8 | 12 | DigitalOut rgb(D0); |
heseg | 1:62778ff59cc8 | 13 | |
heseg | 1:62778ff59cc8 | 14 | short counter1, counter2; |
mbed_official | 0:7a20a6aa1f5e | 15 | |
heseg | 1:62778ff59cc8 | 16 | void flip1() // Interruptprogramm 1 |
heseg | 1:62778ff59cc8 | 17 | { |
heseg | 1:62778ff59cc8 | 18 | vtaste1 = ++counter1; |
heseg | 1:62778ff59cc8 | 19 | if(vtaste1==16) counter1=0; |
mbed_official | 0:7a20a6aa1f5e | 20 | } |
heseg | 1:62778ff59cc8 | 21 | void flip2() // Interruptprogramm 2 |
heseg | 1:62778ff59cc8 | 22 | { |
heseg | 1:62778ff59cc8 | 23 | vtaste2 = ++counter2; |
heseg | 1:62778ff59cc8 | 24 | if(vtaste2==16) counter2=0; |
heseg | 1:62778ff59cc8 | 25 | } |
mbed_official | 0:7a20a6aa1f5e | 26 | |
heseg | 1:62778ff59cc8 | 27 | int main() |
heseg | 1:62778ff59cc8 | 28 | { |
heseg | 1:62778ff59cc8 | 29 | taste1.fall(&flip1); // attach the address of the flip function to the falling edge |
heseg | 1:62778ff59cc8 | 30 | taste2.fall(&flip2); // attach the address of the flip function to the falling edge |
heseg | 1:62778ff59cc8 | 31 | while(1) |
heseg | 1:62778ff59cc8 | 32 | { // wait around, interrupts will interrupt this! |
heseg | 1:62778ff59cc8 | 33 | rgb = !rgb; |
mbed_official | 0:7a20a6aa1f5e | 34 | wait(0.25); |
mbed_official | 0:7a20a6aa1f5e | 35 | } |
mbed_official | 0:7a20a6aa1f5e | 36 | } |