Auf den letzten Metern
Dependencies: mbed
main.cpp@15:bbcf8c3f91c5, 23 months ago (annotated)
- Committer:
- alexander0707
- Date:
- Mon Dec 05 09:05:43 2022 +0000
- Revision:
- 15:bbcf8c3f91c5
- Parent:
- 14:88379565eac6
- Child:
- 16:404bcdd9c518
v2.1 Anpassungen
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 bTimerDot; /* |
alexander0707 | 5:5c9b508670cf | 120 | * Description : Zähler für Dots |
alexander0707 | 5:5c9b508670cf | 121 | */ |
alexander0707 | 5:5c9b508670cf | 122 | |
alexander0707 | 5:5c9b508670cf | 123 | byte bHotKey; /* |
alexander0707 | 5:5c9b508670cf | 124 | * Description : Auswahl der Taste |
alexander0707 | 5:5c9b508670cf | 125 | */ |
alexander0707 | 5:5c9b508670cf | 126 | |
alexander0707 | 5:5c9b508670cf | 127 | byte bDisplayDot; /* |
alexander0707 | 5:5c9b508670cf | 128 | * Description : |
alexander0707 | 5:5c9b508670cf | 129 | */ |
alexander0707 | 5:5c9b508670cf | 130 | |
alexander0707 | 5:5c9b508670cf | 131 | byte bMainState; /* |
alexander0707 | 5:5c9b508670cf | 132 | * Description : Hauptzustand |
alexander0707 | 5:5c9b508670cf | 133 | */ |
alexander0707 | 5:5c9b508670cf | 134 | |
alexander0707 | 5:5c9b508670cf | 135 | byte bBeepTime; /* |
alexander0707 | 5:5c9b508670cf | 136 | * Description : Tondauer |
alexander0707 | 5:5c9b508670cf | 137 | */ |
alexander0707 | 5:5c9b508670cf | 138 | |
alexander0707 | 5:5c9b508670cf | 139 | byte bEinstellungsModus;/* |
alexander0707 | 5:5c9b508670cf | 140 | * Description : Einstellungszustand |
alexander0707 | 5:5c9b508670cf | 141 | */ |
alexander0707 | 5:5c9b508670cf | 142 | |
alexander0707 | 5:5c9b508670cf | 143 | byte bSchwellenwertVergleich;/* |
alexander0707 | 5:5c9b508670cf | 144 | * Description : Einstellungszustand |
alexander0707 | 5:5c9b508670cf | 145 | */ |
alexander0707 | 5:5c9b508670cf | 146 | |
alexander0707 | 6:4e55101c65f4 | 147 | byte bTimeLong;/* |
alexander0707 | 6:4e55101c65f4 | 148 | * Description : Ob Taste bereits lange gedrückt war |
alexander0707 | 6:4e55101c65f4 | 149 | */ |
alexander0707 | 6:4e55101c65f4 | 150 | |
alexander0707 | 13:b1d6b2285b13 | 151 | byte bSizeData;/* |
alexander0707 | 13:b1d6b2285b13 | 152 | * Description : Größe der Daten |
alexander0707 | 13:b1d6b2285b13 | 153 | */ |
alexander0707 | 13:b1d6b2285b13 | 154 | byte *pUartData; /* |
alexander0707 | 13:b1d6b2285b13 | 155 | * Description : pointer to data |
alexander0707 | 13:b1d6b2285b13 | 156 | */ |
alexander0707 | 13:b1d6b2285b13 | 157 | |
alexander0707 | 5:5c9b508670cf | 158 | |
prof_al | 0:5ac32d240694 | 159 | word wSerial; /* |
prof_al | 0:5ac32d240694 | 160 | * Description : serielles Ausgaberegister |
prof_al | 0:5ac32d240694 | 161 | */ |
prof_al | 0:5ac32d240694 | 162 | |
alexander0707 | 5:5c9b508670cf | 163 | word wClockTime; /* |
alexander0707 | 5:5c9b508670cf | 164 | *Description : Timer für verstrichene Zeit |
alexander0707 | 5:5c9b508670cf | 165 | */ |
alexander0707 | 5:5c9b508670cf | 166 | |
alexander0707 | 5:5c9b508670cf | 167 | word wClockShow; /* |
alexander0707 | 5:5c9b508670cf | 168 | *Description : Timer für verstrichene Zeit |
alexander0707 | 5:5c9b508670cf | 169 | */ |
alexander0707 | 5:5c9b508670cf | 170 | |
alexander0707 | 5:5c9b508670cf | 171 | word wDelayGame; /* |
alexander0707 | 5:5c9b508670cf | 172 | * Description : Verzögerungstimer |
alexander0707 | 5:5c9b508670cf | 173 | */ |
alexander0707 | 5:5c9b508670cf | 174 | |
alexander0707 | 5:5c9b508670cf | 175 | word wPotiWert; /* |
alexander0707 | 5:5c9b508670cf | 176 | * Description : Wert des Potis |
alexander0707 | 5:5c9b508670cf | 177 | */ |
alexander0707 | 5:5c9b508670cf | 178 | |
alexander0707 | 5:5c9b508670cf | 179 | word wVorgabeWert; /* |
alexander0707 | 14:88379565eac6 | 180 | * Description : eingestellter Vorgabewert |
alexander0707 | 5:5c9b508670cf | 181 | */ |
alexander0707 | 5:5c9b508670cf | 182 | |
alexander0707 | 10:fdd52c601fcc | 183 | int nDiffWert; /* |
alexander0707 | 6:4e55101c65f4 | 184 | * Description : Differenz zwischen Vorgabe und Eingang |
alexander0707 | 6:4e55101c65f4 | 185 | */ |
alexander0707 | 6:4e55101c65f4 | 186 | |
alexander0707 | 14:88379565eac6 | 187 | word wSizeData; /* |
alexander0707 | 14:88379565eac6 | 188 | * Description : Größe der empfangenen Daten |
alexander0707 | 14:88379565eac6 | 189 | */ |
alexander0707 | 14:88379565eac6 | 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 | 14:88379565eac6 | 196 | byte abTxBuffer[256]; |
alexander0707 | 13:b1d6b2285b13 | 197 | |
prof_al | 0:5ac32d240694 | 198 | |
prof_al | 0:5ac32d240694 | 199 | |
prof_al | 0:5ac32d240694 | 200 | void vShiftLoad(word wLoad){ |
prof_al | 0:5ac32d240694 | 201 | word wMask = Bit15; |
prof_al | 0:5ac32d240694 | 202 | pinLoad = 0; |
prof_al | 0:5ac32d240694 | 203 | while(wMask){ |
prof_al | 0:5ac32d240694 | 204 | if(wMask & wLoad) pinSdo = 1; |
prof_al | 0:5ac32d240694 | 205 | else pinSdo = 0; |
prof_al | 0:5ac32d240694 | 206 | pinSck = 1; |
prof_al | 0:5ac32d240694 | 207 | wMask >>= 1; |
prof_al | 0:5ac32d240694 | 208 | pinSck = 0; |
prof_al | 0:5ac32d240694 | 209 | } |
prof_al | 0:5ac32d240694 | 210 | pinLoad = 1; |
prof_al | 0:5ac32d240694 | 211 | } |
prof_al | 0:5ac32d240694 | 212 | |
alexander0707 | 5:5c9b508670cf | 213 | |
alexander0707 | 5:5c9b508670cf | 214 | byte abDisplayMemory[] = {16,16,16,16}; /* alle Segmente aus */ |
alexander0707 | 5:5c9b508670cf | 215 | |
alexander0707 | 6:4e55101c65f4 | 216 | void vDisplayVolt( word w ) |
alexander0707 | 5:5c9b508670cf | 217 | { |
alexander0707 | 5:5c9b508670cf | 218 | int16 v; |
alexander0707 | 5:5c9b508670cf | 219 | abDisplayMemory[0] = 16; /* Aus */ |
alexander0707 | 8:6f91c39dbabc | 220 | v = (byte)(w / 1000); |
alexander0707 | 8:6f91c39dbabc | 221 | abDisplayMemory[1] = v; /* Hunderter */ |
alexander0707 | 8:6f91c39dbabc | 222 | w = w - (v * 1000); |
alexander0707 | 5:5c9b508670cf | 223 | v = (byte)(w / 100); |
alexander0707 | 8:6f91c39dbabc | 224 | abDisplayMemory[2] = v; /* Zehner */ |
alexander0707 | 5:5c9b508670cf | 225 | w = w - (v * 100); |
alexander0707 | 5:5c9b508670cf | 226 | v = (byte)(w / 10); |
alexander0707 | 8:6f91c39dbabc | 227 | abDisplayMemory[3] = v; /* Einer */ |
alexander0707 | 5:5c9b508670cf | 228 | } |
alexander0707 | 6:4e55101c65f4 | 229 | |
alexander0707 | 6:4e55101c65f4 | 230 | void vDisplayDiff( word w ) |
alexander0707 | 5:5c9b508670cf | 231 | { |
alexander0707 | 6:4e55101c65f4 | 232 | int16 v; |
alexander0707 | 6:4e55101c65f4 | 233 | abDisplayMemory[0] = 12; /* "C" */ |
alexander0707 | 8:6f91c39dbabc | 234 | v = (byte)(w / 1000); |
alexander0707 | 8:6f91c39dbabc | 235 | abDisplayMemory[1] = v; /* Hunderter */ |
alexander0707 | 8:6f91c39dbabc | 236 | w = w - (v * 1000); |
alexander0707 | 6:4e55101c65f4 | 237 | v = (byte)(w / 100); |
alexander0707 | 8:6f91c39dbabc | 238 | abDisplayMemory[2] = v; /* Zehner */ |
alexander0707 | 6:4e55101c65f4 | 239 | w = w - (v * 100); |
alexander0707 | 6:4e55101c65f4 | 240 | v = (byte)(w / 10); |
alexander0707 | 8:6f91c39dbabc | 241 | abDisplayMemory[3] = v; /* Einer */ |
alexander0707 | 6:4e55101c65f4 | 242 | } |
alexander0707 | 6:4e55101c65f4 | 243 | |
alexander0707 | 6:4e55101c65f4 | 244 | void vSetForStart( void ) |
alexander0707 | 6:4e55101c65f4 | 245 | { |
alexander0707 | 6:4e55101c65f4 | 246 | abDisplayMemory[0] = 16; /* 7-Segment-Display ausschalten */ |
alexander0707 | 5:5c9b508670cf | 247 | abDisplayMemory[1] = 16; |
alexander0707 | 5:5c9b508670cf | 248 | abDisplayMemory[2] = 16; |
alexander0707 | 5:5c9b508670cf | 249 | abDisplayMemory[3] = 16; |
alexander0707 | 5:5c9b508670cf | 250 | bTimerDot = 0; |
alexander0707 | 5:5c9b508670cf | 251 | bDigit = 0; |
alexander0707 | 6:4e55101c65f4 | 252 | bMainState = enSchwellenwert; |
alexander0707 | 6:4e55101c65f4 | 253 | bDisplayState = enSchwellenwert; |
alexander0707 | 6:4e55101c65f4 | 254 | pinBeep = 1; |
alexander0707 | 6:4e55101c65f4 | 255 | wVorgabeWert = 0; |
alexander0707 | 5:5c9b508670cf | 256 | } |
alexander0707 | 14:88379565eac6 | 257 | |
alexander0707 | 5:5c9b508670cf | 258 | /* Tastenabfrage */ |
alexander0707 | 5:5c9b508670cf | 259 | void vTasteS1( void ){ |
alexander0707 | 14:88379565eac6 | 260 | if(pinS1 == 0 || abTxBuffer[0] == 'a'){ /* User-Taste gedrückt */ |
alexander0707 | 14:88379565eac6 | 261 | |
alexander0707 | 15:bbcf8c3f91c5 | 262 | do{ |
alexander0707 | 15:bbcf8c3f91c5 | 263 | for(zaehler=0; zaehler<=250; zaehler++){ /*Zaehlen der Tastatur-Eingabe*/ |
alexander0707 | 15:bbcf8c3f91c5 | 264 | if(abTxBuffer[zaehler] == 'a') bSCounter++; |
alexander0707 | 15:bbcf8c3f91c5 | 265 | } |
alexander0707 | 15:bbcf8c3f91c5 | 266 | } while(abTxBuffer[zaehler] == abTxBuffer[zaehler+1]); |
alexander0707 | 14:88379565eac6 | 267 | |
alexander0707 | 14:88379565eac6 | 268 | if(bS1Timer < nTastLong+1 || bSCounter < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */ |
alexander0707 | 5:5c9b508670cf | 269 | if(bS1Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */ |
alexander0707 | 5:5c9b508670cf | 270 | //... |
alexander0707 | 5:5c9b508670cf | 271 | } |
alexander0707 | 14:88379565eac6 | 272 | if(bS1Timer == nTastLong || bSCounter == nTastLong){ /* Taste "lange gedrückt" erkannt */ |
alexander0707 | 7:94c73e4168d8 | 273 | if(bDisplayState == enSchwellenwert || bDisplayState == enPotiAnzeige){ |
alexander0707 | 6:4e55101c65f4 | 274 | bDisplayState = enVergleich; |
alexander0707 | 6:4e55101c65f4 | 275 | bMainState = enVergleich; |
alexander0707 | 6:4e55101c65f4 | 276 | } |
alexander0707 | 6:4e55101c65f4 | 277 | else{ |
alexander0707 | 6:4e55101c65f4 | 278 | bDisplayState = enSchwellenwert; |
alexander0707 | 6:4e55101c65f4 | 279 | bMainState = enSchwellenwert; |
alexander0707 | 6:4e55101c65f4 | 280 | } |
alexander0707 | 6:4e55101c65f4 | 281 | } |
alexander0707 | 6:4e55101c65f4 | 282 | bS1Timer++; |
alexander0707 | 6:4e55101c65f4 | 283 | } |
alexander0707 | 6:4e55101c65f4 | 284 | } |
alexander0707 | 6:4e55101c65f4 | 285 | else{ /* Taste nicht gedrückt */ |
alexander0707 | 14:88379565eac6 | 286 | if(((bS1Timer >= nTastShort) && (bS1Timer <= nTastLong)) || ((bSCounter >= nTastShort) && (bSCounter <= nTastLong))){ /* Taste wurde bereits erkannt */ |
alexander0707 | 7:94c73e4168d8 | 287 | if(bDisplayState == enSchwellenwert){ |
alexander0707 | 5:5c9b508670cf | 288 | bDisplayState = enPotiAnzeige; |
alexander0707 | 5:5c9b508670cf | 289 | bMainState = enPotiAnzeige; |
alexander0707 | 5:5c9b508670cf | 290 | } |
alexander0707 | 5:5c9b508670cf | 291 | else{ |
alexander0707 | 5:5c9b508670cf | 292 | bDisplayState = enSchwellenwert; |
alexander0707 | 5:5c9b508670cf | 293 | bMainState= enSchwellenwert; |
alexander0707 | 5:5c9b508670cf | 294 | } |
alexander0707 | 5:5c9b508670cf | 295 | } |
alexander0707 | 5:5c9b508670cf | 296 | bS1Timer = 0; |
alexander0707 | 14:88379565eac6 | 297 | bSCounter = 0; |
alexander0707 | 5:5c9b508670cf | 298 | } |
alexander0707 | 5:5c9b508670cf | 299 | } |
alexander0707 | 5:5c9b508670cf | 300 | |
alexander0707 | 5:5c9b508670cf | 301 | void vTasteS2( void ){ |
alexander0707 | 14:88379565eac6 | 302 | if((pinS2 == 0 || abTxBuffer[0] == '+') && bMainState == enSchwellenwert){ /* User-Taste gedrückt */ |
alexander0707 | 14:88379565eac6 | 303 | |
alexander0707 | 15:bbcf8c3f91c5 | 304 | do{ |
alexander0707 | 15:bbcf8c3f91c5 | 305 | for(zaehler=0; zaehler<=250; zaehler++){ /*Zaehlen der Tastatur-Eingabe*/ |
alexander0707 | 15:bbcf8c3f91c5 | 306 | if(abTxBuffer[zaehler] == 'a') bSCounter++; |
alexander0707 | 15:bbcf8c3f91c5 | 307 | } |
alexander0707 | 15:bbcf8c3f91c5 | 308 | } while(abTxBuffer[zaehler] == abTxBuffer[zaehler+1]); |
alexander0707 | 14:88379565eac6 | 309 | |
alexander0707 | 14:88379565eac6 | 310 | if(bS2Timer < nTastLong+1 || bSCounter < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */ |
alexander0707 | 5:5c9b508670cf | 311 | if(bS2Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */ |
alexander0707 | 5:5c9b508670cf | 312 | //... |
alexander0707 | 5:5c9b508670cf | 313 | } |
alexander0707 | 14:88379565eac6 | 314 | if(bS2Timer == nTastLong || bSCounter == nTastLong){ /* Taste "lange gedrückt" erkannt */ |
alexander0707 | 6:4e55101c65f4 | 315 | bTimeLong = 1; |
alexander0707 | 10:fdd52c601fcc | 316 | if(wVorgabeWert >=3200) wVorgabeWert = 3300; |
alexander0707 | 10:fdd52c601fcc | 317 | else wVorgabeWert = wVorgabeWert + 100; |
alexander0707 | 9:b30caa6d008f | 318 | bS2Timer = bS2Timer - 40; |
alexander0707 | 5:5c9b508670cf | 319 | } |
alexander0707 | 5:5c9b508670cf | 320 | bS2Timer++; |
alexander0707 | 5:5c9b508670cf | 321 | } |
alexander0707 | 5:5c9b508670cf | 322 | } |
alexander0707 | 5:5c9b508670cf | 323 | else{ /* Taste nicht gedrückt */ |
alexander0707 | 14:88379565eac6 | 324 | if(((bS2Timer >= nTastShort) && (bS2Timer <= nTastLong)) || ((bSCounter >= nTastShort) && (bSCounter <= nTastLong))){ /* Taste wurde bereits erkannt */ |
alexander0707 | 10:fdd52c601fcc | 325 | if(bTimeLong==0){ |
alexander0707 | 10:fdd52c601fcc | 326 | if(wVorgabeWert >=3290) wVorgabeWert = 3300; |
alexander0707 | 10:fdd52c601fcc | 327 | else wVorgabeWert = wVorgabeWert + 10; |
alexander0707 | 10:fdd52c601fcc | 328 | } |
alexander0707 | 5:5c9b508670cf | 329 | } |
alexander0707 | 5:5c9b508670cf | 330 | bS2Timer = 0; |
alexander0707 | 14:88379565eac6 | 331 | bTimeLong = 0; |
alexander0707 | 14:88379565eac6 | 332 | bSCounter = 0; |
alexander0707 | 5:5c9b508670cf | 333 | } |
alexander0707 | 5:5c9b508670cf | 334 | } |
alexander0707 | 5:5c9b508670cf | 335 | |
alexander0707 | 5:5c9b508670cf | 336 | void vTasteS3( void ){ |
alexander0707 | 14:88379565eac6 | 337 | if((pinS3 == 0 || abTxBuffer[0] == '-') && bMainState == enSchwellenwert){ /* User-Taste gedrückt */ |
alexander0707 | 14:88379565eac6 | 338 | |
alexander0707 | 15:bbcf8c3f91c5 | 339 | do{ |
alexander0707 | 15:bbcf8c3f91c5 | 340 | for(zaehler=0; zaehler<=250; zaehler++){ /*Zaehlen der Tastatur-Eingabe*/ |
alexander0707 | 15:bbcf8c3f91c5 | 341 | if(abTxBuffer[zaehler] == 'a') bSCounter++; |
alexander0707 | 15:bbcf8c3f91c5 | 342 | } |
alexander0707 | 15:bbcf8c3f91c5 | 343 | } while(abTxBuffer[zaehler] == abTxBuffer[zaehler+1]); |
alexander0707 | 14:88379565eac6 | 344 | |
alexander0707 | 14:88379565eac6 | 345 | if(bS3Timer < nTastLong+1 || bSCounter < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */ |
alexander0707 | 5:5c9b508670cf | 346 | if(bS3Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */ |
alexander0707 | 5:5c9b508670cf | 347 | //... |
alexander0707 | 5:5c9b508670cf | 348 | } |
alexander0707 | 14:88379565eac6 | 349 | if(bS3Timer == nTastLong || bSCounter == nTastLong){ /* Taste "lange gedrückt" erkannt */ |
alexander0707 | 6:4e55101c65f4 | 350 | bTimeLong = 1; |
alexander0707 | 10:fdd52c601fcc | 351 | if(wVorgabeWert <=100) wVorgabeWert = 0; |
alexander0707 | 10:fdd52c601fcc | 352 | else wVorgabeWert = wVorgabeWert - 100; |
alexander0707 | 12:bd1417475c5f | 353 | bS3Timer = bS3Timer - 40; |
alexander0707 | 5:5c9b508670cf | 354 | } |
alexander0707 | 5:5c9b508670cf | 355 | bS3Timer++; |
alexander0707 | 5:5c9b508670cf | 356 | } |
alexander0707 | 5:5c9b508670cf | 357 | } |
alexander0707 | 5:5c9b508670cf | 358 | else{ /* Taste nicht gedrückt */ |
alexander0707 | 14:88379565eac6 | 359 | if(((bS3Timer >= nTastShort) && (bS3Timer <= nTastLong)) || ((bSCounter >= nTastShort) && (bSCounter <= nTastLong))){ /* Taste wurde bereits erkannt */ |
alexander0707 | 10:fdd52c601fcc | 360 | if(bTimeLong==0){ |
alexander0707 | 10:fdd52c601fcc | 361 | if(wVorgabeWert <=10) wVorgabeWert = 0; |
alexander0707 | 10:fdd52c601fcc | 362 | else wVorgabeWert = wVorgabeWert - 10; |
alexander0707 | 10:fdd52c601fcc | 363 | } |
alexander0707 | 5:5c9b508670cf | 364 | } |
alexander0707 | 5:5c9b508670cf | 365 | bS3Timer = 0; |
alexander0707 | 14:88379565eac6 | 366 | bTimeLong = 0; |
alexander0707 | 14:88379565eac6 | 367 | bSCounter = 0; |
alexander0707 | 5:5c9b508670cf | 368 | } |
alexander0707 | 5:5c9b508670cf | 369 | } |
alexander0707 | 5:5c9b508670cf | 370 | |
alexander0707 | 5:5c9b508670cf | 371 | |
alexander0707 | 5:5c9b508670cf | 372 | |
alexander0707 | 5:5c9b508670cf | 373 | void vCheckTasten( void ){ |
alexander0707 | 5:5c9b508670cf | 374 | vTasteS1(); |
alexander0707 | 5:5c9b508670cf | 375 | vTasteS2(); |
alexander0707 | 5:5c9b508670cf | 376 | vTasteS3(); |
alexander0707 | 5:5c9b508670cf | 377 | } |
alexander0707 | 5:5c9b508670cf | 378 | void vSegmentDigit( void ) //wichtig!! |
alexander0707 | 5:5c9b508670cf | 379 | { |
alexander0707 | 5:5c9b508670cf | 380 | bDigit++; |
alexander0707 | 5:5c9b508670cf | 381 | wSerial = abZiffer[abDisplayMemory[bDigit&0x03]]; |
alexander0707 | 5:5c9b508670cf | 382 | switch(bDisplayState) { |
alexander0707 | 5:5c9b508670cf | 383 | case enSchwellenwert: |
alexander0707 | 5:5c9b508670cf | 384 | bTimerDot++; /* Zähler für Punktwechsel */ |
alexander0707 | 6:4e55101c65f4 | 385 | vDisplayVolt(wVorgabeWert); |
alexander0707 | 6:4e55101c65f4 | 386 | if(bTimerDot == 400) { |
alexander0707 | 7:94c73e4168d8 | 387 | if((bDigit&0x03) == 0x01) { |
alexander0707 | 7:94c73e4168d8 | 388 | wSerial = wSerial & ~nSegH; /* Punktanzeigen */ |
alexander0707 | 7:94c73e4168d8 | 389 | } |
alexander0707 | 5:5c9b508670cf | 390 | bTimerDot = 0; |
alexander0707 | 5:5c9b508670cf | 391 | } |
alexander0707 | 5:5c9b508670cf | 392 | break; |
alexander0707 | 5:5c9b508670cf | 393 | case enPotiAnzeige: |
alexander0707 | 6:4e55101c65f4 | 394 | vDisplayVolt(wPotiWert); |
alexander0707 | 5:5c9b508670cf | 395 | if((bDigit&0x03) == 0x01) { /* Dezimalpunkt setzen */ |
alexander0707 | 5:5c9b508670cf | 396 | wSerial = wSerial & ~nSegH; |
alexander0707 | 5:5c9b508670cf | 397 | } |
alexander0707 | 5:5c9b508670cf | 398 | break; |
alexander0707 | 5:5c9b508670cf | 399 | case enVergleich: |
alexander0707 | 10:fdd52c601fcc | 400 | vDisplayDiff(nDiffWert); |
alexander0707 | 5:5c9b508670cf | 401 | if((bDigit&0x03) == 0x01) { /* Dezimalpunkt setzen */ |
alexander0707 | 5:5c9b508670cf | 402 | wSerial = wSerial & ~nSegH; |
alexander0707 | 5:5c9b508670cf | 403 | } |
alexander0707 | 5:5c9b508670cf | 404 | break; |
alexander0707 | 5:5c9b508670cf | 405 | } |
alexander0707 | 5:5c9b508670cf | 406 | vShiftLoad(((wSerial << 8) & 0xfff0)| (1 << (bDigit&0x03))); |
alexander0707 | 5:5c9b508670cf | 407 | } |
alexander0707 | 5:5c9b508670cf | 408 | |
alexander0707 | 13:b1d6b2285b13 | 409 | |
alexander0707 | 13:b1d6b2285b13 | 410 | |
alexander0707 | 13:b1d6b2285b13 | 411 | |
alexander0707 | 13:b1d6b2285b13 | 412 | |
alexander0707 | 13:b1d6b2285b13 | 413 | |
alexander0707 | 13:b1d6b2285b13 | 414 | |
alexander0707 | 13:b1d6b2285b13 | 415 | |
alexander0707 | 13:b1d6b2285b13 | 416 | |
alexander0707 | 13:b1d6b2285b13 | 417 | |
alexander0707 | 13:b1d6b2285b13 | 418 | Serial stComX(D1,D0); /* UART-Kommunikation (Txd(D1)/Rxd(D0)) mit dem PC */ |
alexander0707 | 13:b1d6b2285b13 | 419 | |
alexander0707 | 14:88379565eac6 | 420 | |
alexander0707 | 14:88379565eac6 | 421 | byte SYS_vStartComX( word wSize, byte *pData ){ /* Start einer Übertragung */ |
alexander0707 | 14:88379565eac6 | 422 | byte i; |
alexander0707 | 14:88379565eac6 | 423 | if(wSizeData) i = False; |
alexander0707 | 14:88379565eac6 | 424 | else{ |
alexander0707 | 14:88379565eac6 | 425 | wSizeData = wSize; /* Anzahl der Sendedaten */ |
alexander0707 | 14:88379565eac6 | 426 | pUartData = pData; /* Zeiger auf diese Daten */ |
alexander0707 | 14:88379565eac6 | 427 | stComX.putc(*pUartData); /* erstes Zeichen senden */ |
alexander0707 | 14:88379565eac6 | 428 | pUartData++; |
alexander0707 | 14:88379565eac6 | 429 | wSizeData--; |
alexander0707 | 14:88379565eac6 | 430 | USART2->CR1 |= USART_CR1_TXEIE; /* TXE-Interrupt freigeben */ |
alexander0707 | 14:88379565eac6 | 431 | i = True; |
alexander0707 | 14:88379565eac6 | 432 | } |
alexander0707 | 14:88379565eac6 | 433 | return i; |
alexander0707 | 14:88379565eac6 | 434 | } |
alexander0707 | 13:b1d6b2285b13 | 435 | |
alexander0707 | 13:b1d6b2285b13 | 436 | |
alexander0707 | 14:88379565eac6 | 437 | /* Senderoutine zum COM-Port am PC */ |
alexander0707 | 14:88379565eac6 | 438 | void vIsrTxComX( void ){ /* Senderoutine */ |
alexander0707 | 14:88379565eac6 | 439 | if(stComX.writeable()){ /* Sende-ISR */ |
alexander0707 | 14:88379565eac6 | 440 | if(bSizeData){ /* sind Daten vorhanden ? */ |
alexander0707 | 14:88379565eac6 | 441 | stComX.putc(*pUartData); /* daten senden */ |
alexander0707 | 14:88379565eac6 | 442 | pUartData++; |
alexander0707 | 14:88379565eac6 | 443 | bSizeData--; |
alexander0707 | 14:88379565eac6 | 444 | } |
alexander0707 | 14:88379565eac6 | 445 | else{ |
alexander0707 | 14:88379565eac6 | 446 | USART2->CR1 &= ~USART_CR1_TXEIE; /* Interrupt sperren */ |
alexander0707 | 14:88379565eac6 | 447 | } |
alexander0707 | 14:88379565eac6 | 448 | } |
alexander0707 | 14:88379565eac6 | 449 | } |
alexander0707 | 14:88379565eac6 | 450 | |
alexander0707 | 14:88379565eac6 | 451 | |
alexander0707 | 14:88379565eac6 | 452 | /* Empfangsroutine vom COM-Port des PC */ |
alexander0707 | 14:88379565eac6 | 453 | void vIsrRxComX( void ){ /* Empfangsroutine */ |
alexander0707 | 14:88379565eac6 | 454 | if(stComX.readable()){ /* Empfangs-ISR */ |
alexander0707 | 14:88379565eac6 | 455 | abTxBuffer[0] = stComX.getc(); |
alexander0707 | 14:88379565eac6 | 456 | abTxBuffer[0] = abTxBuffer[0] + 1; |
alexander0707 | 14:88379565eac6 | 457 | SYS_vStartComX(1, &abTxBuffer[0]); |
alexander0707 | 14:88379565eac6 | 458 | } |
alexander0707 | 14:88379565eac6 | 459 | } |
alexander0707 | 14:88379565eac6 | 460 | |
alexander0707 | 13:b1d6b2285b13 | 461 | |
alexander0707 | 13:b1d6b2285b13 | 462 | |
alexander0707 | 13:b1d6b2285b13 | 463 | |
alexander0707 | 13:b1d6b2285b13 | 464 | |
alexander0707 | 13:b1d6b2285b13 | 465 | |
alexander0707 | 13:b1d6b2285b13 | 466 | |
alexander0707 | 13:b1d6b2285b13 | 467 | |
alexander0707 | 13:b1d6b2285b13 | 468 | |
prof_al | 0:5ac32d240694 | 469 | /*************************************************************************** |
prof_al | 0:5ac32d240694 | 470 | * main() |
prof_al | 0:5ac32d240694 | 471 | ***************************************************************************/ |
prof_al | 0:5ac32d240694 | 472 | int main() { |
prof_al | 0:5ac32d240694 | 473 | /* Variablen initialisieren */ |
alexander0707 | 6:4e55101c65f4 | 474 | vSetForStart(); |
alexander0707 | 13:b1d6b2285b13 | 475 | |
alexander0707 | 13:b1d6b2285b13 | 476 | |
alexander0707 | 14:88379565eac6 | 477 | //Seriel.begin(9600); |
alexander0707 | 5:5c9b508670cf | 478 | |
alexander0707 | 14:88379565eac6 | 479 | |
alexander0707 | 6:4e55101c65f4 | 480 | while(1) { |
alexander0707 | 10:fdd52c601fcc | 481 | wPotiWert = pinPoti*3300; |
alexander0707 | 6:4e55101c65f4 | 482 | vCheckTasten(); |
alexander0707 | 10:fdd52c601fcc | 483 | nDiffWert = wVorgabeWert - wPotiWert; |
alexander0707 | 14:88379565eac6 | 484 | |
alexander0707 | 14:88379565eac6 | 485 | |
alexander0707 | 14:88379565eac6 | 486 | stComX.attach(&vIsrRxComX, Serial::RxIrq); /* ISR zum Datemempfang vom PC */ |
alexander0707 | 14:88379565eac6 | 487 | stComX.attach(&vIsrTxComX, Serial::TxIrq); /* Sende-ISR */ |
alexander0707 | 14:88379565eac6 | 488 | |
alexander0707 | 14:88379565eac6 | 489 | |
alexander0707 | 5:5c9b508670cf | 490 | switch(bMainState) { |
alexander0707 | 6:4e55101c65f4 | 491 | case enSchwellenwert: |
alexander0707 | 12:bd1417475c5f | 492 | pinBeep = 1; |
alexander0707 | 5:5c9b508670cf | 493 | break; |
alexander0707 | 6:4e55101c65f4 | 494 | case enPotiAnzeige: |
alexander0707 | 12:bd1417475c5f | 495 | pinBeep = 1; |
alexander0707 | 5:5c9b508670cf | 496 | break; |
alexander0707 | 6:4e55101c65f4 | 497 | case enVergleich: |
alexander0707 | 10:fdd52c601fcc | 498 | if(nDiffWert<0) pinBeep=0; |
alexander0707 | 6:4e55101c65f4 | 499 | else pinBeep=1; |
alexander0707 | 5:5c9b508670cf | 500 | break; |
prof_al | 0:5ac32d240694 | 501 | } |
alexander0707 | 5:5c9b508670cf | 502 | vSegmentDigit(); |
alexander0707 | 6:4e55101c65f4 | 503 | wait_us(nCircleTime); |
prof_al | 0:5ac32d240694 | 504 | } |
alexander0707 | 5:5c9b508670cf | 505 | } |