Versuch 02 übernommen und angefangen es für Versuch 03 abzuwandeln

Dependencies:   mbed

Committer:
alexander0707
Date:
Sun Dec 04 00:14:49 2022 +0000
Revision:
5:5c9b508670cf
Parent:
4:ab3f709c4d2e
Nur mal grob angepasstes Skript vom Versuch02

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
prof_al 0:5ac32d240694 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 5:5c9b508670cf 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 5:5c9b508670cf 49 #define nTastLong 600 /* Taste 1.5 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 5:5c9b508670cf 103 byte bDisplayState; /*
alexander0707 5:5c9b508670cf 104 * Description :
alexander0707 5:5c9b508670cf 105 */
alexander0707 5:5c9b508670cf 106 const byte enSchwellenwert=0x00;
alexander0707 5:5c9b508670cf 107 const byte enPotiAnzeige = 0x01;
alexander0707 5:5c9b508670cf 108 const byte enVergleich = 0x02;
alexander0707 5:5c9b508670cf 109 //const byte enShowError = 0x03;
alexander0707 5:5c9b508670cf 110 //const byte enWaitForRun = 0x04;
alexander0707 5:5c9b508670cf 111
alexander0707 5:5c9b508670cf 112
alexander0707 5:5c9b508670cf 113 byte bState; /*
alexander0707 5:5c9b508670cf 114 * Description :
alexander0707 5:5c9b508670cf 115 */
alexander0707 5:5c9b508670cf 116
alexander0707 5:5c9b508670cf 117 byte bTimerDot; /*
alexander0707 5:5c9b508670cf 118 * Description : Zähler für Dots
alexander0707 5:5c9b508670cf 119 */
alexander0707 5:5c9b508670cf 120
alexander0707 5:5c9b508670cf 121 byte bHotKey; /*
alexander0707 5:5c9b508670cf 122 * Description : Auswahl der Taste
alexander0707 5:5c9b508670cf 123 */
alexander0707 5:5c9b508670cf 124
alexander0707 5:5c9b508670cf 125 byte bDisplayDot; /*
alexander0707 5:5c9b508670cf 126 * Description :
alexander0707 5:5c9b508670cf 127 */
alexander0707 5:5c9b508670cf 128
alexander0707 5:5c9b508670cf 129 byte bMainState; /*
alexander0707 5:5c9b508670cf 130 * Description : Hauptzustand
alexander0707 5:5c9b508670cf 131 */
alexander0707 5:5c9b508670cf 132
alexander0707 5:5c9b508670cf 133 byte bBeepTime; /*
alexander0707 5:5c9b508670cf 134 * Description : Tondauer
alexander0707 5:5c9b508670cf 135 */
alexander0707 5:5c9b508670cf 136
alexander0707 5:5c9b508670cf 137 byte bEinstellungsModus;/*
alexander0707 5:5c9b508670cf 138 * Description : Einstellungszustand
alexander0707 5:5c9b508670cf 139 */
alexander0707 5:5c9b508670cf 140
alexander0707 5:5c9b508670cf 141 byte bSchwellenwertVergleich;/*
alexander0707 5:5c9b508670cf 142 * Description : Einstellungszustand
alexander0707 5:5c9b508670cf 143 */
alexander0707 5:5c9b508670cf 144
alexander0707 5:5c9b508670cf 145
prof_al 0:5ac32d240694 146 word wSerial; /*
prof_al 0:5ac32d240694 147 * Description : serielles Ausgaberegister
prof_al 0:5ac32d240694 148 */
prof_al 0:5ac32d240694 149
alexander0707 5:5c9b508670cf 150 word wClockTime; /*
alexander0707 5:5c9b508670cf 151 *Description : Timer für verstrichene Zeit
alexander0707 5:5c9b508670cf 152 */
alexander0707 5:5c9b508670cf 153
alexander0707 5:5c9b508670cf 154 word wClockShow; /*
alexander0707 5:5c9b508670cf 155 *Description : Timer für verstrichene Zeit
alexander0707 5:5c9b508670cf 156 */
alexander0707 5:5c9b508670cf 157
alexander0707 5:5c9b508670cf 158 word wDelayGame; /*
alexander0707 5:5c9b508670cf 159 * Description : Verzögerungstimer
alexander0707 5:5c9b508670cf 160 */
alexander0707 5:5c9b508670cf 161
alexander0707 5:5c9b508670cf 162 word wPotiWert; /*
alexander0707 5:5c9b508670cf 163 * Description : Wert des Potis
alexander0707 5:5c9b508670cf 164 */
alexander0707 5:5c9b508670cf 165
alexander0707 5:5c9b508670cf 166 word wVorgabeWert; /*
alexander0707 5:5c9b508670cf 167 * Description : engestellter Vorgabewert
alexander0707 5:5c9b508670cf 168 */
alexander0707 5:5c9b508670cf 169
prof_al 0:5ac32d240694 170 /* Bitmuster */
prof_al 0:5ac32d240694 171 const byte abZiffer[] = {nZiffer0, nZiffer1, nZiffer2, nZiffer3, nZiffer4, nZiffer5, nZiffer6, nZiffer7, nZiffer8, nZiffer9, nZifferA, nZifferB, nZifferC, nZifferD, nZifferE, nZifferF, nZifferOff};
prof_al 0:5ac32d240694 172 const byte abBargraph[] = {~Bit0, ~(Bit0|Bit1), ~(Bit0|Bit1|Bit2), ~(Bit0|Bit1|Bit2|Bit3), 0x0f};
prof_al 0:5ac32d240694 173
prof_al 0:5ac32d240694 174
prof_al 0:5ac32d240694 175 void vShiftLoad(word wLoad){
prof_al 0:5ac32d240694 176 word wMask = Bit15;
prof_al 0:5ac32d240694 177 pinLoad = 0;
prof_al 0:5ac32d240694 178 while(wMask){
prof_al 0:5ac32d240694 179 if(wMask & wLoad) pinSdo = 1;
prof_al 0:5ac32d240694 180 else pinSdo = 0;
prof_al 0:5ac32d240694 181 pinSck = 1;
prof_al 0:5ac32d240694 182 wMask >>= 1;
prof_al 0:5ac32d240694 183 pinSck = 0;
prof_al 0:5ac32d240694 184 }
prof_al 0:5ac32d240694 185 pinLoad = 1;
prof_al 0:5ac32d240694 186 }
prof_al 0:5ac32d240694 187
alexander0707 5:5c9b508670cf 188
alexander0707 5:5c9b508670cf 189 byte abDisplayMemory[] = {16,16,16,16}; /* alle Segmente aus */
alexander0707 5:5c9b508670cf 190
alexander0707 5:5c9b508670cf 191 void vDisplayClock( word w )
alexander0707 5:5c9b508670cf 192 {
alexander0707 5:5c9b508670cf 193 int16 v;
alexander0707 5:5c9b508670cf 194 abDisplayMemory[0] = 16; /* Aus */
alexander0707 5:5c9b508670cf 195 v = (byte)(w / 100);
alexander0707 5:5c9b508670cf 196 abDisplayMemory[1] = v; /* Hunderter */
alexander0707 5:5c9b508670cf 197 w = w - (v * 100);
alexander0707 5:5c9b508670cf 198 v = (byte)(w / 10);
alexander0707 5:5c9b508670cf 199 abDisplayMemory[2] = v; /* Zehner */
alexander0707 5:5c9b508670cf 200 w = w - (v * 10);
alexander0707 5:5c9b508670cf 201 abDisplayMemory[3] = (byte)w; /* Einer */
alexander0707 5:5c9b508670cf 202 }
alexander0707 5:5c9b508670cf 203 /*
alexander0707 5:5c9b508670cf 204 void vSetWaitForStart( void )
alexander0707 5:5c9b508670cf 205 {
alexander0707 5:5c9b508670cf 206 abDisplayMemory[0] = 16; /* 7-Segment-Display ausschalten
alexander0707 5:5c9b508670cf 207 abDisplayMemory[1] = 16;
alexander0707 5:5c9b508670cf 208 abDisplayMemory[2] = 16;
alexander0707 5:5c9b508670cf 209 abDisplayMemory[3] = 16;
alexander0707 5:5c9b508670cf 210 bDisplayState = enWaitForStart;
alexander0707 5:5c9b508670cf 211 bTimerDot = 0;
alexander0707 5:5c9b508670cf 212 bDigit = 0;
alexander0707 5:5c9b508670cf 213 }
alexander0707 5:5c9b508670cf 214
alexander0707 5:5c9b508670cf 215 void vSetRunClock( void )
alexander0707 5:5c9b508670cf 216 {
alexander0707 5:5c9b508670cf 217 wClockTime = 0;
alexander0707 5:5c9b508670cf 218 bDigit = 0;
alexander0707 5:5c9b508670cf 219 abDisplayMemory[0] = 16; /* 7-Segment-Display ausschalten
alexander0707 5:5c9b508670cf 220 abDisplayMemory[1] = 0;
alexander0707 5:5c9b508670cf 221 abDisplayMemory[2] = 0;
alexander0707 5:5c9b508670cf 222 abDisplayMemory[3] = 0;
alexander0707 5:5c9b508670cf 223 bDisplayState = enRunClock;
alexander0707 5:5c9b508670cf 224 }
alexander0707 5:5c9b508670cf 225 */
alexander0707 5:5c9b508670cf 226 /*
alexander0707 5:5c9b508670cf 227 byte bCheckTasten( byte bState )
alexander0707 5:5c9b508670cf 228 {
alexander0707 5:5c9b508670cf 229 if((pinS1 == 0) || (pinS2 == 0) || (pinS3 == 0)) { /* Tastendruck erkannt
alexander0707 5:5c9b508670cf 230 wClockShow = 1200;
alexander0707 5:5c9b508670cf 231 if((pinS1 == 0) && (bHotKey == 0)) {
alexander0707 5:5c9b508670cf 232 wDelayGame = 0;
alexander0707 5:5c9b508670cf 233 bState = enShowResult;
alexander0707 5:5c9b508670cf 234 bDisplayState = enShowResult;
alexander0707 5:5c9b508670cf 235 } else if((pinS2 == 0) && (bHotKey == 1)) {
alexander0707 5:5c9b508670cf 236 wDelayGame = 0;
alexander0707 5:5c9b508670cf 237 bState = enShowResult;
alexander0707 5:5c9b508670cf 238 bDisplayState = enShowResult;
alexander0707 5:5c9b508670cf 239 } else if((pinS3 == 0) && (bHotKey == 2)) {
alexander0707 5:5c9b508670cf 240 wDelayGame = 0;
alexander0707 5:5c9b508670cf 241 bState = enShowResult;
alexander0707 5:5c9b508670cf 242 bDisplayState = enShowResult;
alexander0707 5:5c9b508670cf 243 } else {
alexander0707 5:5c9b508670cf 244 wDelayGame = 200;
alexander0707 5:5c9b508670cf 245 abDisplayMemory[1] = 15;
alexander0707 5:5c9b508670cf 246 abDisplayMemory[2] = 15;
alexander0707 5:5c9b508670cf 247 abDisplayMemory[3] = 15;
alexander0707 5:5c9b508670cf 248 bState = enShowError;
alexander0707 5:5c9b508670cf 249 bDisplayState = enShowResult;
alexander0707 5:5c9b508670cf 250 pinBeep = 0;
alexander0707 5:5c9b508670cf 251 }
alexander0707 5:5c9b508670cf 252 }
alexander0707 5:5c9b508670cf 253 return bState;
alexander0707 5:5c9b508670cf 254 }
alexander0707 5:5c9b508670cf 255 */
alexander0707 5:5c9b508670cf 256 /* Tastenabfrage */
alexander0707 5:5c9b508670cf 257 void vTasteS1( void ){
alexander0707 5:5c9b508670cf 258 if(pinS1 == 0){ /* User-Taste gedrückt */
alexander0707 5:5c9b508670cf 259 if(bS1Timer < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */
alexander0707 5:5c9b508670cf 260 if(bS1Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */
alexander0707 5:5c9b508670cf 261 //...
alexander0707 5:5c9b508670cf 262 }
alexander0707 5:5c9b508670cf 263 if(bS1Timer == nTastLong){ /* Taste "lange gedrückt" erkannt */
alexander0707 5:5c9b508670cf 264 if(bDisplayState = enSchwellenwert){
alexander0707 5:5c9b508670cf 265 bDisplayState = enPotiAnzeige;
alexander0707 5:5c9b508670cf 266 bMainState = enPotiAnzeige;
alexander0707 5:5c9b508670cf 267 }
alexander0707 5:5c9b508670cf 268 else{
alexander0707 5:5c9b508670cf 269 bDisplayState = enSchwellenwert;
alexander0707 5:5c9b508670cf 270 bMainState= enSchwellenwert;
alexander0707 5:5c9b508670cf 271 }
alexander0707 5:5c9b508670cf 272 }
alexander0707 5:5c9b508670cf 273 bS1Timer++;
alexander0707 5:5c9b508670cf 274 }
alexander0707 5:5c9b508670cf 275 }
alexander0707 5:5c9b508670cf 276 else{ /* Taste nicht gedrückt */
alexander0707 5:5c9b508670cf 277 if((bS1Timer >= nTastShort) && (bS1Timer <= nTastLong)){ /* Taste wurde bereits erkannt */
alexander0707 5:5c9b508670cf 278 if(bDisplayState = enSchwellenwert || bDisplayState = enPotiAnzeige){
alexander0707 5:5c9b508670cf 279 bDisplayState = enVergleich;
alexander0707 5:5c9b508670cf 280 bMainState = enVergleich;
alexander0707 5:5c9b508670cf 281 }
alexander0707 5:5c9b508670cf 282 else{
alexander0707 5:5c9b508670cf 283 bDisplayState = enSchwellenwert;
alexander0707 5:5c9b508670cf 284 bMainState = enSchwellenwert;
alexander0707 5:5c9b508670cf 285 }
alexander0707 5:5c9b508670cf 286 }
alexander0707 5:5c9b508670cf 287 bS1Timer = 0;
alexander0707 5:5c9b508670cf 288 }
alexander0707 5:5c9b508670cf 289 }
alexander0707 5:5c9b508670cf 290
alexander0707 5:5c9b508670cf 291 void vTasteS2( void ){
alexander0707 5:5c9b508670cf 292 if(pinS2 == 0){ /* User-Taste gedrückt */
alexander0707 5:5c9b508670cf 293 if(bS2Timer < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */
alexander0707 5:5c9b508670cf 294 if(bS2Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */
alexander0707 5:5c9b508670cf 295 //...
alexander0707 5:5c9b508670cf 296 }
alexander0707 5:5c9b508670cf 297 if(bS2Timer == nTastLong){ /* Taste "lange gedrückt" erkannt */
alexander0707 5:5c9b508670cf 298 //...
alexander0707 5:5c9b508670cf 299 }
alexander0707 5:5c9b508670cf 300 bS2Timer++;
alexander0707 5:5c9b508670cf 301 }
alexander0707 5:5c9b508670cf 302 }
alexander0707 5:5c9b508670cf 303 else{ /* Taste nicht gedrückt */
alexander0707 5:5c9b508670cf 304 if((bS2Timer >= nTastShort) && (bS2Timer <= nTastLong)){ /* Taste wurde bereits erkannt */
alexander0707 5:5c9b508670cf 305 //...
alexander0707 5:5c9b508670cf 306 }
alexander0707 5:5c9b508670cf 307 bS2Timer = 0;
alexander0707 5:5c9b508670cf 308 }
alexander0707 5:5c9b508670cf 309 }
alexander0707 5:5c9b508670cf 310
alexander0707 5:5c9b508670cf 311 void vTasteS3( void ){
alexander0707 5:5c9b508670cf 312 if(pinS3 == 0){ /* User-Taste gedrückt */
alexander0707 5:5c9b508670cf 313 if(bS3Timer < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */
alexander0707 5:5c9b508670cf 314 if(bS3Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */
alexander0707 5:5c9b508670cf 315 //...
alexander0707 5:5c9b508670cf 316 }
alexander0707 5:5c9b508670cf 317 if(bS3Timer == nTastLong){ /* Taste "lange gedrückt" erkannt */
alexander0707 5:5c9b508670cf 318 //...
alexander0707 5:5c9b508670cf 319 }
alexander0707 5:5c9b508670cf 320 bS3Timer++;
alexander0707 5:5c9b508670cf 321 }
alexander0707 5:5c9b508670cf 322 }
alexander0707 5:5c9b508670cf 323 else{ /* Taste nicht gedrückt */
alexander0707 5:5c9b508670cf 324 if((bS3Timer >= nTastShort) && (bS3Timer <= nTastLong)){ /* Taste wurde bereits erkannt */
alexander0707 5:5c9b508670cf 325 //...
alexander0707 5:5c9b508670cf 326 }
alexander0707 5:5c9b508670cf 327 bS3Timer = 0;
alexander0707 5:5c9b508670cf 328 }
alexander0707 5:5c9b508670cf 329 }
alexander0707 5:5c9b508670cf 330
alexander0707 5:5c9b508670cf 331
alexander0707 5:5c9b508670cf 332
alexander0707 5:5c9b508670cf 333 void vCheckTasten( void ){
alexander0707 5:5c9b508670cf 334 vTasteS1();
alexander0707 5:5c9b508670cf 335 vTasteS2();
alexander0707 5:5c9b508670cf 336 vTasteS3();
alexander0707 5:5c9b508670cf 337 }
alexander0707 5:5c9b508670cf 338 void vSegmentDigit( void ) //wichtig!!
alexander0707 5:5c9b508670cf 339 {
alexander0707 5:5c9b508670cf 340 bDigit++;
alexander0707 5:5c9b508670cf 341 wSerial = abZiffer[abDisplayMemory[bDigit&0x03]];
alexander0707 5:5c9b508670cf 342 switch(bDisplayState) {
alexander0707 5:5c9b508670cf 343 case enSchwellenwert:
alexander0707 5:5c9b508670cf 344 bTimerDot++; /* Zähler für Punktwechsel */
alexander0707 5:5c9b508670cf 345 if(bTimerDot == 50) {
alexander0707 5:5c9b508670cf 346 bTimerDot = 0;
alexander0707 5:5c9b508670cf 347 bDisplayDot = (bDisplayDot + 1) & 0x03;
alexander0707 5:5c9b508670cf 348 }
alexander0707 5:5c9b508670cf 349 if(bDisplayDot == (bDigit&0x03)) {
alexander0707 5:5c9b508670cf 350 wSerial = wSerial & ~nSegH; /* Punktanzeigen */
alexander0707 5:5c9b508670cf 351 }
alexander0707 5:5c9b508670cf 352 break;
alexander0707 5:5c9b508670cf 353 case enPotiAnzeige:
alexander0707 5:5c9b508670cf 354 if((bDigit&0x03) == 0x03){ /* Ablauf von 10 ms */
alexander0707 5:5c9b508670cf 355 wClockTime++;
alexander0707 5:5c9b508670cf 356 if(wClockTime > 999) {
alexander0707 5:5c9b508670cf 357 wClockTime = 0;
alexander0707 5:5c9b508670cf 358 }
alexander0707 5:5c9b508670cf 359 vDisplayClock(wClockTime);
alexander0707 5:5c9b508670cf 360 }
alexander0707 5:5c9b508670cf 361 if((bDigit&0x03) == 0x01) { /* Dezimalpunkt setzen */
alexander0707 5:5c9b508670cf 362 wSerial = wSerial & ~nSegH;
alexander0707 5:5c9b508670cf 363 }
alexander0707 5:5c9b508670cf 364 break;
alexander0707 5:5c9b508670cf 365 case enVergleich:
alexander0707 5:5c9b508670cf 366 if((bDigit&0x03) == 0x01) { /* Dezimalpunkt setzen */
alexander0707 5:5c9b508670cf 367 wSerial = wSerial & ~nSegH;
alexander0707 5:5c9b508670cf 368 }
alexander0707 5:5c9b508670cf 369 break;
alexander0707 5:5c9b508670cf 370 }
alexander0707 5:5c9b508670cf 371 vShiftLoad(((wSerial << 8) & 0xfff0)| (1 << (bDigit&0x03)));
alexander0707 5:5c9b508670cf 372 }
alexander0707 5:5c9b508670cf 373
alexander0707 5:5c9b508670cf 374 void vBargraph(byte bTaste){
alexander0707 5:5c9b508670cf 375 switch(bTaste){
alexander0707 5:5c9b508670cf 376 case 0 :
alexander0707 5:5c9b508670cf 377 bLedShield =0b1110;
alexander0707 5:5c9b508670cf 378 break;
alexander0707 5:5c9b508670cf 379 case 1 :
alexander0707 5:5c9b508670cf 380 bLedShield =0b1101;
alexander0707 5:5c9b508670cf 381 break;
alexander0707 5:5c9b508670cf 382 case 2 :
alexander0707 5:5c9b508670cf 383 bLedShield =0b1011;
alexander0707 5:5c9b508670cf 384 break;
alexander0707 5:5c9b508670cf 385 }
alexander0707 5:5c9b508670cf 386 }
alexander0707 5:5c9b508670cf 387
prof_al 0:5ac32d240694 388 /***************************************************************************
prof_al 0:5ac32d240694 389 * main()
prof_al 0:5ac32d240694 390 ***************************************************************************/
prof_al 0:5ac32d240694 391 int main() {
prof_al 0:5ac32d240694 392 /* Variablen initialisieren */
alexander0707 5:5c9b508670cf 393 byte bRandomTaste = 0;
alexander0707 5:5c9b508670cf 394 word wRandomClock = 0;
alexander0707 5:5c9b508670cf 395 bMainState = enWaitForStart;
alexander0707 5:5c9b508670cf 396 bDisplayState = enWaitForStart;
alexander0707 5:5c9b508670cf 397 pinBeep = 1;
alexander0707 5:5c9b508670cf 398 vSetWaitForStart();
alexander0707 5:5c9b508670cf 399
alexander0707 5:5c9b508670cf 400 Seriel.begin(9600);
alexander0707 5:5c9b508670cf 401
alexander0707 5:5c9b508670cf 402 while(1) {
alexander0707 5:5c9b508670cf 403 bRandomTaste++;
alexander0707 5:5c9b508670cf 404 if(bRandomTaste > 2) bRandomTaste = 0; /* zufällige LED/Taste bestimmen */
alexander0707 5:5c9b508670cf 405 wRandomClock++;
alexander0707 5:5c9b508670cf 406 if(wRandomClock > 800) wRandomClock = 0; /* Zufallszeit erzeugen */
alexander0707 5:5c9b508670cf 407 switch(bMainState) {
alexander0707 5:5c9b508670cf 408 case enWaitForStart:
alexander0707 5:5c9b508670cf 409 wDelayGame++;
alexander0707 5:5c9b508670cf 410 bLedShield =0b1111;
alexander0707 5:5c9b508670cf 411 if(wDelayGame > 1200) { /* 3 Sekundenminimum */
alexander0707 5:5c9b508670cf 412 wDelayGame = wRandomClock;
alexander0707 5:5c9b508670cf 413 bMainState = enWaitForRun;
alexander0707 5:5c9b508670cf 414 }
alexander0707 5:5c9b508670cf 415 break;
alexander0707 5:5c9b508670cf 416 case enRunClock:
alexander0707 5:5c9b508670cf 417 bBeepTime--;
alexander0707 5:5c9b508670cf 418 if(bBeepTime == 0)pinBeep = 1;
alexander0707 5:5c9b508670cf 419 bMainState = bCheckTasten(enRunClock);
alexander0707 5:5c9b508670cf 420 break;
alexander0707 5:5c9b508670cf 421 case enWaitForRun:
alexander0707 5:5c9b508670cf 422 wDelayGame--;
alexander0707 5:5c9b508670cf 423 if(wDelayGame == 0){
alexander0707 5:5c9b508670cf 424 bMainState = enRunClock;
alexander0707 5:5c9b508670cf 425 bDisplayState = enRunClock;
alexander0707 5:5c9b508670cf 426 bBeepTime = 20;
alexander0707 5:5c9b508670cf 427 bHotKey = bRandomTaste;
alexander0707 5:5c9b508670cf 428 vBargraph(bRandomTaste);
alexander0707 5:5c9b508670cf 429 vSetRunClock();
alexander0707 5:5c9b508670cf 430 pinBeep = 0;
alexander0707 5:5c9b508670cf 431 }
alexander0707 5:5c9b508670cf 432 break;
alexander0707 5:5c9b508670cf 433 case enShowResult:
alexander0707 5:5c9b508670cf 434 wClockShow--;
alexander0707 5:5c9b508670cf 435 if(wClockShow==0){
alexander0707 5:5c9b508670cf 436 bMainState = enWaitForStart;
alexander0707 5:5c9b508670cf 437 bDisplayState = enWaitForStart;
alexander0707 5:5c9b508670cf 438 vSetWaitForStart();
alexander0707 5:5c9b508670cf 439 }
alexander0707 5:5c9b508670cf 440 break;
alexander0707 5:5c9b508670cf 441 case enShowError:
alexander0707 5:5c9b508670cf 442 wDelayGame--;
alexander0707 5:5c9b508670cf 443 if(wDelayGame == 0)pinBeep = 1;
alexander0707 5:5c9b508670cf 444 wClockShow--;
alexander0707 5:5c9b508670cf 445 if(wClockShow==0){
alexander0707 5:5c9b508670cf 446 bMainState = enWaitForStart;
alexander0707 5:5c9b508670cf 447 bDisplayState = enWaitForStart;
alexander0707 5:5c9b508670cf 448 wDelayGame = 0;
alexander0707 5:5c9b508670cf 449 vSetWaitForStart();
alexander0707 5:5c9b508670cf 450 }
alexander0707 5:5c9b508670cf 451 break;
prof_al 0:5ac32d240694 452 }
alexander0707 5:5c9b508670cf 453 vSegmentDigit();
alexander0707 5:5c9b508670cf 454 wait_us(n CircleTime);
prof_al 0:5ac32d240694 455 }
alexander0707 5:5c9b508670cf 456 }