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.
Dependencies: mbed
main.cpp@19:8fdd91276de8, 2022-12-05 (annotated)
- Committer:
- alexander0707
- Date:
- Mon Dec 05 13:51:24 2022 +0000
- Revision:
- 19:8fdd91276de8
- Parent:
- 18:6f0897438c03
- Child:
- 20:0f975b296b67
V3.0 Anderer Ansatz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
prof_al | 0:5ac32d240694 | 1 | /*************************************************************************** |
alexander0707 | 5:5c9b508670cf | 2 | * Titel : main.cpp |
prof_al | 0:5ac32d240694 | 3 | * |
alexander0707 | 5:5c9b508670cf | 4 | * Description : Labormodul "HAPOA" |
prof_al | 0:5ac32d240694 | 5 | * |
prof_al | 0:5ac32d240694 | 6 | * Revision List: |
prof_al | 0:5ac32d240694 | 7 | -------------------------------------------------------------------------- |
prof_al | 0:5ac32d240694 | 8 | Date | Author | Change |
prof_al | 0:5ac32d240694 | 9 | -------------------------------------------------------------------------- |
prof_al | 0:5ac32d240694 | 10 | 24.10.22 | J. Altenburg | Ersterstellung |
prof_al | 0:5ac32d240694 | 11 | -------------------------------------------------------------------------- |
prof_al | 0:5ac32d240694 | 12 | | | |
alexander0707 | 5:5c9b508670cf | 13 | --------------------------------------------------------------------------- |
alexander0707 | 5:5c9b508670cf | 14 | |
alexander0707 | 5:5c9b508670cf | 15 | Editor List: |
alexander0707 | 5:5c9b508670cf | 16 | -------------------------------------------------------------------------- |
alexander0707 | 5:5c9b508670cf | 17 | Date | Author | Change |
alexander0707 | 5:5c9b508670cf | 18 | -------------------------------------------------------------------------- |
alexander0707 | 5:5c9b508670cf | 19 | 30.11.22 |Tobias Zinke | Labor03 |
alexander0707 | 5:5c9b508670cf | 20 | -------------------------------------------------------------------------- |
alexander0707 | 5:5c9b508670cf | 21 | 30.11.22 |Alexander Pitthan| Labor03 |
alexander0707 | 5:5c9b508670cf | 22 | --------------------------------------------------------------------------- |
prof_al | 0:5ac32d240694 | 23 | ****************************************************************************/ |
prof_al | 0:5ac32d240694 | 24 | #include "mbed.h" |
prof_al | 0:5ac32d240694 | 25 | #include "cdef.h" |
prof_al | 0:5ac32d240694 | 26 | |
alexander0707 | 5:5c9b508670cf | 27 | AnalogIn pinPoti (A0); |
alexander0707 | 5:5c9b508670cf | 28 | |
prof_al | 0:5ac32d240694 | 29 | /* Vereinbarungen zu den Tasteneingängen */ |
prof_al | 0:5ac32d240694 | 30 | DigitalIn pinS1(A1); |
prof_al | 0:5ac32d240694 | 31 | DigitalIn pinS2(A2); |
prof_al | 0:5ac32d240694 | 32 | DigitalIn pinS3(A3); |
prof_al | 0:5ac32d240694 | 33 | |
alexander0707 | 12:bd1417475c5f | 34 | //BusOut bLedShield(D10, D11, D12, D13); |
prof_al | 0:5ac32d240694 | 35 | |
prof_al | 0:5ac32d240694 | 36 | /* Anschlüsse der Schieberegister */ |
prof_al | 0:5ac32d240694 | 37 | DigitalOut pinSdo(PA_9); |
prof_al | 0:5ac32d240694 | 38 | DigitalOut pinSck(PA_8); |
prof_al | 0:5ac32d240694 | 39 | DigitalOut pinLoad(PB_5); |
alexander0707 | 6:4e55101c65f4 | 40 | DigitalOut pinBeep(PB_3); |
prof_al | 0:5ac32d240694 | 41 | |
prof_al | 0:5ac32d240694 | 42 | /* ISR */ |
prof_al | 0:5ac32d240694 | 43 | Ticker stTimer; |
prof_al | 0:5ac32d240694 | 44 | |
prof_al | 0:5ac32d240694 | 45 | /*************************************************************************** |
prof_al | 0:5ac32d240694 | 46 | * Defines und Makros * |
prof_al | 0:5ac32d240694 | 47 | ***************************************************************************/ |
alexander0707 | 5:5c9b508670cf | 48 | #define nTastShort 20 /* Taste 50 Millisekunden gedrückt */ |
alexander0707 | 12:bd1417475c5f | 49 | #define nTastLong 240 /* Taste 0.6 Sekunden gedrückt */ |
alexander0707 | 5:5c9b508670cf | 50 | #define nCircleTime 2500 /* Laufzeit der Main in us */ |
prof_al | 0:5ac32d240694 | 51 | |
prof_al | 0:5ac32d240694 | 52 | #define nSegA 0x01 |
prof_al | 0:5ac32d240694 | 53 | #define nSegB 0x02 |
prof_al | 0:5ac32d240694 | 54 | #define nSegC 0x04 |
prof_al | 0:5ac32d240694 | 55 | #define nSegD 0x08 |
prof_al | 0:5ac32d240694 | 56 | #define nSegE 0x10 |
prof_al | 0:5ac32d240694 | 57 | #define nSegF 0x20 |
prof_al | 0:5ac32d240694 | 58 | #define nSegG 0x40 |
prof_al | 0:5ac32d240694 | 59 | #define nSegH 0x80 |
prof_al | 0:5ac32d240694 | 60 | |
prof_al | 0:5ac32d240694 | 61 | #define nZiffer0 ~(nSegA | nSegB | nSegC | nSegD | nSegE | nSegF) |
prof_al | 0:5ac32d240694 | 62 | #define nZiffer1 ~(nSegB | nSegC) |
prof_al | 0:5ac32d240694 | 63 | #define nZiffer2 ~(nSegA | nSegB | nSegD | nSegE | nSegG) |
prof_al | 0:5ac32d240694 | 64 | #define nZiffer3 ~(nSegA | nSegB | nSegC | nSegD | nSegG) |
prof_al | 0:5ac32d240694 | 65 | #define nZiffer4 ~(nSegB | nSegC | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 66 | #define nZiffer5 ~(nSegA | nSegC | nSegD | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 67 | #define nZiffer6 ~(nSegA | nSegC | nSegD | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 68 | #define nZiffer7 ~(nSegA | nSegB | nSegC) |
prof_al | 0:5ac32d240694 | 69 | #define nZiffer8 ~(nSegA | nSegB | nSegC | nSegD | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 70 | #define nZiffer9 ~(nSegA | nSegB | nSegC | nSegD | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 71 | #define nZifferA ~(nSegA | nSegB | nSegC | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 72 | #define nZifferB ~(nSegC | nSegD | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 73 | #define nZifferC ~(nSegA | nSegD | nSegE | nSegF) |
prof_al | 0:5ac32d240694 | 74 | #define nZifferD ~(nSegB | nSegC | nSegD | nSegE | nSegG) |
prof_al | 0:5ac32d240694 | 75 | #define nZifferE ~(nSegA | nSegD | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 76 | #define nZifferF ~(nSegA | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 77 | #define nZifferOff (nSegA | nSegB | nSegC | nSegD | nSegE | nSegF | nSegG | nSegH) |
prof_al | 0:5ac32d240694 | 78 | |
prof_al | 0:5ac32d240694 | 79 | byte bIdx; /* |
prof_al | 0:5ac32d240694 | 80 | * Description : Index auf Ausgabe |
prof_al | 0:5ac32d240694 | 81 | */ |
prof_al | 0:5ac32d240694 | 82 | |
prof_al | 0:5ac32d240694 | 83 | byte bDigit; /* |
prof_al | 0:5ac32d240694 | 84 | * Description : aktives Digit |
prof_al | 0:5ac32d240694 | 85 | */ |
prof_al | 0:5ac32d240694 | 86 | |
prof_al | 0:5ac32d240694 | 87 | byte bBargraph; /* |
prof_al | 0:5ac32d240694 | 88 | * Description : Bargraph durchschalten |
prof_al | 0:5ac32d240694 | 89 | */ |
prof_al | 0:5ac32d240694 | 90 | |
prof_al | 0:5ac32d240694 | 91 | byte bS1Timer; /* |
prof_al | 0:5ac32d240694 | 92 | * Description : Timer für Taste S1 |
prof_al | 0:5ac32d240694 | 93 | */ |
prof_al | 0:5ac32d240694 | 94 | |
prof_al | 0:5ac32d240694 | 95 | byte bS2Timer; /* |
prof_al | 0:5ac32d240694 | 96 | * Description : Timer für Taste S2 |
prof_al | 0:5ac32d240694 | 97 | */ |
prof_al | 0:5ac32d240694 | 98 | |
prof_al | 0:5ac32d240694 | 99 | byte bS3Timer; /* |
prof_al | 0:5ac32d240694 | 100 | * Description : Timer für Taste S3 |
prof_al | 0:5ac32d240694 | 101 | */ |
prof_al | 0:5ac32d240694 | 102 | |
alexander0707 | 14:88379565eac6 | 103 | byte bSCounter; /* |
alexander0707 | 14:88379565eac6 | 104 | * Description : Zähler UART-Auslese für Tasterersatz |
alexander0707 | 14:88379565eac6 | 105 | */ |
alexander0707 | 14:88379565eac6 | 106 | |
alexander0707 | 5:5c9b508670cf | 107 | byte bDisplayState; /* |
alexander0707 | 5:5c9b508670cf | 108 | * Description : |
alexander0707 | 5:5c9b508670cf | 109 | */ |
alexander0707 | 5:5c9b508670cf | 110 | const byte enSchwellenwert=0x00; |
alexander0707 | 5:5c9b508670cf | 111 | const byte enPotiAnzeige = 0x01; |
alexander0707 | 5:5c9b508670cf | 112 | const byte enVergleich = 0x02; |
alexander0707 | 5:5c9b508670cf | 113 | |
alexander0707 | 5:5c9b508670cf | 114 | |
alexander0707 | 5:5c9b508670cf | 115 | byte bState; /* |
alexander0707 | 5:5c9b508670cf | 116 | * Description : |
alexander0707 | 5:5c9b508670cf | 117 | */ |
alexander0707 | 5:5c9b508670cf | 118 | |
alexander0707 | 5:5c9b508670cf | 119 | byte bHotKey; /* |
alexander0707 | 5:5c9b508670cf | 120 | * Description : Auswahl der Taste |
alexander0707 | 5:5c9b508670cf | 121 | */ |
alexander0707 | 5:5c9b508670cf | 122 | |
alexander0707 | 5:5c9b508670cf | 123 | byte bDisplayDot; /* |
alexander0707 | 5:5c9b508670cf | 124 | * Description : |
alexander0707 | 5:5c9b508670cf | 125 | */ |
alexander0707 | 5:5c9b508670cf | 126 | |
alexander0707 | 5:5c9b508670cf | 127 | byte bMainState; /* |
alexander0707 | 5:5c9b508670cf | 128 | * Description : Hauptzustand |
alexander0707 | 5:5c9b508670cf | 129 | */ |
alexander0707 | 5:5c9b508670cf | 130 | |
alexander0707 | 5:5c9b508670cf | 131 | byte bBeepTime; /* |
alexander0707 | 5:5c9b508670cf | 132 | * Description : Tondauer |
alexander0707 | 5:5c9b508670cf | 133 | */ |
alexander0707 | 5:5c9b508670cf | 134 | |
alexander0707 | 5:5c9b508670cf | 135 | byte bEinstellungsModus;/* |
alexander0707 | 5:5c9b508670cf | 136 | * Description : Einstellungszustand |
alexander0707 | 5:5c9b508670cf | 137 | */ |
alexander0707 | 5:5c9b508670cf | 138 | |
alexander0707 | 5:5c9b508670cf | 139 | byte bSchwellenwertVergleich;/* |
alexander0707 | 5:5c9b508670cf | 140 | * Description : Einstellungszustand |
alexander0707 | 5:5c9b508670cf | 141 | */ |
alexander0707 | 5:5c9b508670cf | 142 | |
alexander0707 | 6:4e55101c65f4 | 143 | byte bTimeLong;/* |
alexander0707 | 6:4e55101c65f4 | 144 | * Description : Ob Taste bereits lange gedrückt war |
alexander0707 | 6:4e55101c65f4 | 145 | */ |
alexander0707 | 6:4e55101c65f4 | 146 | |
alexander0707 | 13:b1d6b2285b13 | 147 | byte bSizeData;/* |
alexander0707 | 13:b1d6b2285b13 | 148 | * Description : Größe der Daten |
alexander0707 | 13:b1d6b2285b13 | 149 | */ |
alexander0707 | 13:b1d6b2285b13 | 150 | byte *pUartData; /* |
alexander0707 | 13:b1d6b2285b13 | 151 | * Description : pointer to data |
alexander0707 | 13:b1d6b2285b13 | 152 | */ |
alexander0707 | 13:b1d6b2285b13 | 153 | |
alexander0707 | 5:5c9b508670cf | 154 | |
prof_al | 0:5ac32d240694 | 155 | word wSerial; /* |
prof_al | 0:5ac32d240694 | 156 | * Description : serielles Ausgaberegister |
prof_al | 0:5ac32d240694 | 157 | */ |
prof_al | 0:5ac32d240694 | 158 | |
alexander0707 | 5:5c9b508670cf | 159 | word wClockTime; /* |
alexander0707 | 5:5c9b508670cf | 160 | *Description : Timer für verstrichene Zeit |
alexander0707 | 5:5c9b508670cf | 161 | */ |
alexander0707 | 5:5c9b508670cf | 162 | |
alexander0707 | 5:5c9b508670cf | 163 | word wClockShow; /* |
alexander0707 | 5:5c9b508670cf | 164 | *Description : Timer für verstrichene Zeit |
alexander0707 | 5:5c9b508670cf | 165 | */ |
alexander0707 | 5:5c9b508670cf | 166 | |
alexander0707 | 5:5c9b508670cf | 167 | word wDelayGame; /* |
alexander0707 | 5:5c9b508670cf | 168 | * Description : Verzögerungstimer |
alexander0707 | 5:5c9b508670cf | 169 | */ |
alexander0707 | 5:5c9b508670cf | 170 | |
alexander0707 | 5:5c9b508670cf | 171 | word wPotiWert; /* |
alexander0707 | 5:5c9b508670cf | 172 | * Description : Wert des Potis |
alexander0707 | 5:5c9b508670cf | 173 | */ |
alexander0707 | 5:5c9b508670cf | 174 | |
alexander0707 | 5:5c9b508670cf | 175 | word wVorgabeWert; /* |
alexander0707 | 14:88379565eac6 | 176 | * Description : eingestellter Vorgabewert |
alexander0707 | 5:5c9b508670cf | 177 | */ |
alexander0707 | 5:5c9b508670cf | 178 | |
alexander0707 | 10:fdd52c601fcc | 179 | int nDiffWert; /* |
alexander0707 | 6:4e55101c65f4 | 180 | * Description : Differenz zwischen Vorgabe und Eingang |
alexander0707 | 6:4e55101c65f4 | 181 | */ |
alexander0707 | 6:4e55101c65f4 | 182 | |
alexander0707 | 14:88379565eac6 | 183 | word wSizeData; /* |
alexander0707 | 14:88379565eac6 | 184 | * Description : Größe der empfangenen Daten |
alexander0707 | 14:88379565eac6 | 185 | */ |
alexander0707 | 14:88379565eac6 | 186 | |
alexander0707 | 19:8fdd91276de8 | 187 | word wTimerDot; /* |
alexander0707 | 19:8fdd91276de8 | 188 | * Description : Zähler für Dots |
alexander0707 | 19:8fdd91276de8 | 189 | */ |
alexander0707 | 19:8fdd91276de8 | 190 | |
alexander0707 | 15:bbcf8c3f91c5 | 191 | int zaehler; |
alexander0707 | 14:88379565eac6 | 192 | |
prof_al | 0:5ac32d240694 | 193 | /* Bitmuster */ |
prof_al | 0:5ac32d240694 | 194 | const byte abZiffer[] = {nZiffer0, nZiffer1, nZiffer2, nZiffer3, nZiffer4, nZiffer5, nZiffer6, nZiffer7, nZiffer8, nZiffer9, nZifferA, nZifferB, nZifferC, nZifferD, nZifferE, nZifferF, nZifferOff}; |
alexander0707 | 12:bd1417475c5f | 195 | //const byte abBargraph[] = {~Bit0, ~(Bit0|Bit1), ~(Bit0|Bit1|Bit2), ~(Bit0|Bit1|Bit2|Bit3), 0x0f}; |
alexander0707 | 19:8fdd91276de8 | 196 | byte abTxBuffer[60]; |
alexander0707 | 19:8fdd91276de8 | 197 | byte abTxBufferOld[60]; |
alexander0707 | 13:b1d6b2285b13 | 198 | |
prof_al | 0:5ac32d240694 | 199 | |
prof_al | 0:5ac32d240694 | 200 | |
prof_al | 0:5ac32d240694 | 201 | void vShiftLoad(word wLoad){ |
prof_al | 0:5ac32d240694 | 202 | word wMask = Bit15; |
prof_al | 0:5ac32d240694 | 203 | pinLoad = 0; |
prof_al | 0:5ac32d240694 | 204 | while(wMask){ |
prof_al | 0:5ac32d240694 | 205 | if(wMask & wLoad) pinSdo = 1; |
prof_al | 0:5ac32d240694 | 206 | else pinSdo = 0; |
prof_al | 0:5ac32d240694 | 207 | pinSck = 1; |
prof_al | 0:5ac32d240694 | 208 | wMask >>= 1; |
prof_al | 0:5ac32d240694 | 209 | pinSck = 0; |
prof_al | 0:5ac32d240694 | 210 | } |
prof_al | 0:5ac32d240694 | 211 | pinLoad = 1; |
prof_al | 0:5ac32d240694 | 212 | } |
prof_al | 0:5ac32d240694 | 213 | |
alexander0707 | 5:5c9b508670cf | 214 | |
alexander0707 | 5:5c9b508670cf | 215 | byte abDisplayMemory[] = {16,16,16,16}; /* alle Segmente aus */ |
alexander0707 | 5:5c9b508670cf | 216 | |
alexander0707 | 6:4e55101c65f4 | 217 | void vDisplayVolt( word w ) |
alexander0707 | 5:5c9b508670cf | 218 | { |
alexander0707 | 5:5c9b508670cf | 219 | int16 v; |
alexander0707 | 5:5c9b508670cf | 220 | abDisplayMemory[0] = 16; /* Aus */ |
alexander0707 | 8:6f91c39dbabc | 221 | v = (byte)(w / 1000); |
alexander0707 | 8:6f91c39dbabc | 222 | abDisplayMemory[1] = v; /* Hunderter */ |
alexander0707 | 8:6f91c39dbabc | 223 | w = w - (v * 1000); |
alexander0707 | 5:5c9b508670cf | 224 | v = (byte)(w / 100); |
alexander0707 | 8:6f91c39dbabc | 225 | abDisplayMemory[2] = v; /* Zehner */ |
alexander0707 | 5:5c9b508670cf | 226 | w = w - (v * 100); |
alexander0707 | 5:5c9b508670cf | 227 | v = (byte)(w / 10); |
alexander0707 | 8:6f91c39dbabc | 228 | abDisplayMemory[3] = v; /* Einer */ |
alexander0707 | 5:5c9b508670cf | 229 | } |
alexander0707 | 6:4e55101c65f4 | 230 | |
alexander0707 | 6:4e55101c65f4 | 231 | void vDisplayDiff( word w ) |
alexander0707 | 5:5c9b508670cf | 232 | { |
alexander0707 | 6:4e55101c65f4 | 233 | int16 v; |
alexander0707 | 6:4e55101c65f4 | 234 | abDisplayMemory[0] = 12; /* "C" */ |
alexander0707 | 8:6f91c39dbabc | 235 | v = (byte)(w / 1000); |
alexander0707 | 8:6f91c39dbabc | 236 | abDisplayMemory[1] = v; /* Hunderter */ |
alexander0707 | 8:6f91c39dbabc | 237 | w = w - (v * 1000); |
alexander0707 | 6:4e55101c65f4 | 238 | v = (byte)(w / 100); |
alexander0707 | 8:6f91c39dbabc | 239 | abDisplayMemory[2] = v; /* Zehner */ |
alexander0707 | 6:4e55101c65f4 | 240 | w = w - (v * 100); |
alexander0707 | 6:4e55101c65f4 | 241 | v = (byte)(w / 10); |
alexander0707 | 8:6f91c39dbabc | 242 | abDisplayMemory[3] = v; /* Einer */ |
alexander0707 | 6:4e55101c65f4 | 243 | } |
alexander0707 | 6:4e55101c65f4 | 244 | |
alexander0707 | 6:4e55101c65f4 | 245 | void vSetForStart( void ) |
alexander0707 | 6:4e55101c65f4 | 246 | { |
alexander0707 | 6:4e55101c65f4 | 247 | abDisplayMemory[0] = 16; /* 7-Segment-Display ausschalten */ |
alexander0707 | 5:5c9b508670cf | 248 | abDisplayMemory[1] = 16; |
alexander0707 | 5:5c9b508670cf | 249 | abDisplayMemory[2] = 16; |
alexander0707 | 5:5c9b508670cf | 250 | abDisplayMemory[3] = 16; |
alexander0707 | 19:8fdd91276de8 | 251 | wTimerDot = 0; |
alexander0707 | 5:5c9b508670cf | 252 | bDigit = 0; |
alexander0707 | 6:4e55101c65f4 | 253 | bMainState = enSchwellenwert; |
alexander0707 | 6:4e55101c65f4 | 254 | bDisplayState = enSchwellenwert; |
alexander0707 | 6:4e55101c65f4 | 255 | pinBeep = 1; |
alexander0707 | 6:4e55101c65f4 | 256 | wVorgabeWert = 0; |
alexander0707 | 5:5c9b508670cf | 257 | } |
alexander0707 | 14:88379565eac6 | 258 | |
alexander0707 | 5:5c9b508670cf | 259 | /* Tastenabfrage */ |
alexander0707 | 5:5c9b508670cf | 260 | void vTasteS1( void ){ |
alexander0707 | 16:404bcdd9c518 | 261 | if(pinS1 == 0){ /* User-Taste gedrückt */ |
alexander0707 | 16:404bcdd9c518 | 262 | if(bS1Timer < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */ |
alexander0707 | 5:5c9b508670cf | 263 | if(bS1Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */ |
alexander0707 | 5:5c9b508670cf | 264 | //... |
alexander0707 | 5:5c9b508670cf | 265 | } |
alexander0707 | 16:404bcdd9c518 | 266 | if(bS1Timer == nTastLong){ /* Taste "lange gedrückt" erkannt */ |
alexander0707 | 16:404bcdd9c518 | 267 | if(bDisplayState == enSchwellenwert){ |
alexander0707 | 6:4e55101c65f4 | 268 | bDisplayState = enVergleich; |
alexander0707 | 6:4e55101c65f4 | 269 | bMainState = enVergleich; |
alexander0707 | 6:4e55101c65f4 | 270 | } |
alexander0707 | 6:4e55101c65f4 | 271 | else{ |
alexander0707 | 6:4e55101c65f4 | 272 | bDisplayState = enSchwellenwert; |
alexander0707 | 6:4e55101c65f4 | 273 | bMainState = enSchwellenwert; |
alexander0707 | 6:4e55101c65f4 | 274 | } |
alexander0707 | 6:4e55101c65f4 | 275 | } |
alexander0707 | 6:4e55101c65f4 | 276 | bS1Timer++; |
alexander0707 | 6:4e55101c65f4 | 277 | } |
alexander0707 | 6:4e55101c65f4 | 278 | } |
alexander0707 | 6:4e55101c65f4 | 279 | else{ /* Taste nicht gedrückt */ |
alexander0707 | 16:404bcdd9c518 | 280 | if(((bS1Timer >= nTastShort) && (bS1Timer <= nTastLong))){ /* Taste wurde bereits erkannt */ |
alexander0707 | 7:94c73e4168d8 | 281 | if(bDisplayState == enSchwellenwert){ |
alexander0707 | 5:5c9b508670cf | 282 | bDisplayState = enPotiAnzeige; |
alexander0707 | 5:5c9b508670cf | 283 | bMainState = enPotiAnzeige; |
alexander0707 | 5:5c9b508670cf | 284 | } |
alexander0707 | 5:5c9b508670cf | 285 | else{ |
alexander0707 | 5:5c9b508670cf | 286 | bDisplayState = enSchwellenwert; |
alexander0707 | 5:5c9b508670cf | 287 | bMainState= enSchwellenwert; |
alexander0707 | 5:5c9b508670cf | 288 | } |
alexander0707 | 5:5c9b508670cf | 289 | } |
alexander0707 | 5:5c9b508670cf | 290 | bS1Timer = 0; |
alexander0707 | 5:5c9b508670cf | 291 | } |
alexander0707 | 5:5c9b508670cf | 292 | } |
alexander0707 | 5:5c9b508670cf | 293 | |
alexander0707 | 5:5c9b508670cf | 294 | void vTasteS2( void ){ |
alexander0707 | 17:c34f14ec2beb | 295 | if((pinS2 == 0) && bMainState == enSchwellenwert){ /* User-Taste gedrückt */ |
alexander0707 | 17:c34f14ec2beb | 296 | if(bS2Timer < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */ |
alexander0707 | 5:5c9b508670cf | 297 | if(bS2Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */ |
alexander0707 | 5:5c9b508670cf | 298 | //... |
alexander0707 | 5:5c9b508670cf | 299 | } |
alexander0707 | 17:c34f14ec2beb | 300 | if(bS2Timer == nTastLong){ /* Taste "lange gedrückt" erkannt */ |
alexander0707 | 6:4e55101c65f4 | 301 | bTimeLong = 1; |
alexander0707 | 10:fdd52c601fcc | 302 | if(wVorgabeWert >=3200) wVorgabeWert = 3300; |
alexander0707 | 10:fdd52c601fcc | 303 | else wVorgabeWert = wVorgabeWert + 100; |
alexander0707 | 9:b30caa6d008f | 304 | bS2Timer = bS2Timer - 40; |
alexander0707 | 5:5c9b508670cf | 305 | } |
alexander0707 | 5:5c9b508670cf | 306 | bS2Timer++; |
alexander0707 | 5:5c9b508670cf | 307 | } |
alexander0707 | 5:5c9b508670cf | 308 | } |
alexander0707 | 5:5c9b508670cf | 309 | else{ /* Taste nicht gedrückt */ |
alexander0707 | 17:c34f14ec2beb | 310 | if(((bS2Timer >= nTastShort) && (bS2Timer <= nTastLong))){ /* Taste wurde bereits erkannt */ |
alexander0707 | 10:fdd52c601fcc | 311 | if(bTimeLong==0){ |
alexander0707 | 10:fdd52c601fcc | 312 | if(wVorgabeWert >=3290) wVorgabeWert = 3300; |
alexander0707 | 10:fdd52c601fcc | 313 | else wVorgabeWert = wVorgabeWert + 10; |
alexander0707 | 10:fdd52c601fcc | 314 | } |
alexander0707 | 5:5c9b508670cf | 315 | } |
alexander0707 | 5:5c9b508670cf | 316 | bS2Timer = 0; |
alexander0707 | 14:88379565eac6 | 317 | bTimeLong = 0; |
alexander0707 | 17:c34f14ec2beb | 318 | } |
alexander0707 | 5:5c9b508670cf | 319 | } |
alexander0707 | 5:5c9b508670cf | 320 | |
alexander0707 | 5:5c9b508670cf | 321 | void vTasteS3( void ){ |
alexander0707 | 17:c34f14ec2beb | 322 | if(pinS3 == 0 && bMainState == enSchwellenwert){ /* User-Taste gedrückt */ |
alexander0707 | 17:c34f14ec2beb | 323 | if(bS3Timer < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */ |
alexander0707 | 5:5c9b508670cf | 324 | if(bS3Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */ |
alexander0707 | 5:5c9b508670cf | 325 | //... |
alexander0707 | 5:5c9b508670cf | 326 | } |
alexander0707 | 17:c34f14ec2beb | 327 | if(bS3Timer == nTastLong){ /* Taste "lange gedrückt" erkannt */ |
alexander0707 | 6:4e55101c65f4 | 328 | bTimeLong = 1; |
alexander0707 | 10:fdd52c601fcc | 329 | if(wVorgabeWert <=100) wVorgabeWert = 0; |
alexander0707 | 10:fdd52c601fcc | 330 | else wVorgabeWert = wVorgabeWert - 100; |
alexander0707 | 12:bd1417475c5f | 331 | bS3Timer = bS3Timer - 40; |
alexander0707 | 5:5c9b508670cf | 332 | } |
alexander0707 | 5:5c9b508670cf | 333 | bS3Timer++; |
alexander0707 | 5:5c9b508670cf | 334 | } |
alexander0707 | 5:5c9b508670cf | 335 | } |
alexander0707 | 5:5c9b508670cf | 336 | else{ /* Taste nicht gedrückt */ |
alexander0707 | 17:c34f14ec2beb | 337 | if((bS3Timer >= nTastShort) && (bS3Timer <= nTastLong)){ /* Taste wurde bereits erkannt */ |
alexander0707 | 10:fdd52c601fcc | 338 | if(bTimeLong==0){ |
alexander0707 | 10:fdd52c601fcc | 339 | if(wVorgabeWert <=10) wVorgabeWert = 0; |
alexander0707 | 10:fdd52c601fcc | 340 | else wVorgabeWert = wVorgabeWert - 10; |
alexander0707 | 10:fdd52c601fcc | 341 | } |
alexander0707 | 5:5c9b508670cf | 342 | } |
alexander0707 | 5:5c9b508670cf | 343 | bS3Timer = 0; |
alexander0707 | 14:88379565eac6 | 344 | bTimeLong = 0; |
alexander0707 | 17:c34f14ec2beb | 345 | } |
alexander0707 | 5:5c9b508670cf | 346 | } |
alexander0707 | 5:5c9b508670cf | 347 | |
alexander0707 | 5:5c9b508670cf | 348 | |
alexander0707 | 5:5c9b508670cf | 349 | |
alexander0707 | 5:5c9b508670cf | 350 | void vCheckTasten( void ){ |
alexander0707 | 5:5c9b508670cf | 351 | vTasteS1(); |
alexander0707 | 5:5c9b508670cf | 352 | vTasteS2(); |
alexander0707 | 5:5c9b508670cf | 353 | vTasteS3(); |
alexander0707 | 5:5c9b508670cf | 354 | } |
alexander0707 | 5:5c9b508670cf | 355 | void vSegmentDigit( void ) //wichtig!! |
alexander0707 | 5:5c9b508670cf | 356 | { |
alexander0707 | 5:5c9b508670cf | 357 | bDigit++; |
alexander0707 | 5:5c9b508670cf | 358 | wSerial = abZiffer[abDisplayMemory[bDigit&0x03]]; |
alexander0707 | 5:5c9b508670cf | 359 | switch(bDisplayState) { |
alexander0707 | 5:5c9b508670cf | 360 | case enSchwellenwert: |
alexander0707 | 19:8fdd91276de8 | 361 | wTimerDot++; /* Zähler für Punktwechsel */ |
alexander0707 | 6:4e55101c65f4 | 362 | vDisplayVolt(wVorgabeWert); |
alexander0707 | 19:8fdd91276de8 | 363 | if(wTimerDot == 400) { |
alexander0707 | 19:8fdd91276de8 | 364 | wDelayGame=200; |
alexander0707 | 19:8fdd91276de8 | 365 | wTimerDot = 0; |
alexander0707 | 18:6f0897438c03 | 366 | } |
alexander0707 | 18:6f0897438c03 | 367 | if(wDelayGame!=0){ |
alexander0707 | 7:94c73e4168d8 | 368 | if((bDigit&0x03) == 0x01) { |
alexander0707 | 7:94c73e4168d8 | 369 | wSerial = wSerial & ~nSegH; /* Punktanzeigen */ |
alexander0707 | 18:6f0897438c03 | 370 | } |
alexander0707 | 18:6f0897438c03 | 371 | wDelayGame--; |
alexander0707 | 5:5c9b508670cf | 372 | } |
alexander0707 | 5:5c9b508670cf | 373 | break; |
alexander0707 | 5:5c9b508670cf | 374 | case enPotiAnzeige: |
alexander0707 | 6:4e55101c65f4 | 375 | vDisplayVolt(wPotiWert); |
alexander0707 | 5:5c9b508670cf | 376 | if((bDigit&0x03) == 0x01) { /* Dezimalpunkt setzen */ |
alexander0707 | 5:5c9b508670cf | 377 | wSerial = wSerial & ~nSegH; |
alexander0707 | 5:5c9b508670cf | 378 | } |
alexander0707 | 5:5c9b508670cf | 379 | break; |
alexander0707 | 5:5c9b508670cf | 380 | case enVergleich: |
alexander0707 | 10:fdd52c601fcc | 381 | vDisplayDiff(nDiffWert); |
alexander0707 | 5:5c9b508670cf | 382 | if((bDigit&0x03) == 0x01) { /* Dezimalpunkt setzen */ |
alexander0707 | 5:5c9b508670cf | 383 | wSerial = wSerial & ~nSegH; |
alexander0707 | 5:5c9b508670cf | 384 | } |
alexander0707 | 5:5c9b508670cf | 385 | break; |
alexander0707 | 5:5c9b508670cf | 386 | } |
alexander0707 | 5:5c9b508670cf | 387 | vShiftLoad(((wSerial << 8) & 0xfff0)| (1 << (bDigit&0x03))); |
alexander0707 | 5:5c9b508670cf | 388 | } |
alexander0707 | 5:5c9b508670cf | 389 | |
alexander0707 | 13:b1d6b2285b13 | 390 | |
alexander0707 | 13:b1d6b2285b13 | 391 | |
alexander0707 | 13:b1d6b2285b13 | 392 | |
alexander0707 | 13:b1d6b2285b13 | 393 | |
alexander0707 | 13:b1d6b2285b13 | 394 | |
alexander0707 | 13:b1d6b2285b13 | 395 | |
alexander0707 | 13:b1d6b2285b13 | 396 | |
alexander0707 | 13:b1d6b2285b13 | 397 | |
alexander0707 | 13:b1d6b2285b13 | 398 | |
alexander0707 | 19:8fdd91276de8 | 399 | Serial stComX(D1,D0); // UART-Kommunikation (Txd(D1)/Rxd(D0)) mit dem PC |
alexander0707 | 13:b1d6b2285b13 | 400 | |
alexander0707 | 19:8fdd91276de8 | 401 | |
alexander0707 | 19:8fdd91276de8 | 402 | byte SYS_vStartComX( word wSize, byte *pData ){ // Start einer Übertragung |
alexander0707 | 14:88379565eac6 | 403 | byte i; |
alexander0707 | 14:88379565eac6 | 404 | if(wSizeData) i = False; |
alexander0707 | 14:88379565eac6 | 405 | else{ |
alexander0707 | 19:8fdd91276de8 | 406 | wSizeData = wSize; // Anzahl der Sendedaten |
alexander0707 | 19:8fdd91276de8 | 407 | pUartData = pData; // Zeiger auf diese Daten |
alexander0707 | 19:8fdd91276de8 | 408 | stComX.putc(*pUartData); // erstes Zeichen senden |
alexander0707 | 14:88379565eac6 | 409 | pUartData++; |
alexander0707 | 14:88379565eac6 | 410 | wSizeData--; |
alexander0707 | 19:8fdd91276de8 | 411 | USART2->CR1 |= USART_CR1_TXEIE; // TXE-Interrupt freigeben |
alexander0707 | 14:88379565eac6 | 412 | i = True; |
alexander0707 | 14:88379565eac6 | 413 | } |
alexander0707 | 14:88379565eac6 | 414 | return i; |
alexander0707 | 14:88379565eac6 | 415 | } |
alexander0707 | 13:b1d6b2285b13 | 416 | |
alexander0707 | 13:b1d6b2285b13 | 417 | |
alexander0707 | 19:8fdd91276de8 | 418 | // Senderoutine zum COM-Port am PC |
alexander0707 | 19:8fdd91276de8 | 419 | void vIsrTxComX( void ){ // Senderoutine |
alexander0707 | 19:8fdd91276de8 | 420 | if(stComX.writeable()){ // Sende-ISR |
alexander0707 | 19:8fdd91276de8 | 421 | if(bSizeData){ // sind Daten vorhanden ? |
alexander0707 | 19:8fdd91276de8 | 422 | stComX.putc(*pUartData); // daten senden |
alexander0707 | 14:88379565eac6 | 423 | pUartData++; |
alexander0707 | 14:88379565eac6 | 424 | bSizeData--; |
alexander0707 | 14:88379565eac6 | 425 | } |
alexander0707 | 14:88379565eac6 | 426 | else{ |
alexander0707 | 19:8fdd91276de8 | 427 | USART2->CR1 &= ~USART_CR1_TXEIE; // Interrupt sperren |
alexander0707 | 14:88379565eac6 | 428 | } |
alexander0707 | 14:88379565eac6 | 429 | } |
alexander0707 | 14:88379565eac6 | 430 | } |
alexander0707 | 14:88379565eac6 | 431 | |
alexander0707 | 14:88379565eac6 | 432 | |
alexander0707 | 19:8fdd91276de8 | 433 | // Empfangsroutine vom COM-Port des PC |
alexander0707 | 19:8fdd91276de8 | 434 | void vIsrRxComX( void ){ // Empfangsroutine |
alexander0707 | 19:8fdd91276de8 | 435 | if(stComX.readable()){ // Empfangs-ISR |
alexander0707 | 14:88379565eac6 | 436 | abTxBuffer[0] = stComX.getc(); |
alexander0707 | 14:88379565eac6 | 437 | SYS_vStartComX(1, &abTxBuffer[0]); |
alexander0707 | 14:88379565eac6 | 438 | } |
alexander0707 | 14:88379565eac6 | 439 | } |
alexander0707 | 14:88379565eac6 | 440 | |
alexander0707 | 13:b1d6b2285b13 | 441 | |
alexander0707 | 13:b1d6b2285b13 | 442 | |
alexander0707 | 13:b1d6b2285b13 | 443 | |
alexander0707 | 19:8fdd91276de8 | 444 | void vComA(void){ |
alexander0707 | 19:8fdd91276de8 | 445 | if(abTxBuffer[0]=='a'){ |
alexander0707 | 19:8fdd91276de8 | 446 | if(bMainState==enSchwellenwert) { |
alexander0707 | 19:8fdd91276de8 | 447 | bDisplayState = enPotiAnzeige; |
alexander0707 | 19:8fdd91276de8 | 448 | bMainState = enPotiAnzeige; |
alexander0707 | 19:8fdd91276de8 | 449 | } |
alexander0707 | 19:8fdd91276de8 | 450 | if(bMainState==enPotiAnzeige) { |
alexander0707 | 19:8fdd91276de8 | 451 | bDisplayState = enVergleich; |
alexander0707 | 19:8fdd91276de8 | 452 | bMainState = enVergleich; |
alexander0707 | 19:8fdd91276de8 | 453 | } |
alexander0707 | 19:8fdd91276de8 | 454 | if(bMainState==enVergleich) { |
alexander0707 | 19:8fdd91276de8 | 455 | bDisplayState = enSchwellenwert; |
alexander0707 | 19:8fdd91276de8 | 456 | bMainState = enSchwellenwert; |
alexander0707 | 19:8fdd91276de8 | 457 | } |
alexander0707 | 19:8fdd91276de8 | 458 | } |
alexander0707 | 19:8fdd91276de8 | 459 | } |
alexander0707 | 13:b1d6b2285b13 | 460 | |
alexander0707 | 19:8fdd91276de8 | 461 | void vComPlus(void){ |
alexander0707 | 19:8fdd91276de8 | 462 | if(abTxBuffer[0]=='+'){ |
alexander0707 | 19:8fdd91276de8 | 463 | if(wVorgabeWert >=3290) wVorgabeWert = 3300; |
alexander0707 | 19:8fdd91276de8 | 464 | else wVorgabeWert = wVorgabeWert + 10; |
alexander0707 | 19:8fdd91276de8 | 465 | } |
alexander0707 | 19:8fdd91276de8 | 466 | } |
alexander0707 | 19:8fdd91276de8 | 467 | |
alexander0707 | 19:8fdd91276de8 | 468 | void vComMinus(void){ |
alexander0707 | 19:8fdd91276de8 | 469 | if(abTxBuffer[0]=='-'){ |
alexander0707 | 19:8fdd91276de8 | 470 | if(wVorgabeWert <=10) wVorgabeWert = 0; |
alexander0707 | 19:8fdd91276de8 | 471 | else wVorgabeWert = wVorgabeWert - 10;; |
alexander0707 | 19:8fdd91276de8 | 472 | } |
alexander0707 | 19:8fdd91276de8 | 473 | } |
alexander0707 | 19:8fdd91276de8 | 474 | |
alexander0707 | 19:8fdd91276de8 | 475 | void vCheckCom(void){ |
alexander0707 | 19:8fdd91276de8 | 476 | vComA(); |
alexander0707 | 19:8fdd91276de8 | 477 | vComPlus(); |
alexander0707 | 19:8fdd91276de8 | 478 | vComMinus(); |
alexander0707 | 19:8fdd91276de8 | 479 | } |
alexander0707 | 13:b1d6b2285b13 | 480 | |
alexander0707 | 13:b1d6b2285b13 | 481 | |
alexander0707 | 13:b1d6b2285b13 | 482 | |
alexander0707 | 13:b1d6b2285b13 | 483 | |
prof_al | 0:5ac32d240694 | 484 | /*************************************************************************** |
prof_al | 0:5ac32d240694 | 485 | * main() |
prof_al | 0:5ac32d240694 | 486 | ***************************************************************************/ |
prof_al | 0:5ac32d240694 | 487 | int main() { |
prof_al | 0:5ac32d240694 | 488 | /* Variablen initialisieren */ |
alexander0707 | 6:4e55101c65f4 | 489 | vSetForStart(); |
alexander0707 | 13:b1d6b2285b13 | 490 | |
alexander0707 | 13:b1d6b2285b13 | 491 | |
alexander0707 | 14:88379565eac6 | 492 | //Seriel.begin(9600); |
alexander0707 | 5:5c9b508670cf | 493 | |
alexander0707 | 14:88379565eac6 | 494 | |
alexander0707 | 6:4e55101c65f4 | 495 | while(1) { |
alexander0707 | 10:fdd52c601fcc | 496 | wPotiWert = pinPoti*3300; |
alexander0707 | 6:4e55101c65f4 | 497 | vCheckTasten(); |
alexander0707 | 10:fdd52c601fcc | 498 | nDiffWert = wVorgabeWert - wPotiWert; |
alexander0707 | 14:88379565eac6 | 499 | |
alexander0707 | 14:88379565eac6 | 500 | |
alexander0707 | 14:88379565eac6 | 501 | stComX.attach(&vIsrRxComX, Serial::RxIrq); /* ISR zum Datemempfang vom PC */ |
alexander0707 | 14:88379565eac6 | 502 | stComX.attach(&vIsrTxComX, Serial::TxIrq); /* Sende-ISR */ |
alexander0707 | 19:8fdd91276de8 | 503 | |
alexander0707 | 19:8fdd91276de8 | 504 | vCheckCom(); |
alexander0707 | 14:88379565eac6 | 505 | |
alexander0707 | 14:88379565eac6 | 506 | |
alexander0707 | 5:5c9b508670cf | 507 | switch(bMainState) { |
alexander0707 | 6:4e55101c65f4 | 508 | case enSchwellenwert: |
alexander0707 | 12:bd1417475c5f | 509 | pinBeep = 1; |
alexander0707 | 5:5c9b508670cf | 510 | break; |
alexander0707 | 6:4e55101c65f4 | 511 | case enPotiAnzeige: |
alexander0707 | 12:bd1417475c5f | 512 | pinBeep = 1; |
alexander0707 | 5:5c9b508670cf | 513 | break; |
alexander0707 | 6:4e55101c65f4 | 514 | case enVergleich: |
alexander0707 | 10:fdd52c601fcc | 515 | if(nDiffWert<0) pinBeep=0; |
alexander0707 | 6:4e55101c65f4 | 516 | else pinBeep=1; |
alexander0707 | 5:5c9b508670cf | 517 | break; |
prof_al | 0:5ac32d240694 | 518 | } |
alexander0707 | 5:5c9b508670cf | 519 | vSegmentDigit(); |
alexander0707 | 6:4e55101c65f4 | 520 | wait_us(nCircleTime); |
prof_al | 0:5ac32d240694 | 521 | } |
alexander0707 | 5:5c9b508670cf | 522 | } |