Version 1 mit Interruptverriegeling

Committer:
JoergSturm
Date:
Thu Dec 17 11:30:32 2020 +0000
Revision:
0:5e36fcac4547
Version 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JoergSturm 0:5e36fcac4547 1 /* mbed Microcontroller Library
JoergSturm 0:5e36fcac4547 2 * Copyright (c) 2019 ARM Limited
JoergSturm 0:5e36fcac4547 3 * SPDX-License-Identifier: Apache-2.0
JoergSturm 0:5e36fcac4547 4 */
JoergSturm 0:5e36fcac4547 5
JoergSturm 0:5e36fcac4547 6 #include "mbed.h"
JoergSturm 0:5e36fcac4547 7 #include "platform/mbed_thread.h"
JoergSturm 0:5e36fcac4547 8
JoergSturm 0:5e36fcac4547 9 InterruptIn links(PA_1);
JoergSturm 0:5e36fcac4547 10 InterruptIn rechts(PA_6);
JoergSturm 0:5e36fcac4547 11 InterruptIn stop(PA_10);
JoergSturm 0:5e36fcac4547 12 DigitalIn s(PB_0);
JoergSturm 0:5e36fcac4547 13 PortOut Motor(PortC,0b11);
JoergSturm 0:5e36fcac4547 14 #define Rechts 0b10
JoergSturm 0:5e36fcac4547 15 #define Links 0b01
JoergSturm 0:5e36fcac4547 16 #define Aus 0b00
JoergSturm 0:5e36fcac4547 17
JoergSturm 0:5e36fcac4547 18 void linksISR()
JoergSturm 0:5e36fcac4547 19 {
JoergSturm 0:5e36fcac4547 20 Motor=Links;
JoergSturm 0:5e36fcac4547 21 rechts.disable_irq();
JoergSturm 0:5e36fcac4547 22 }
JoergSturm 0:5e36fcac4547 23 void rechtsISR()
JoergSturm 0:5e36fcac4547 24 {
JoergSturm 0:5e36fcac4547 25 Motor=Rechts;
JoergSturm 0:5e36fcac4547 26 links.disable_irq();
JoergSturm 0:5e36fcac4547 27 }
JoergSturm 0:5e36fcac4547 28 void stopISR()
JoergSturm 0:5e36fcac4547 29 {
JoergSturm 0:5e36fcac4547 30 Motor=Aus;
JoergSturm 0:5e36fcac4547 31 rechts.enable_irq();
JoergSturm 0:5e36fcac4547 32 links.enable_irq();
JoergSturm 0:5e36fcac4547 33 }
JoergSturm 0:5e36fcac4547 34
JoergSturm 0:5e36fcac4547 35 int main()
JoergSturm 0:5e36fcac4547 36 {
JoergSturm 0:5e36fcac4547 37 Motor=Aus;
JoergSturm 0:5e36fcac4547 38 links.mode(PullDown);
JoergSturm 0:5e36fcac4547 39 rechts.mode(PullDown);
JoergSturm 0:5e36fcac4547 40 stop.mode(PullDown);
JoergSturm 0:5e36fcac4547 41 s.mode(PullDown);
JoergSturm 0:5e36fcac4547 42 links.fall(&linksISR);
JoergSturm 0:5e36fcac4547 43 rechts.fall(&rechtsISR);
JoergSturm 0:5e36fcac4547 44 stop.fall(&stopISR);
JoergSturm 0:5e36fcac4547 45 links.enable_irq();
JoergSturm 0:5e36fcac4547 46 rechts.enable_irq();
JoergSturm 0:5e36fcac4547 47 stop.enable_irq();
JoergSturm 0:5e36fcac4547 48 __enable_irq();
JoergSturm 0:5e36fcac4547 49 while (true) {
JoergSturm 0:5e36fcac4547 50 if(s==1)
JoergSturm 0:5e36fcac4547 51 {
JoergSturm 0:5e36fcac4547 52 Motor=Aus;
JoergSturm 0:5e36fcac4547 53 __disable_irq();
JoergSturm 0:5e36fcac4547 54 }
JoergSturm 0:5e36fcac4547 55 else
JoergSturm 0:5e36fcac4547 56 {
JoergSturm 0:5e36fcac4547 57 __enable_irq();
JoergSturm 0:5e36fcac4547 58 }
JoergSturm 0:5e36fcac4547 59 }
JoergSturm 0:5e36fcac4547 60 }