Auf den letzten Metern
Dependencies: mbed
main.cpp@16:404bcdd9c518, 23 months ago (annotated)
- Committer:
- alexander0707
- Date:
- Mon Dec 05 09:29:47 2022 +0000
- Revision:
- 16:404bcdd9c518
- Parent:
- 15:bbcf8c3f91c5
- Child:
- 17:c34f14ec2beb
v2.3 Tests.....;
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 | 16:404bcdd9c518 | 260 | if(pinS1 == 0){ /* User-Taste gedrückt */ |
alexander0707 | 16:404bcdd9c518 | 261 | if(bS1Timer < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */ |
alexander0707 | 5:5c9b508670cf | 262 | if(bS1Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */ |
alexander0707 | 5:5c9b508670cf | 263 | //... |
alexander0707 | 5:5c9b508670cf | 264 | } |
alexander0707 | 16:404bcdd9c518 | 265 | if(bS1Timer == nTastLong){ /* Taste "lange gedrückt" erkannt */ |
alexander0707 | 16:404bcdd9c518 | 266 | if(bDisplayState == enSchwellenwert){ |
alexander0707 | 6:4e55101c65f4 | 267 | bDisplayState = enVergleich; |
alexander0707 | 6:4e55101c65f4 | 268 | bMainState = enVergleich; |
alexander0707 | 6:4e55101c65f4 | 269 | } |
alexander0707 | 6:4e55101c65f4 | 270 | else{ |
alexander0707 | 6:4e55101c65f4 | 271 | bDisplayState = enSchwellenwert; |
alexander0707 | 6:4e55101c65f4 | 272 | bMainState = enSchwellenwert; |
alexander0707 | 6:4e55101c65f4 | 273 | } |
alexander0707 | 6:4e55101c65f4 | 274 | } |
alexander0707 | 6:4e55101c65f4 | 275 | bS1Timer++; |
alexander0707 | 6:4e55101c65f4 | 276 | } |
alexander0707 | 6:4e55101c65f4 | 277 | } |
alexander0707 | 6:4e55101c65f4 | 278 | else{ /* Taste nicht gedrückt */ |
alexander0707 | 16:404bcdd9c518 | 279 | if(((bS1Timer >= nTastShort) && (bS1Timer <= nTastLong))){ /* Taste wurde bereits erkannt */ |
alexander0707 | 7:94c73e4168d8 | 280 | if(bDisplayState == enSchwellenwert){ |
alexander0707 | 5:5c9b508670cf | 281 | bDisplayState = enPotiAnzeige; |
alexander0707 | 5:5c9b508670cf | 282 | bMainState = enPotiAnzeige; |
alexander0707 | 5:5c9b508670cf | 283 | } |
alexander0707 | 5:5c9b508670cf | 284 | else{ |
alexander0707 | 5:5c9b508670cf | 285 | bDisplayState = enSchwellenwert; |
alexander0707 | 5:5c9b508670cf | 286 | bMainState= enSchwellenwert; |
alexander0707 | 5:5c9b508670cf | 287 | } |
alexander0707 | 5:5c9b508670cf | 288 | } |
alexander0707 | 5:5c9b508670cf | 289 | bS1Timer = 0; |
alexander0707 | 14:88379565eac6 | 290 | bSCounter = 0; |
alexander0707 | 5:5c9b508670cf | 291 | } |
alexander0707 | 16:404bcdd9c518 | 292 | |
alexander0707 | 16:404bcdd9c518 | 293 | if(abTxBuffer[0] == 'b') { /* User-Taste gedrückt */ |
alexander0707 | 16:404bcdd9c518 | 294 | |
alexander0707 | 16:404bcdd9c518 | 295 | for(zaehler=0; zaehler<=250; zaehler++) { /*Zaehlen der Tastatur-Eingabe*/ |
alexander0707 | 16:404bcdd9c518 | 296 | while(abTxBuffer[zaehler] == abTxBuffer[zaehler+1]) if(abTxBuffer[zaehler] == 'b') bSCounter++; |
alexander0707 | 16:404bcdd9c518 | 297 | } |
alexander0707 | 16:404bcdd9c518 | 298 | |
alexander0707 | 16:404bcdd9c518 | 299 | if(bSCounter < nTastLong+1) { /* Abfrage max. bis Taste lange gedrückt */ |
alexander0707 | 16:404bcdd9c518 | 300 | if(bS1Timer == nTastShort) { /* Taste "kurz gedrückt" erkannt */ |
alexander0707 | 16:404bcdd9c518 | 301 | //... |
alexander0707 | 16:404bcdd9c518 | 302 | } |
alexander0707 | 16:404bcdd9c518 | 303 | if(bSCounter == nTastLong) { /* Taste "lange gedrückt" erkannt */ |
alexander0707 | 16:404bcdd9c518 | 304 | if(bDisplayState == enPotiAnzeige) { |
alexander0707 | 16:404bcdd9c518 | 305 | bDisplayState = enVergleich; |
alexander0707 | 16:404bcdd9c518 | 306 | bMainState = enVergleich; |
alexander0707 | 16:404bcdd9c518 | 307 | } else { |
alexander0707 | 16:404bcdd9c518 | 308 | bDisplayState = enSchwellenwert; |
alexander0707 | 16:404bcdd9c518 | 309 | bMainState = enSchwellenwert; |
alexander0707 | 16:404bcdd9c518 | 310 | } |
alexander0707 | 16:404bcdd9c518 | 311 | } |
alexander0707 | 16:404bcdd9c518 | 312 | bS1Timer++; |
alexander0707 | 16:404bcdd9c518 | 313 | } |
alexander0707 | 16:404bcdd9c518 | 314 | } else { /* Taste nicht gedrückt */ |
alexander0707 | 16:404bcdd9c518 | 315 | if(((bSCounter >= nTastShort) && (bSCounter <= nTastLong))) { /* Taste wurde bereits erkannt */ |
alexander0707 | 16:404bcdd9c518 | 316 | if(bDisplayState == enSchwellenwert) { |
alexander0707 | 16:404bcdd9c518 | 317 | bDisplayState = enPotiAnzeige; |
alexander0707 | 16:404bcdd9c518 | 318 | bMainState = enPotiAnzeige; |
alexander0707 | 16:404bcdd9c518 | 319 | } else { |
alexander0707 | 16:404bcdd9c518 | 320 | bDisplayState = enSchwellenwert; |
alexander0707 | 16:404bcdd9c518 | 321 | bMainState= enSchwellenwert; |
alexander0707 | 16:404bcdd9c518 | 322 | } |
alexander0707 | 16:404bcdd9c518 | 323 | } |
alexander0707 | 16:404bcdd9c518 | 324 | bS1Timer = 0; |
alexander0707 | 16:404bcdd9c518 | 325 | bSCounter = 0; |
alexander0707 | 16:404bcdd9c518 | 326 | } |
alexander0707 | 5:5c9b508670cf | 327 | } |
alexander0707 | 5:5c9b508670cf | 328 | |
alexander0707 | 5:5c9b508670cf | 329 | void vTasteS2( void ){ |
alexander0707 | 16:404bcdd9c518 | 330 | if((pinS2 == 0 || abTxBuffer[0] == ',') && bMainState == enSchwellenwert){ /* User-Taste gedrückt */ |
alexander0707 | 14:88379565eac6 | 331 | |
alexander0707 | 16:404bcdd9c518 | 332 | for(zaehler=0; zaehler<=250; zaehler++){ /*Zaehlen der Tastatur-Eingabe*/ |
alexander0707 | 16:404bcdd9c518 | 333 | while(abTxBuffer[zaehler] == abTxBuffer[zaehler+1]) if(abTxBuffer[zaehler] == ',') bSCounter++; |
alexander0707 | 16:404bcdd9c518 | 334 | } |
alexander0707 | 14:88379565eac6 | 335 | |
alexander0707 | 14:88379565eac6 | 336 | if(bS2Timer < nTastLong+1 || bSCounter < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */ |
alexander0707 | 5:5c9b508670cf | 337 | if(bS2Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */ |
alexander0707 | 5:5c9b508670cf | 338 | //... |
alexander0707 | 5:5c9b508670cf | 339 | } |
alexander0707 | 14:88379565eac6 | 340 | if(bS2Timer == nTastLong || bSCounter == nTastLong){ /* Taste "lange gedrückt" erkannt */ |
alexander0707 | 6:4e55101c65f4 | 341 | bTimeLong = 1; |
alexander0707 | 10:fdd52c601fcc | 342 | if(wVorgabeWert >=3200) wVorgabeWert = 3300; |
alexander0707 | 10:fdd52c601fcc | 343 | else wVorgabeWert = wVorgabeWert + 100; |
alexander0707 | 9:b30caa6d008f | 344 | bS2Timer = bS2Timer - 40; |
alexander0707 | 5:5c9b508670cf | 345 | } |
alexander0707 | 5:5c9b508670cf | 346 | bS2Timer++; |
alexander0707 | 5:5c9b508670cf | 347 | } |
alexander0707 | 5:5c9b508670cf | 348 | } |
alexander0707 | 5:5c9b508670cf | 349 | else{ /* Taste nicht gedrückt */ |
alexander0707 | 14:88379565eac6 | 350 | if(((bS2Timer >= nTastShort) && (bS2Timer <= nTastLong)) || ((bSCounter >= nTastShort) && (bSCounter <= nTastLong))){ /* Taste wurde bereits erkannt */ |
alexander0707 | 10:fdd52c601fcc | 351 | if(bTimeLong==0){ |
alexander0707 | 10:fdd52c601fcc | 352 | if(wVorgabeWert >=3290) wVorgabeWert = 3300; |
alexander0707 | 10:fdd52c601fcc | 353 | else wVorgabeWert = wVorgabeWert + 10; |
alexander0707 | 10:fdd52c601fcc | 354 | } |
alexander0707 | 5:5c9b508670cf | 355 | } |
alexander0707 | 5:5c9b508670cf | 356 | bS2Timer = 0; |
alexander0707 | 14:88379565eac6 | 357 | bTimeLong = 0; |
alexander0707 | 14:88379565eac6 | 358 | bSCounter = 0; |
alexander0707 | 5:5c9b508670cf | 359 | } |
alexander0707 | 5:5c9b508670cf | 360 | } |
alexander0707 | 5:5c9b508670cf | 361 | |
alexander0707 | 5:5c9b508670cf | 362 | void vTasteS3( void ){ |
alexander0707 | 16:404bcdd9c518 | 363 | if((pinS3 == 0 || abTxBuffer[0] == '.') && bMainState == enSchwellenwert){ /* User-Taste gedrückt */ |
alexander0707 | 14:88379565eac6 | 364 | |
alexander0707 | 16:404bcdd9c518 | 365 | for(zaehler=0; zaehler<=250; zaehler++){ /*Zaehlen der Tastatur-Eingabe*/ |
alexander0707 | 16:404bcdd9c518 | 366 | while(abTxBuffer[zaehler] == abTxBuffer[zaehler+1]) if(abTxBuffer[zaehler] == '.') bSCounter++; |
alexander0707 | 16:404bcdd9c518 | 367 | } |
alexander0707 | 14:88379565eac6 | 368 | |
alexander0707 | 14:88379565eac6 | 369 | if(bS3Timer < nTastLong+1 || bSCounter < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */ |
alexander0707 | 5:5c9b508670cf | 370 | if(bS3Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */ |
alexander0707 | 5:5c9b508670cf | 371 | //... |
alexander0707 | 5:5c9b508670cf | 372 | } |
alexander0707 | 14:88379565eac6 | 373 | if(bS3Timer == nTastLong || bSCounter == nTastLong){ /* Taste "lange gedrückt" erkannt */ |
alexander0707 | 6:4e55101c65f4 | 374 | bTimeLong = 1; |
alexander0707 | 10:fdd52c601fcc | 375 | if(wVorgabeWert <=100) wVorgabeWert = 0; |
alexander0707 | 10:fdd52c601fcc | 376 | else wVorgabeWert = wVorgabeWert - 100; |
alexander0707 | 12:bd1417475c5f | 377 | bS3Timer = bS3Timer - 40; |
alexander0707 | 5:5c9b508670cf | 378 | } |
alexander0707 | 5:5c9b508670cf | 379 | bS3Timer++; |
alexander0707 | 5:5c9b508670cf | 380 | } |
alexander0707 | 5:5c9b508670cf | 381 | } |
alexander0707 | 5:5c9b508670cf | 382 | else{ /* Taste nicht gedrückt */ |
alexander0707 | 14:88379565eac6 | 383 | if(((bS3Timer >= nTastShort) && (bS3Timer <= nTastLong)) || ((bSCounter >= nTastShort) && (bSCounter <= nTastLong))){ /* Taste wurde bereits erkannt */ |
alexander0707 | 10:fdd52c601fcc | 384 | if(bTimeLong==0){ |
alexander0707 | 10:fdd52c601fcc | 385 | if(wVorgabeWert <=10) wVorgabeWert = 0; |
alexander0707 | 10:fdd52c601fcc | 386 | else wVorgabeWert = wVorgabeWert - 10; |
alexander0707 | 10:fdd52c601fcc | 387 | } |
alexander0707 | 5:5c9b508670cf | 388 | } |
alexander0707 | 5:5c9b508670cf | 389 | bS3Timer = 0; |
alexander0707 | 14:88379565eac6 | 390 | bTimeLong = 0; |
alexander0707 | 14:88379565eac6 | 391 | bSCounter = 0; |
alexander0707 | 5:5c9b508670cf | 392 | } |
alexander0707 | 5:5c9b508670cf | 393 | } |
alexander0707 | 5:5c9b508670cf | 394 | |
alexander0707 | 5:5c9b508670cf | 395 | |
alexander0707 | 5:5c9b508670cf | 396 | |
alexander0707 | 5:5c9b508670cf | 397 | void vCheckTasten( void ){ |
alexander0707 | 5:5c9b508670cf | 398 | vTasteS1(); |
alexander0707 | 5:5c9b508670cf | 399 | vTasteS2(); |
alexander0707 | 5:5c9b508670cf | 400 | vTasteS3(); |
alexander0707 | 5:5c9b508670cf | 401 | } |
alexander0707 | 5:5c9b508670cf | 402 | void vSegmentDigit( void ) //wichtig!! |
alexander0707 | 5:5c9b508670cf | 403 | { |
alexander0707 | 5:5c9b508670cf | 404 | bDigit++; |
alexander0707 | 5:5c9b508670cf | 405 | wSerial = abZiffer[abDisplayMemory[bDigit&0x03]]; |
alexander0707 | 5:5c9b508670cf | 406 | switch(bDisplayState) { |
alexander0707 | 5:5c9b508670cf | 407 | case enSchwellenwert: |
alexander0707 | 5:5c9b508670cf | 408 | bTimerDot++; /* Zähler für Punktwechsel */ |
alexander0707 | 6:4e55101c65f4 | 409 | vDisplayVolt(wVorgabeWert); |
alexander0707 | 6:4e55101c65f4 | 410 | if(bTimerDot == 400) { |
alexander0707 | 7:94c73e4168d8 | 411 | if((bDigit&0x03) == 0x01) { |
alexander0707 | 7:94c73e4168d8 | 412 | wSerial = wSerial & ~nSegH; /* Punktanzeigen */ |
alexander0707 | 7:94c73e4168d8 | 413 | } |
alexander0707 | 5:5c9b508670cf | 414 | bTimerDot = 0; |
alexander0707 | 5:5c9b508670cf | 415 | } |
alexander0707 | 5:5c9b508670cf | 416 | break; |
alexander0707 | 5:5c9b508670cf | 417 | case enPotiAnzeige: |
alexander0707 | 6:4e55101c65f4 | 418 | vDisplayVolt(wPotiWert); |
alexander0707 | 5:5c9b508670cf | 419 | if((bDigit&0x03) == 0x01) { /* Dezimalpunkt setzen */ |
alexander0707 | 5:5c9b508670cf | 420 | wSerial = wSerial & ~nSegH; |
alexander0707 | 5:5c9b508670cf | 421 | } |
alexander0707 | 5:5c9b508670cf | 422 | break; |
alexander0707 | 5:5c9b508670cf | 423 | case enVergleich: |
alexander0707 | 10:fdd52c601fcc | 424 | vDisplayDiff(nDiffWert); |
alexander0707 | 5:5c9b508670cf | 425 | if((bDigit&0x03) == 0x01) { /* Dezimalpunkt setzen */ |
alexander0707 | 5:5c9b508670cf | 426 | wSerial = wSerial & ~nSegH; |
alexander0707 | 5:5c9b508670cf | 427 | } |
alexander0707 | 5:5c9b508670cf | 428 | break; |
alexander0707 | 5:5c9b508670cf | 429 | } |
alexander0707 | 5:5c9b508670cf | 430 | vShiftLoad(((wSerial << 8) & 0xfff0)| (1 << (bDigit&0x03))); |
alexander0707 | 5:5c9b508670cf | 431 | } |
alexander0707 | 5:5c9b508670cf | 432 | |
alexander0707 | 13:b1d6b2285b13 | 433 | |
alexander0707 | 13:b1d6b2285b13 | 434 | |
alexander0707 | 13:b1d6b2285b13 | 435 | |
alexander0707 | 13:b1d6b2285b13 | 436 | |
alexander0707 | 13:b1d6b2285b13 | 437 | |
alexander0707 | 13:b1d6b2285b13 | 438 | |
alexander0707 | 13:b1d6b2285b13 | 439 | |
alexander0707 | 13:b1d6b2285b13 | 440 | |
alexander0707 | 13:b1d6b2285b13 | 441 | |
alexander0707 | 13:b1d6b2285b13 | 442 | Serial stComX(D1,D0); /* UART-Kommunikation (Txd(D1)/Rxd(D0)) mit dem PC */ |
alexander0707 | 13:b1d6b2285b13 | 443 | |
alexander0707 | 14:88379565eac6 | 444 | |
alexander0707 | 14:88379565eac6 | 445 | byte SYS_vStartComX( word wSize, byte *pData ){ /* Start einer Übertragung */ |
alexander0707 | 14:88379565eac6 | 446 | byte i; |
alexander0707 | 14:88379565eac6 | 447 | if(wSizeData) i = False; |
alexander0707 | 14:88379565eac6 | 448 | else{ |
alexander0707 | 14:88379565eac6 | 449 | wSizeData = wSize; /* Anzahl der Sendedaten */ |
alexander0707 | 14:88379565eac6 | 450 | pUartData = pData; /* Zeiger auf diese Daten */ |
alexander0707 | 14:88379565eac6 | 451 | stComX.putc(*pUartData); /* erstes Zeichen senden */ |
alexander0707 | 14:88379565eac6 | 452 | pUartData++; |
alexander0707 | 14:88379565eac6 | 453 | wSizeData--; |
alexander0707 | 14:88379565eac6 | 454 | USART2->CR1 |= USART_CR1_TXEIE; /* TXE-Interrupt freigeben */ |
alexander0707 | 14:88379565eac6 | 455 | i = True; |
alexander0707 | 14:88379565eac6 | 456 | } |
alexander0707 | 14:88379565eac6 | 457 | return i; |
alexander0707 | 14:88379565eac6 | 458 | } |
alexander0707 | 13:b1d6b2285b13 | 459 | |
alexander0707 | 13:b1d6b2285b13 | 460 | |
alexander0707 | 14:88379565eac6 | 461 | /* Senderoutine zum COM-Port am PC */ |
alexander0707 | 14:88379565eac6 | 462 | void vIsrTxComX( void ){ /* Senderoutine */ |
alexander0707 | 14:88379565eac6 | 463 | if(stComX.writeable()){ /* Sende-ISR */ |
alexander0707 | 14:88379565eac6 | 464 | if(bSizeData){ /* sind Daten vorhanden ? */ |
alexander0707 | 14:88379565eac6 | 465 | stComX.putc(*pUartData); /* daten senden */ |
alexander0707 | 14:88379565eac6 | 466 | pUartData++; |
alexander0707 | 14:88379565eac6 | 467 | bSizeData--; |
alexander0707 | 14:88379565eac6 | 468 | } |
alexander0707 | 14:88379565eac6 | 469 | else{ |
alexander0707 | 14:88379565eac6 | 470 | USART2->CR1 &= ~USART_CR1_TXEIE; /* Interrupt sperren */ |
alexander0707 | 14:88379565eac6 | 471 | } |
alexander0707 | 14:88379565eac6 | 472 | } |
alexander0707 | 14:88379565eac6 | 473 | } |
alexander0707 | 14:88379565eac6 | 474 | |
alexander0707 | 14:88379565eac6 | 475 | |
alexander0707 | 14:88379565eac6 | 476 | /* Empfangsroutine vom COM-Port des PC */ |
alexander0707 | 14:88379565eac6 | 477 | void vIsrRxComX( void ){ /* Empfangsroutine */ |
alexander0707 | 14:88379565eac6 | 478 | if(stComX.readable()){ /* Empfangs-ISR */ |
alexander0707 | 14:88379565eac6 | 479 | abTxBuffer[0] = stComX.getc(); |
alexander0707 | 14:88379565eac6 | 480 | abTxBuffer[0] = abTxBuffer[0] + 1; |
alexander0707 | 14:88379565eac6 | 481 | SYS_vStartComX(1, &abTxBuffer[0]); |
alexander0707 | 14:88379565eac6 | 482 | } |
alexander0707 | 14:88379565eac6 | 483 | } |
alexander0707 | 14:88379565eac6 | 484 | |
alexander0707 | 13:b1d6b2285b13 | 485 | |
alexander0707 | 13:b1d6b2285b13 | 486 | |
alexander0707 | 13:b1d6b2285b13 | 487 | |
alexander0707 | 13:b1d6b2285b13 | 488 | |
alexander0707 | 13:b1d6b2285b13 | 489 | |
alexander0707 | 13:b1d6b2285b13 | 490 | |
alexander0707 | 13:b1d6b2285b13 | 491 | |
alexander0707 | 13:b1d6b2285b13 | 492 | |
prof_al | 0:5ac32d240694 | 493 | /*************************************************************************** |
prof_al | 0:5ac32d240694 | 494 | * main() |
prof_al | 0:5ac32d240694 | 495 | ***************************************************************************/ |
prof_al | 0:5ac32d240694 | 496 | int main() { |
prof_al | 0:5ac32d240694 | 497 | /* Variablen initialisieren */ |
alexander0707 | 6:4e55101c65f4 | 498 | vSetForStart(); |
alexander0707 | 13:b1d6b2285b13 | 499 | |
alexander0707 | 13:b1d6b2285b13 | 500 | |
alexander0707 | 14:88379565eac6 | 501 | //Seriel.begin(9600); |
alexander0707 | 5:5c9b508670cf | 502 | |
alexander0707 | 14:88379565eac6 | 503 | |
alexander0707 | 6:4e55101c65f4 | 504 | while(1) { |
alexander0707 | 10:fdd52c601fcc | 505 | wPotiWert = pinPoti*3300; |
alexander0707 | 6:4e55101c65f4 | 506 | vCheckTasten(); |
alexander0707 | 10:fdd52c601fcc | 507 | nDiffWert = wVorgabeWert - wPotiWert; |
alexander0707 | 14:88379565eac6 | 508 | |
alexander0707 | 14:88379565eac6 | 509 | |
alexander0707 | 14:88379565eac6 | 510 | stComX.attach(&vIsrRxComX, Serial::RxIrq); /* ISR zum Datemempfang vom PC */ |
alexander0707 | 14:88379565eac6 | 511 | stComX.attach(&vIsrTxComX, Serial::TxIrq); /* Sende-ISR */ |
alexander0707 | 14:88379565eac6 | 512 | |
alexander0707 | 14:88379565eac6 | 513 | |
alexander0707 | 5:5c9b508670cf | 514 | switch(bMainState) { |
alexander0707 | 6:4e55101c65f4 | 515 | case enSchwellenwert: |
alexander0707 | 12:bd1417475c5f | 516 | pinBeep = 1; |
alexander0707 | 5:5c9b508670cf | 517 | break; |
alexander0707 | 6:4e55101c65f4 | 518 | case enPotiAnzeige: |
alexander0707 | 12:bd1417475c5f | 519 | pinBeep = 1; |
alexander0707 | 5:5c9b508670cf | 520 | break; |
alexander0707 | 6:4e55101c65f4 | 521 | case enVergleich: |
alexander0707 | 10:fdd52c601fcc | 522 | if(nDiffWert<0) pinBeep=0; |
alexander0707 | 6:4e55101c65f4 | 523 | else pinBeep=1; |
alexander0707 | 5:5c9b508670cf | 524 | break; |
prof_al | 0:5ac32d240694 | 525 | } |
alexander0707 | 5:5c9b508670cf | 526 | vSegmentDigit(); |
alexander0707 | 6:4e55101c65f4 | 527 | wait_us(nCircleTime); |
prof_al | 0:5ac32d240694 | 528 | } |
alexander0707 | 5:5c9b508670cf | 529 | } |