Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:060d22d109e9, 2020-11-03 (annotated)
- Committer:
- prof_al
- Date:
- Tue Nov 03 15:34:04 2020 +0000
- Revision:
- 0:060d22d109e9
Version 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
prof_al | 0:060d22d109e9 | 1 | /*************************************************************************** |
prof_al | 0:060d22d109e9 | 2 | * Titel : main.c |
prof_al | 0:060d22d109e9 | 3 | * |
prof_al | 0:060d22d109e9 | 4 | * Description : Labormodul "HAPO" |
prof_al | 0:060d22d109e9 | 5 | * |
prof_al | 0:060d22d109e9 | 6 | * Revision List: |
prof_al | 0:060d22d109e9 | 7 | -------------------------------------------------------------------------- |
prof_al | 0:060d22d109e9 | 8 | Date | Author | Change |
prof_al | 0:060d22d109e9 | 9 | -------------------------------------------------------------------------- |
prof_al | 0:060d22d109e9 | 10 | 30.10.20 | J. Altenburg | Ersterstellung |
prof_al | 0:060d22d109e9 | 11 | -------------------------------------------------------------------------- |
prof_al | 0:060d22d109e9 | 12 | | | |
prof_al | 0:060d22d109e9 | 13 | ---------------------------------------------------------------------------- |
prof_al | 0:060d22d109e9 | 14 | ****************************************************************************/ |
prof_al | 0:060d22d109e9 | 15 | #include "mbed.h" |
prof_al | 0:060d22d109e9 | 16 | #include "cdef.h" |
prof_al | 0:060d22d109e9 | 17 | |
prof_al | 0:060d22d109e9 | 18 | /* Vereinbarungen zu den Tasteneingängen */ |
prof_al | 0:060d22d109e9 | 19 | DigitalIn pinS1(A1); |
prof_al | 0:060d22d109e9 | 20 | DigitalIn pinS2(A2); |
prof_al | 0:060d22d109e9 | 21 | DigitalIn pinS3(A3); |
prof_al | 0:060d22d109e9 | 22 | |
prof_al | 0:060d22d109e9 | 23 | /* Ausgänge als "BUS" konfigurieren */ |
prof_al | 0:060d22d109e9 | 24 | BusOut bLed(D10, D11, D12, D13); |
prof_al | 0:060d22d109e9 | 25 | |
prof_al | 0:060d22d109e9 | 26 | /*************************************************************************** |
prof_al | 0:060d22d109e9 | 27 | * Defines und Makros * |
prof_al | 0:060d22d109e9 | 28 | ***************************************************************************/ |
prof_al | 0:060d22d109e9 | 29 | #define nPressed 0 /* Tasten sind "low active" */ |
prof_al | 0:060d22d109e9 | 30 | #define nPressedLong 4 |
prof_al | 0:060d22d109e9 | 31 | |
prof_al | 0:060d22d109e9 | 32 | #define n500ms 165000 /* Laufzeitparameter für 500 ms */ |
prof_al | 0:060d22d109e9 | 33 | |
prof_al | 0:060d22d109e9 | 34 | #define nLed1 0x01 /* Bitposition Led 1 */ |
prof_al | 0:060d22d109e9 | 35 | #define nLed2 0x02 |
prof_al | 0:060d22d109e9 | 36 | #define nLed3 0x04 |
prof_al | 0:060d22d109e9 | 37 | #define nLed4 0x08 |
prof_al | 0:060d22d109e9 | 38 | |
prof_al | 0:060d22d109e9 | 39 | #define nLedOff (nLed1 | nLed2 | nLed3 | nLed4) |
prof_al | 0:060d22d109e9 | 40 | |
prof_al | 0:060d22d109e9 | 41 | enum{ /* Bezeichner für Zustandsautomat */ |
prof_al | 0:060d22d109e9 | 42 | enBlinkNothing = 0 |
prof_al | 0:060d22d109e9 | 43 | , enBlinkLed2Only |
prof_al | 0:060d22d109e9 | 44 | , enBlinkAll |
prof_al | 0:060d22d109e9 | 45 | , enBlinkWarnOnly |
prof_al | 0:060d22d109e9 | 46 | }; |
prof_al | 0:060d22d109e9 | 47 | |
prof_al | 0:060d22d109e9 | 48 | byte bS3Timer; /* |
prof_al | 0:060d22d109e9 | 49 | * Description : Timer für Taste S3 |
prof_al | 0:060d22d109e9 | 50 | */ |
prof_al | 0:060d22d109e9 | 51 | |
prof_al | 0:060d22d109e9 | 52 | byte bState; /* |
prof_al | 0:060d22d109e9 | 53 | * Description : Variable für Zustandsautomat |
prof_al | 0:060d22d109e9 | 54 | */ |
prof_al | 0:060d22d109e9 | 55 | |
prof_al | 0:060d22d109e9 | 56 | dword dwTimer; /* |
prof_al | 0:060d22d109e9 | 57 | * Description : Hilfsvariable zur Erzeugung der 200 ms Programmlaufzeit |
prof_al | 0:060d22d109e9 | 58 | */ |
prof_al | 0:060d22d109e9 | 59 | |
prof_al | 0:060d22d109e9 | 60 | /* Tastenfunktion Taste S1 */ |
prof_al | 0:060d22d109e9 | 61 | void vTasteS1( void ){ |
prof_al | 0:060d22d109e9 | 62 | byte i; |
prof_al | 0:060d22d109e9 | 63 | i = bLed; /* BUS lesen */ |
prof_al | 0:060d22d109e9 | 64 | if(pinS1 == nPressed){ /* Taste gedrückt */ |
prof_al | 0:060d22d109e9 | 65 | i &= ~nLed1; /* LED AN */ |
prof_al | 0:060d22d109e9 | 66 | } |
prof_al | 0:060d22d109e9 | 67 | else{ /* Taste nicht gedrückt */ |
prof_al | 0:060d22d109e9 | 68 | i |= nLed1; /* LED AUS */ |
prof_al | 0:060d22d109e9 | 69 | } |
prof_al | 0:060d22d109e9 | 70 | bLed = i; |
prof_al | 0:060d22d109e9 | 71 | } |
prof_al | 0:060d22d109e9 | 72 | |
prof_al | 0:060d22d109e9 | 73 | /* Tastenfunktion Taste S3 */ |
prof_al | 0:060d22d109e9 | 74 | void vTasteS3( void ){ |
prof_al | 0:060d22d109e9 | 75 | } |
prof_al | 0:060d22d109e9 | 76 | |
prof_al | 0:060d22d109e9 | 77 | /* LED2 blinken lassen */ |
prof_al | 0:060d22d109e9 | 78 | void vToggleLed2( void ){ |
prof_al | 0:060d22d109e9 | 79 | } |
prof_al | 0:060d22d109e9 | 80 | |
prof_al | 0:060d22d109e9 | 81 | /* Wechelblinker LED2/3 */ |
prof_al | 0:060d22d109e9 | 82 | void vToggleLed34( void ){ |
prof_al | 0:060d22d109e9 | 83 | } |
prof_al | 0:060d22d109e9 | 84 | |
prof_al | 0:060d22d109e9 | 85 | /* Zustandsautomat */ |
prof_al | 0:060d22d109e9 | 86 | void vStateMachine( void ){ |
prof_al | 0:060d22d109e9 | 87 | } |
prof_al | 0:060d22d109e9 | 88 | |
prof_al | 0:060d22d109e9 | 89 | /*************************************************************************** |
prof_al | 0:060d22d109e9 | 90 | * main() |
prof_al | 0:060d22d109e9 | 91 | ***************************************************************************/ |
prof_al | 0:060d22d109e9 | 92 | int main() { |
prof_al | 0:060d22d109e9 | 93 | dwTimer = n500ms; |
prof_al | 0:060d22d109e9 | 94 | bLed = nLedOff; |
prof_al | 0:060d22d109e9 | 95 | bState = enBlinkNothing; |
prof_al | 0:060d22d109e9 | 96 | while(1) { /* zeitliche Strukur */ |
prof_al | 0:060d22d109e9 | 97 | vTasteS1(); /* bei jedem Durchlauf */ |
prof_al | 0:060d22d109e9 | 98 | dwTimer--; |
prof_al | 0:060d22d109e9 | 99 | if(dwTimer == 0){ /* alle 500 ms */ |
prof_al | 0:060d22d109e9 | 100 | dwTimer = n500ms; |
prof_al | 0:060d22d109e9 | 101 | vTasteS3(); |
prof_al | 0:060d22d109e9 | 102 | vStateMachine(); |
prof_al | 0:060d22d109e9 | 103 | } |
prof_al | 0:060d22d109e9 | 104 | } |
prof_al | 0:060d22d109e9 | 105 | } |