komplett funktionsfähig

Dependencies:   mbed

Committer:
alexander0707
Date:
Mon Dec 05 15:58:01 2022 +0000
Revision:
23:7b9ec8cd081d
Parent:
22:5600f9b29a51
v4.0 Jetzt klappts doch.

Who changed what in which revision?

UserRevisionLine numberNew 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 bDigit; /*
prof_al 0:5ac32d240694 80 * Description : aktives Digit
prof_al 0:5ac32d240694 81 */
prof_al 0:5ac32d240694 82
prof_al 0:5ac32d240694 83 byte bS1Timer; /*
prof_al 0:5ac32d240694 84 * Description : Timer für Taste S1
prof_al 0:5ac32d240694 85 */
prof_al 0:5ac32d240694 86
prof_al 0:5ac32d240694 87 byte bS2Timer; /*
prof_al 0:5ac32d240694 88 * Description : Timer für Taste S2
prof_al 0:5ac32d240694 89 */
prof_al 0:5ac32d240694 90
prof_al 0:5ac32d240694 91 byte bS3Timer; /*
prof_al 0:5ac32d240694 92 * Description : Timer für Taste S3
prof_al 0:5ac32d240694 93 */
prof_al 0:5ac32d240694 94
alexander0707 14:88379565eac6 95 byte bSCounter; /*
alexander0707 14:88379565eac6 96 * Description : Zähler UART-Auslese für Tasterersatz
alexander0707 14:88379565eac6 97 */
alexander0707 14:88379565eac6 98
alexander0707 5:5c9b508670cf 99 byte bDisplayState; /*
alexander0707 5:5c9b508670cf 100 * Description :
alexander0707 5:5c9b508670cf 101 */
alexander0707 5:5c9b508670cf 102 const byte enSchwellenwert=0x00;
alexander0707 5:5c9b508670cf 103 const byte enPotiAnzeige = 0x01;
alexander0707 5:5c9b508670cf 104 const byte enVergleich = 0x02;
alexander0707 5:5c9b508670cf 105
alexander0707 5:5c9b508670cf 106
alexander0707 5:5c9b508670cf 107 byte bDisplayDot; /*
alexander0707 5:5c9b508670cf 108 * Description :
alexander0707 5:5c9b508670cf 109 */
alexander0707 5:5c9b508670cf 110
alexander0707 5:5c9b508670cf 111 byte bMainState; /*
alexander0707 5:5c9b508670cf 112 * Description : Hauptzustand
alexander0707 5:5c9b508670cf 113 */
alexander0707 5:5c9b508670cf 114
alexander0707 6:4e55101c65f4 115 byte bTimeLong;/*
alexander0707 6:4e55101c65f4 116 * Description : Ob Taste bereits lange gedrückt war
alexander0707 6:4e55101c65f4 117 */
alexander0707 6:4e55101c65f4 118
alexander0707 13:b1d6b2285b13 119 byte bSizeData;/*
alexander0707 13:b1d6b2285b13 120 * Description : Größe der Daten
alexander0707 13:b1d6b2285b13 121 */
alexander0707 13:b1d6b2285b13 122 byte *pUartData; /*
alexander0707 13:b1d6b2285b13 123 * Description : pointer to data
alexander0707 13:b1d6b2285b13 124 */
alexander0707 13:b1d6b2285b13 125
alexander0707 5:5c9b508670cf 126
prof_al 0:5ac32d240694 127 word wSerial; /*
prof_al 0:5ac32d240694 128 * Description : serielles Ausgaberegister
prof_al 0:5ac32d240694 129 */
prof_al 0:5ac32d240694 130
alexander0707 5:5c9b508670cf 131 word wClockShow; /*
alexander0707 5:5c9b508670cf 132 *Description : Timer für verstrichene Zeit
alexander0707 5:5c9b508670cf 133 */
alexander0707 5:5c9b508670cf 134
alexander0707 5:5c9b508670cf 135 word wDelayGame; /*
alexander0707 5:5c9b508670cf 136 * Description : Verzögerungstimer
alexander0707 5:5c9b508670cf 137 */
alexander0707 5:5c9b508670cf 138
alexander0707 5:5c9b508670cf 139 word wPotiWert; /*
alexander0707 5:5c9b508670cf 140 * Description : Wert des Potis
alexander0707 5:5c9b508670cf 141 */
alexander0707 5:5c9b508670cf 142
alexander0707 5:5c9b508670cf 143 word wVorgabeWert; /*
alexander0707 14:88379565eac6 144 * Description : eingestellter Vorgabewert
alexander0707 5:5c9b508670cf 145 */
alexander0707 5:5c9b508670cf 146
alexander0707 10:fdd52c601fcc 147 int nDiffWert; /*
alexander0707 6:4e55101c65f4 148 * Description : Differenz zwischen Vorgabe und Eingang
alexander0707 6:4e55101c65f4 149 */
alexander0707 6:4e55101c65f4 150
alexander0707 14:88379565eac6 151 word wSizeData; /*
alexander0707 14:88379565eac6 152 * Description : Größe der empfangenen Daten
alexander0707 14:88379565eac6 153 */
alexander0707 14:88379565eac6 154
alexander0707 19:8fdd91276de8 155 word wTimerDot; /*
alexander0707 19:8fdd91276de8 156 * Description : Zähler für Dots
alexander0707 19:8fdd91276de8 157 */
alexander0707 19:8fdd91276de8 158
alexander0707 14:88379565eac6 159
prof_al 0:5ac32d240694 160 /* Bitmuster */
prof_al 0:5ac32d240694 161 const byte abZiffer[] = {nZiffer0, nZiffer1, nZiffer2, nZiffer3, nZiffer4, nZiffer5, nZiffer6, nZiffer7, nZiffer8, nZiffer9, nZifferA, nZifferB, nZifferC, nZifferD, nZifferE, nZifferF, nZifferOff};
alexander0707 12:bd1417475c5f 162 //const byte abBargraph[] = {~Bit0, ~(Bit0|Bit1), ~(Bit0|Bit1|Bit2), ~(Bit0|Bit1|Bit2|Bit3), 0x0f};
alexander0707 19:8fdd91276de8 163 byte abTxBuffer[60];
prof_al 0:5ac32d240694 164
prof_al 0:5ac32d240694 165
prof_al 0:5ac32d240694 166 void vShiftLoad(word wLoad){
prof_al 0:5ac32d240694 167 word wMask = Bit15;
prof_al 0:5ac32d240694 168 pinLoad = 0;
prof_al 0:5ac32d240694 169 while(wMask){
prof_al 0:5ac32d240694 170 if(wMask & wLoad) pinSdo = 1;
prof_al 0:5ac32d240694 171 else pinSdo = 0;
prof_al 0:5ac32d240694 172 pinSck = 1;
prof_al 0:5ac32d240694 173 wMask >>= 1;
prof_al 0:5ac32d240694 174 pinSck = 0;
prof_al 0:5ac32d240694 175 }
prof_al 0:5ac32d240694 176 pinLoad = 1;
prof_al 0:5ac32d240694 177 }
prof_al 0:5ac32d240694 178
alexander0707 5:5c9b508670cf 179
alexander0707 5:5c9b508670cf 180 byte abDisplayMemory[] = {16,16,16,16}; /* alle Segmente aus */
alexander0707 5:5c9b508670cf 181
alexander0707 6:4e55101c65f4 182 void vDisplayVolt( word w )
alexander0707 5:5c9b508670cf 183 {
alexander0707 5:5c9b508670cf 184 int16 v;
alexander0707 5:5c9b508670cf 185 abDisplayMemory[0] = 16; /* Aus */
alexander0707 8:6f91c39dbabc 186 v = (byte)(w / 1000);
alexander0707 8:6f91c39dbabc 187 abDisplayMemory[1] = v; /* Hunderter */
alexander0707 8:6f91c39dbabc 188 w = w - (v * 1000);
alexander0707 5:5c9b508670cf 189 v = (byte)(w / 100);
alexander0707 8:6f91c39dbabc 190 abDisplayMemory[2] = v; /* Zehner */
alexander0707 5:5c9b508670cf 191 w = w - (v * 100);
alexander0707 5:5c9b508670cf 192 v = (byte)(w / 10);
alexander0707 8:6f91c39dbabc 193 abDisplayMemory[3] = v; /* Einer */
alexander0707 5:5c9b508670cf 194 }
alexander0707 6:4e55101c65f4 195
alexander0707 6:4e55101c65f4 196 void vDisplayDiff( word w )
alexander0707 5:5c9b508670cf 197 {
alexander0707 6:4e55101c65f4 198 int16 v;
alexander0707 6:4e55101c65f4 199 abDisplayMemory[0] = 12; /* "C" */
alexander0707 8:6f91c39dbabc 200 v = (byte)(w / 1000);
alexander0707 8:6f91c39dbabc 201 abDisplayMemory[1] = v; /* Hunderter */
alexander0707 8:6f91c39dbabc 202 w = w - (v * 1000);
alexander0707 6:4e55101c65f4 203 v = (byte)(w / 100);
alexander0707 8:6f91c39dbabc 204 abDisplayMemory[2] = v; /* Zehner */
alexander0707 6:4e55101c65f4 205 w = w - (v * 100);
alexander0707 6:4e55101c65f4 206 v = (byte)(w / 10);
alexander0707 8:6f91c39dbabc 207 abDisplayMemory[3] = v; /* Einer */
alexander0707 6:4e55101c65f4 208 }
alexander0707 6:4e55101c65f4 209
alexander0707 6:4e55101c65f4 210 void vSetForStart( void )
alexander0707 6:4e55101c65f4 211 {
alexander0707 6:4e55101c65f4 212 abDisplayMemory[0] = 16; /* 7-Segment-Display ausschalten */
alexander0707 5:5c9b508670cf 213 abDisplayMemory[1] = 16;
alexander0707 5:5c9b508670cf 214 abDisplayMemory[2] = 16;
alexander0707 5:5c9b508670cf 215 abDisplayMemory[3] = 16;
alexander0707 19:8fdd91276de8 216 wTimerDot = 0;
alexander0707 5:5c9b508670cf 217 bDigit = 0;
alexander0707 6:4e55101c65f4 218 bMainState = enSchwellenwert;
alexander0707 6:4e55101c65f4 219 bDisplayState = enSchwellenwert;
alexander0707 6:4e55101c65f4 220 pinBeep = 1;
alexander0707 6:4e55101c65f4 221 wVorgabeWert = 0;
alexander0707 5:5c9b508670cf 222 }
alexander0707 14:88379565eac6 223
alexander0707 5:5c9b508670cf 224 /* Tastenabfrage */
alexander0707 5:5c9b508670cf 225 void vTasteS1( void ){
alexander0707 16:404bcdd9c518 226 if(pinS1 == 0){ /* User-Taste gedrückt */
alexander0707 16:404bcdd9c518 227 if(bS1Timer < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */
alexander0707 5:5c9b508670cf 228 if(bS1Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */
alexander0707 5:5c9b508670cf 229 //...
alexander0707 5:5c9b508670cf 230 }
alexander0707 16:404bcdd9c518 231 if(bS1Timer == nTastLong){ /* Taste "lange gedrückt" erkannt */
alexander0707 16:404bcdd9c518 232 if(bDisplayState == enSchwellenwert){
alexander0707 6:4e55101c65f4 233 bDisplayState = enVergleich;
alexander0707 6:4e55101c65f4 234 bMainState = enVergleich;
alexander0707 6:4e55101c65f4 235 }
alexander0707 6:4e55101c65f4 236 else{
alexander0707 6:4e55101c65f4 237 bDisplayState = enSchwellenwert;
alexander0707 6:4e55101c65f4 238 bMainState = enSchwellenwert;
alexander0707 6:4e55101c65f4 239 }
alexander0707 6:4e55101c65f4 240 }
alexander0707 6:4e55101c65f4 241 bS1Timer++;
alexander0707 6:4e55101c65f4 242 }
alexander0707 6:4e55101c65f4 243 }
alexander0707 6:4e55101c65f4 244 else{ /* Taste nicht gedrückt */
alexander0707 16:404bcdd9c518 245 if(((bS1Timer >= nTastShort) && (bS1Timer <= nTastLong))){ /* Taste wurde bereits erkannt */
alexander0707 7:94c73e4168d8 246 if(bDisplayState == enSchwellenwert){
alexander0707 5:5c9b508670cf 247 bDisplayState = enPotiAnzeige;
alexander0707 5:5c9b508670cf 248 bMainState = enPotiAnzeige;
alexander0707 5:5c9b508670cf 249 }
alexander0707 5:5c9b508670cf 250 else{
alexander0707 5:5c9b508670cf 251 bDisplayState = enSchwellenwert;
alexander0707 5:5c9b508670cf 252 bMainState= enSchwellenwert;
alexander0707 5:5c9b508670cf 253 }
alexander0707 5:5c9b508670cf 254 }
alexander0707 5:5c9b508670cf 255 bS1Timer = 0;
alexander0707 5:5c9b508670cf 256 }
alexander0707 5:5c9b508670cf 257 }
alexander0707 5:5c9b508670cf 258
alexander0707 5:5c9b508670cf 259 void vTasteS2( void ){
alexander0707 17:c34f14ec2beb 260 if((pinS2 == 0) && bMainState == enSchwellenwert){ /* User-Taste gedrückt */
alexander0707 17:c34f14ec2beb 261 if(bS2Timer < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */
alexander0707 5:5c9b508670cf 262 if(bS2Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */
alexander0707 5:5c9b508670cf 263 //...
alexander0707 5:5c9b508670cf 264 }
alexander0707 17:c34f14ec2beb 265 if(bS2Timer == nTastLong){ /* Taste "lange gedrückt" erkannt */
alexander0707 6:4e55101c65f4 266 bTimeLong = 1;
alexander0707 10:fdd52c601fcc 267 if(wVorgabeWert >=3200) wVorgabeWert = 3300;
alexander0707 10:fdd52c601fcc 268 else wVorgabeWert = wVorgabeWert + 100;
alexander0707 9:b30caa6d008f 269 bS2Timer = bS2Timer - 40;
alexander0707 5:5c9b508670cf 270 }
alexander0707 5:5c9b508670cf 271 bS2Timer++;
alexander0707 5:5c9b508670cf 272 }
alexander0707 5:5c9b508670cf 273 }
alexander0707 5:5c9b508670cf 274 else{ /* Taste nicht gedrückt */
alexander0707 17:c34f14ec2beb 275 if(((bS2Timer >= nTastShort) && (bS2Timer <= nTastLong))){ /* Taste wurde bereits erkannt */
alexander0707 10:fdd52c601fcc 276 if(bTimeLong==0){
alexander0707 10:fdd52c601fcc 277 if(wVorgabeWert >=3290) wVorgabeWert = 3300;
alexander0707 10:fdd52c601fcc 278 else wVorgabeWert = wVorgabeWert + 10;
alexander0707 10:fdd52c601fcc 279 }
alexander0707 5:5c9b508670cf 280 }
alexander0707 5:5c9b508670cf 281 bS2Timer = 0;
alexander0707 14:88379565eac6 282 bTimeLong = 0;
alexander0707 17:c34f14ec2beb 283 }
alexander0707 5:5c9b508670cf 284 }
alexander0707 5:5c9b508670cf 285
alexander0707 5:5c9b508670cf 286 void vTasteS3( void ){
alexander0707 17:c34f14ec2beb 287 if(pinS3 == 0 && bMainState == enSchwellenwert){ /* User-Taste gedrückt */
alexander0707 17:c34f14ec2beb 288 if(bS3Timer < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */
alexander0707 5:5c9b508670cf 289 if(bS3Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */
alexander0707 5:5c9b508670cf 290 //...
alexander0707 5:5c9b508670cf 291 }
alexander0707 17:c34f14ec2beb 292 if(bS3Timer == nTastLong){ /* Taste "lange gedrückt" erkannt */
alexander0707 6:4e55101c65f4 293 bTimeLong = 1;
alexander0707 10:fdd52c601fcc 294 if(wVorgabeWert <=100) wVorgabeWert = 0;
alexander0707 10:fdd52c601fcc 295 else wVorgabeWert = wVorgabeWert - 100;
alexander0707 12:bd1417475c5f 296 bS3Timer = bS3Timer - 40;
alexander0707 5:5c9b508670cf 297 }
alexander0707 5:5c9b508670cf 298 bS3Timer++;
alexander0707 5:5c9b508670cf 299 }
alexander0707 5:5c9b508670cf 300 }
alexander0707 5:5c9b508670cf 301 else{ /* Taste nicht gedrückt */
alexander0707 17:c34f14ec2beb 302 if((bS3Timer >= nTastShort) && (bS3Timer <= nTastLong)){ /* Taste wurde bereits erkannt */
alexander0707 10:fdd52c601fcc 303 if(bTimeLong==0){
alexander0707 10:fdd52c601fcc 304 if(wVorgabeWert <=10) wVorgabeWert = 0;
alexander0707 10:fdd52c601fcc 305 else wVorgabeWert = wVorgabeWert - 10;
alexander0707 10:fdd52c601fcc 306 }
alexander0707 5:5c9b508670cf 307 }
alexander0707 5:5c9b508670cf 308 bS3Timer = 0;
alexander0707 14:88379565eac6 309 bTimeLong = 0;
alexander0707 17:c34f14ec2beb 310 }
alexander0707 5:5c9b508670cf 311 }
alexander0707 5:5c9b508670cf 312
alexander0707 5:5c9b508670cf 313
alexander0707 5:5c9b508670cf 314 void vCheckTasten( void ){
alexander0707 5:5c9b508670cf 315 vTasteS1();
alexander0707 5:5c9b508670cf 316 vTasteS2();
alexander0707 5:5c9b508670cf 317 vTasteS3();
alexander0707 5:5c9b508670cf 318 }
alexander0707 5:5c9b508670cf 319 void vSegmentDigit( void ) //wichtig!!
alexander0707 5:5c9b508670cf 320 {
alexander0707 5:5c9b508670cf 321 bDigit++;
alexander0707 5:5c9b508670cf 322 wSerial = abZiffer[abDisplayMemory[bDigit&0x03]];
alexander0707 5:5c9b508670cf 323 switch(bDisplayState) {
alexander0707 5:5c9b508670cf 324 case enSchwellenwert:
alexander0707 19:8fdd91276de8 325 wTimerDot++; /* Zähler für Punktwechsel */
alexander0707 6:4e55101c65f4 326 vDisplayVolt(wVorgabeWert);
alexander0707 19:8fdd91276de8 327 if(wTimerDot == 400) {
alexander0707 19:8fdd91276de8 328 wDelayGame=200;
alexander0707 19:8fdd91276de8 329 wTimerDot = 0;
alexander0707 18:6f0897438c03 330 }
alexander0707 18:6f0897438c03 331 if(wDelayGame!=0){
alexander0707 7:94c73e4168d8 332 if((bDigit&0x03) == 0x01) {
alexander0707 7:94c73e4168d8 333 wSerial = wSerial & ~nSegH; /* Punktanzeigen */
alexander0707 18:6f0897438c03 334 }
alexander0707 18:6f0897438c03 335 wDelayGame--;
alexander0707 5:5c9b508670cf 336 }
alexander0707 5:5c9b508670cf 337 break;
alexander0707 5:5c9b508670cf 338 case enPotiAnzeige:
alexander0707 6:4e55101c65f4 339 vDisplayVolt(wPotiWert);
alexander0707 5:5c9b508670cf 340 if((bDigit&0x03) == 0x01) { /* Dezimalpunkt setzen */
alexander0707 5:5c9b508670cf 341 wSerial = wSerial & ~nSegH;
alexander0707 5:5c9b508670cf 342 }
alexander0707 5:5c9b508670cf 343 break;
alexander0707 5:5c9b508670cf 344 case enVergleich:
alexander0707 10:fdd52c601fcc 345 vDisplayDiff(nDiffWert);
alexander0707 5:5c9b508670cf 346 if((bDigit&0x03) == 0x01) { /* Dezimalpunkt setzen */
alexander0707 5:5c9b508670cf 347 wSerial = wSerial & ~nSegH;
alexander0707 5:5c9b508670cf 348 }
alexander0707 5:5c9b508670cf 349 break;
alexander0707 5:5c9b508670cf 350 }
alexander0707 5:5c9b508670cf 351 vShiftLoad(((wSerial << 8) & 0xfff0)| (1 << (bDigit&0x03)));
alexander0707 5:5c9b508670cf 352 }
alexander0707 5:5c9b508670cf 353
alexander0707 13:b1d6b2285b13 354
alexander0707 13:b1d6b2285b13 355
alexander0707 19:8fdd91276de8 356 Serial stComX(D1,D0); // UART-Kommunikation (Txd(D1)/Rxd(D0)) mit dem PC
alexander0707 13:b1d6b2285b13 357
alexander0707 21:2c1292affc10 358 /*
alexander0707 19:8fdd91276de8 359 byte SYS_vStartComX( word wSize, byte *pData ){ // Start einer Übertragung
alexander0707 14:88379565eac6 360 byte i;
alexander0707 14:88379565eac6 361 if(wSizeData) i = False;
alexander0707 14:88379565eac6 362 else{
alexander0707 19:8fdd91276de8 363 wSizeData = wSize; // Anzahl der Sendedaten
alexander0707 19:8fdd91276de8 364 pUartData = pData; // Zeiger auf diese Daten
alexander0707 19:8fdd91276de8 365 stComX.putc(*pUartData); // erstes Zeichen senden
alexander0707 14:88379565eac6 366 pUartData++;
alexander0707 14:88379565eac6 367 wSizeData--;
alexander0707 19:8fdd91276de8 368 USART2->CR1 |= USART_CR1_TXEIE; // TXE-Interrupt freigeben
alexander0707 14:88379565eac6 369 i = True;
alexander0707 14:88379565eac6 370 }
alexander0707 14:88379565eac6 371 return i;
alexander0707 14:88379565eac6 372 }
alexander0707 13:b1d6b2285b13 373
alexander0707 13:b1d6b2285b13 374
alexander0707 19:8fdd91276de8 375 // Senderoutine zum COM-Port am PC
alexander0707 19:8fdd91276de8 376 void vIsrTxComX( void ){ // Senderoutine
alexander0707 19:8fdd91276de8 377 if(stComX.writeable()){ // Sende-ISR
alexander0707 19:8fdd91276de8 378 if(bSizeData){ // sind Daten vorhanden ?
alexander0707 19:8fdd91276de8 379 stComX.putc(*pUartData); // daten senden
alexander0707 14:88379565eac6 380 pUartData++;
alexander0707 14:88379565eac6 381 bSizeData--;
alexander0707 14:88379565eac6 382 }
alexander0707 14:88379565eac6 383 else{
alexander0707 19:8fdd91276de8 384 USART2->CR1 &= ~USART_CR1_TXEIE; // Interrupt sperren
alexander0707 14:88379565eac6 385 }
alexander0707 14:88379565eac6 386 }
alexander0707 14:88379565eac6 387 }
alexander0707 14:88379565eac6 388
alexander0707 14:88379565eac6 389
alexander0707 19:8fdd91276de8 390 // Empfangsroutine vom COM-Port des PC
alexander0707 19:8fdd91276de8 391 void vIsrRxComX( void ){ // Empfangsroutine
alexander0707 19:8fdd91276de8 392 if(stComX.readable()){ // Empfangs-ISR
alexander0707 20:0f975b296b67 393 for(int i=60; i>0; i--){
alexander0707 20:0f975b296b67 394 abTxBufferOld[i]=abTxBuffer[i];
alexander0707 20:0f975b296b67 395 }
alexander0707 20:0f975b296b67 396 for(int i=60; i>0; i--){
alexander0707 20:0f975b296b67 397 abTxBuffer[i]=abTxBuffer[i-1];
alexander0707 20:0f975b296b67 398 }
alexander0707 14:88379565eac6 399 abTxBuffer[0] = stComX.getc();
alexander0707 14:88379565eac6 400 SYS_vStartComX(1, &abTxBuffer[0]);
alexander0707 14:88379565eac6 401 }
alexander0707 14:88379565eac6 402 }
alexander0707 21:2c1292affc10 403 */
alexander0707 14:88379565eac6 404
alexander0707 13:b1d6b2285b13 405
alexander0707 13:b1d6b2285b13 406
alexander0707 19:8fdd91276de8 407 void vComA(void){
alexander0707 19:8fdd91276de8 408 if(abTxBuffer[0]=='a'){
alexander0707 19:8fdd91276de8 409 if(bMainState==enSchwellenwert) {
alexander0707 19:8fdd91276de8 410 bDisplayState = enPotiAnzeige;
alexander0707 19:8fdd91276de8 411 bMainState = enPotiAnzeige;
alexander0707 19:8fdd91276de8 412 }
alexander0707 20:0f975b296b67 413 else if(bMainState==enPotiAnzeige) {
alexander0707 19:8fdd91276de8 414 bDisplayState = enVergleich;
alexander0707 19:8fdd91276de8 415 bMainState = enVergleich;
alexander0707 19:8fdd91276de8 416 }
alexander0707 20:0f975b296b67 417 else {
alexander0707 19:8fdd91276de8 418 bDisplayState = enSchwellenwert;
alexander0707 19:8fdd91276de8 419 bMainState = enSchwellenwert;
alexander0707 19:8fdd91276de8 420 }
alexander0707 19:8fdd91276de8 421 }
alexander0707 19:8fdd91276de8 422 }
alexander0707 13:b1d6b2285b13 423
alexander0707 19:8fdd91276de8 424 void vComPlus(void){
alexander0707 19:8fdd91276de8 425 if(abTxBuffer[0]=='+'){
alexander0707 19:8fdd91276de8 426 if(wVorgabeWert >=3290) wVorgabeWert = 3300;
alexander0707 19:8fdd91276de8 427 else wVorgabeWert = wVorgabeWert + 10;
alexander0707 19:8fdd91276de8 428 }
alexander0707 19:8fdd91276de8 429 }
alexander0707 19:8fdd91276de8 430
alexander0707 19:8fdd91276de8 431 void vComMinus(void){
alexander0707 19:8fdd91276de8 432 if(abTxBuffer[0]=='-'){
alexander0707 19:8fdd91276de8 433 if(wVorgabeWert <=10) wVorgabeWert = 0;
alexander0707 19:8fdd91276de8 434 else wVorgabeWert = wVorgabeWert - 10;;
alexander0707 19:8fdd91276de8 435 }
alexander0707 19:8fdd91276de8 436 }
alexander0707 19:8fdd91276de8 437
alexander0707 19:8fdd91276de8 438 void vCheckCom(void){
alexander0707 22:5600f9b29a51 439 vComA();
alexander0707 22:5600f9b29a51 440 vComPlus();
alexander0707 22:5600f9b29a51 441 vComMinus();
alexander0707 19:8fdd91276de8 442 }
alexander0707 13:b1d6b2285b13 443
alexander0707 13:b1d6b2285b13 444
prof_al 0:5ac32d240694 445 /***************************************************************************
prof_al 0:5ac32d240694 446 * main()
prof_al 0:5ac32d240694 447 ***************************************************************************/
prof_al 0:5ac32d240694 448 int main() {
prof_al 0:5ac32d240694 449 /* Variablen initialisieren */
alexander0707 6:4e55101c65f4 450 vSetForStart();
alexander0707 13:b1d6b2285b13 451
alexander0707 13:b1d6b2285b13 452
alexander0707 14:88379565eac6 453 //Seriel.begin(9600);
alexander0707 5:5c9b508670cf 454
alexander0707 14:88379565eac6 455
alexander0707 6:4e55101c65f4 456 while(1) {
alexander0707 10:fdd52c601fcc 457 wPotiWert = pinPoti*3300;
alexander0707 6:4e55101c65f4 458 vCheckTasten();
alexander0707 10:fdd52c601fcc 459 nDiffWert = wVorgabeWert - wPotiWert;
alexander0707 14:88379565eac6 460
alexander0707 22:5600f9b29a51 461 if(stComX.readable()) {
alexander0707 22:5600f9b29a51 462 abTxBuffer[0]=stComX.getc();
alexander0707 23:7b9ec8cd081d 463 vCheckCom();
alexander0707 23:7b9ec8cd081d 464 }
alexander0707 14:88379565eac6 465
alexander0707 5:5c9b508670cf 466 switch(bMainState) {
alexander0707 6:4e55101c65f4 467 case enSchwellenwert:
alexander0707 12:bd1417475c5f 468 pinBeep = 1;
alexander0707 5:5c9b508670cf 469 break;
alexander0707 6:4e55101c65f4 470 case enPotiAnzeige:
alexander0707 12:bd1417475c5f 471 pinBeep = 1;
alexander0707 5:5c9b508670cf 472 break;
alexander0707 6:4e55101c65f4 473 case enVergleich:
alexander0707 10:fdd52c601fcc 474 if(nDiffWert<0) pinBeep=0;
alexander0707 6:4e55101c65f4 475 else pinBeep=1;
alexander0707 5:5c9b508670cf 476 break;
prof_al 0:5ac32d240694 477 }
alexander0707 5:5c9b508670cf 478 vSegmentDigit();
alexander0707 6:4e55101c65f4 479 wait_us(nCircleTime);
prof_al 0:5ac32d240694 480 }
alexander0707 5:5c9b508670cf 481 }