Jens Altenburg
/
HAPO_WS22_Labor1_Template
TH Bingen HAPO Labor 1, Prof. Altenburg, WS2022
main.cpp@0:5ac32d240694, 2022-10-24 (annotated)
- Committer:
- prof_al
- Date:
- Mon Oct 24 11:59:31 2022 +0000
- Revision:
- 0:5ac32d240694
Version 24.10.2022 HAPO Labor1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
prof_al | 0:5ac32d240694 | 1 | /*************************************************************************** |
prof_al | 0:5ac32d240694 | 2 | * Titel : main.c |
prof_al | 0:5ac32d240694 | 3 | * |
prof_al | 0:5ac32d240694 | 4 | * Description : Labormodul "DIBI" |
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 | | | |
prof_al | 0:5ac32d240694 | 13 | ---------------------------------------------------------------------------- |
prof_al | 0:5ac32d240694 | 14 | ****************************************************************************/ |
prof_al | 0:5ac32d240694 | 15 | #include "mbed.h" |
prof_al | 0:5ac32d240694 | 16 | #include "cdef.h" |
prof_al | 0:5ac32d240694 | 17 | |
prof_al | 0:5ac32d240694 | 18 | /* Vereinbarungen zu den Tasteneingängen */ |
prof_al | 0:5ac32d240694 | 19 | DigitalIn pinS1(A1); |
prof_al | 0:5ac32d240694 | 20 | DigitalIn pinS2(A2); |
prof_al | 0:5ac32d240694 | 21 | DigitalIn pinS3(A3); |
prof_al | 0:5ac32d240694 | 22 | |
prof_al | 0:5ac32d240694 | 23 | BusOut bLedShield(D10, D11, D12, D13); |
prof_al | 0:5ac32d240694 | 24 | |
prof_al | 0:5ac32d240694 | 25 | /* Anschlüsse der Schieberegister */ |
prof_al | 0:5ac32d240694 | 26 | DigitalOut pinSdo(PA_9); |
prof_al | 0:5ac32d240694 | 27 | DigitalOut pinSck(PA_8); |
prof_al | 0:5ac32d240694 | 28 | DigitalOut pinLoad(PB_5); |
prof_al | 0:5ac32d240694 | 29 | |
prof_al | 0:5ac32d240694 | 30 | /* ISR */ |
prof_al | 0:5ac32d240694 | 31 | Ticker stTimer; |
prof_al | 0:5ac32d240694 | 32 | |
prof_al | 0:5ac32d240694 | 33 | /*************************************************************************** |
prof_al | 0:5ac32d240694 | 34 | * Defines und Makros * |
prof_al | 0:5ac32d240694 | 35 | ***************************************************************************/ |
prof_al | 0:5ac32d240694 | 36 | #define nTastShort 4 /* Taste 50 Millisekunden gedrückt */ |
prof_al | 0:5ac32d240694 | 37 | #define nTastLong 150 /* Taste 1.5 Sekunden gedrückt */ |
prof_al | 0:5ac32d240694 | 38 | |
prof_al | 0:5ac32d240694 | 39 | #define nSegA 0x01 |
prof_al | 0:5ac32d240694 | 40 | #define nSegB 0x02 |
prof_al | 0:5ac32d240694 | 41 | #define nSegC 0x04 |
prof_al | 0:5ac32d240694 | 42 | #define nSegD 0x08 |
prof_al | 0:5ac32d240694 | 43 | #define nSegE 0x10 |
prof_al | 0:5ac32d240694 | 44 | #define nSegF 0x20 |
prof_al | 0:5ac32d240694 | 45 | #define nSegG 0x40 |
prof_al | 0:5ac32d240694 | 46 | #define nSegH 0x80 |
prof_al | 0:5ac32d240694 | 47 | |
prof_al | 0:5ac32d240694 | 48 | #define nZiffer0 ~(nSegA | nSegB | nSegC | nSegD | nSegE | nSegF) |
prof_al | 0:5ac32d240694 | 49 | #define nZiffer1 ~(nSegB | nSegC) |
prof_al | 0:5ac32d240694 | 50 | #define nZiffer2 ~(nSegA | nSegB | nSegD | nSegE | nSegG) |
prof_al | 0:5ac32d240694 | 51 | #define nZiffer3 ~(nSegA | nSegB | nSegC | nSegD | nSegG) |
prof_al | 0:5ac32d240694 | 52 | #define nZiffer4 ~(nSegB | nSegC | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 53 | #define nZiffer5 ~(nSegA | nSegC | nSegD | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 54 | #define nZiffer6 ~(nSegA | nSegC | nSegD | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 55 | #define nZiffer7 ~(nSegA | nSegB | nSegC) |
prof_al | 0:5ac32d240694 | 56 | #define nZiffer8 ~(nSegA | nSegB | nSegC | nSegD | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 57 | #define nZiffer9 ~(nSegA | nSegB | nSegC | nSegD | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 58 | #define nZifferA ~(nSegA | nSegB | nSegC | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 59 | #define nZifferB ~(nSegC | nSegD | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 60 | #define nZifferC ~(nSegA | nSegD | nSegE | nSegF) |
prof_al | 0:5ac32d240694 | 61 | #define nZifferD ~(nSegB | nSegC | nSegD | nSegE | nSegG) |
prof_al | 0:5ac32d240694 | 62 | #define nZifferE ~(nSegA | nSegD | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 63 | #define nZifferF ~(nSegA | nSegE | nSegF | nSegG) |
prof_al | 0:5ac32d240694 | 64 | #define nZifferOff (nSegA | nSegB | nSegC | nSegD | nSegE | nSegF | nSegG | nSegH) |
prof_al | 0:5ac32d240694 | 65 | |
prof_al | 0:5ac32d240694 | 66 | byte bIdx; /* |
prof_al | 0:5ac32d240694 | 67 | * Description : Index auf Ausgabe |
prof_al | 0:5ac32d240694 | 68 | */ |
prof_al | 0:5ac32d240694 | 69 | |
prof_al | 0:5ac32d240694 | 70 | byte bDigit; /* |
prof_al | 0:5ac32d240694 | 71 | * Description : aktives Digit |
prof_al | 0:5ac32d240694 | 72 | */ |
prof_al | 0:5ac32d240694 | 73 | |
prof_al | 0:5ac32d240694 | 74 | byte bBargraph; /* |
prof_al | 0:5ac32d240694 | 75 | * Description : Bargraph durchschalten |
prof_al | 0:5ac32d240694 | 76 | */ |
prof_al | 0:5ac32d240694 | 77 | |
prof_al | 0:5ac32d240694 | 78 | byte bS1Timer; /* |
prof_al | 0:5ac32d240694 | 79 | * Description : Timer für Taste S1 |
prof_al | 0:5ac32d240694 | 80 | */ |
prof_al | 0:5ac32d240694 | 81 | |
prof_al | 0:5ac32d240694 | 82 | byte bS2Timer; /* |
prof_al | 0:5ac32d240694 | 83 | * Description : Timer für Taste S2 |
prof_al | 0:5ac32d240694 | 84 | */ |
prof_al | 0:5ac32d240694 | 85 | |
prof_al | 0:5ac32d240694 | 86 | byte bS3Timer; /* |
prof_al | 0:5ac32d240694 | 87 | * Description : Timer für Taste S3 |
prof_al | 0:5ac32d240694 | 88 | */ |
prof_al | 0:5ac32d240694 | 89 | |
prof_al | 0:5ac32d240694 | 90 | word wSerial; /* |
prof_al | 0:5ac32d240694 | 91 | * Description : serielles Ausgaberegister |
prof_al | 0:5ac32d240694 | 92 | */ |
prof_al | 0:5ac32d240694 | 93 | |
prof_al | 0:5ac32d240694 | 94 | /* Bitmuster */ |
prof_al | 0:5ac32d240694 | 95 | const byte abZiffer[] = {nZiffer0, nZiffer1, nZiffer2, nZiffer3, nZiffer4, nZiffer5, nZiffer6, nZiffer7, nZiffer8, nZiffer9, nZifferA, nZifferB, nZifferC, nZifferD, nZifferE, nZifferF, nZifferOff}; |
prof_al | 0:5ac32d240694 | 96 | const byte abBargraph[] = {~Bit0, ~(Bit0|Bit1), ~(Bit0|Bit1|Bit2), ~(Bit0|Bit1|Bit2|Bit3), 0x0f}; |
prof_al | 0:5ac32d240694 | 97 | |
prof_al | 0:5ac32d240694 | 98 | |
prof_al | 0:5ac32d240694 | 99 | /* Tastenabfrage */ |
prof_al | 0:5ac32d240694 | 100 | void vTasteS1( void ){ |
prof_al | 0:5ac32d240694 | 101 | if(pinS1 == 0){ /* User-Taste gedrückt */ |
prof_al | 0:5ac32d240694 | 102 | if(bS1Timer < nTastLong+1){ /* Abfrage max. bis Taste lange gedrückt */ |
prof_al | 0:5ac32d240694 | 103 | if(bS1Timer == nTastShort){ /* Taste "kurz gedrückt" erkannt */ |
prof_al | 0:5ac32d240694 | 104 | //... |
prof_al | 0:5ac32d240694 | 105 | } |
prof_al | 0:5ac32d240694 | 106 | if(bS1Timer == nTastLong){ /* Taste "lange gedrückt" erkannt */ |
prof_al | 0:5ac32d240694 | 107 | bIdx--; |
prof_al | 0:5ac32d240694 | 108 | } |
prof_al | 0:5ac32d240694 | 109 | bS1Timer++; |
prof_al | 0:5ac32d240694 | 110 | } |
prof_al | 0:5ac32d240694 | 111 | } |
prof_al | 0:5ac32d240694 | 112 | else{ /* Taste nicht gedrückt */ |
prof_al | 0:5ac32d240694 | 113 | if((bS1Timer >= nTastShort) && (bS1Timer <= nTastLong)){ /* Taste wurde bereits erkannt */ |
prof_al | 0:5ac32d240694 | 114 | bIdx++; |
prof_al | 0:5ac32d240694 | 115 | } |
prof_al | 0:5ac32d240694 | 116 | bS1Timer = 0; |
prof_al | 0:5ac32d240694 | 117 | } |
prof_al | 0:5ac32d240694 | 118 | } |
prof_al | 0:5ac32d240694 | 119 | |
prof_al | 0:5ac32d240694 | 120 | void vTasteS2( void ){ |
prof_al | 0:5ac32d240694 | 121 | } |
prof_al | 0:5ac32d240694 | 122 | |
prof_al | 0:5ac32d240694 | 123 | void vTasteS3( void ){ |
prof_al | 0:5ac32d240694 | 124 | } |
prof_al | 0:5ac32d240694 | 125 | |
prof_al | 0:5ac32d240694 | 126 | |
prof_al | 0:5ac32d240694 | 127 | |
prof_al | 0:5ac32d240694 | 128 | void vCheckTasten( void ){ |
prof_al | 0:5ac32d240694 | 129 | vTasteS1(); |
prof_al | 0:5ac32d240694 | 130 | vTasteS2(); |
prof_al | 0:5ac32d240694 | 131 | vTasteS3(); |
prof_al | 0:5ac32d240694 | 132 | } |
prof_al | 0:5ac32d240694 | 133 | |
prof_al | 0:5ac32d240694 | 134 | /* Ausschieben der 16 Bits für die Anzeige */ |
prof_al | 0:5ac32d240694 | 135 | void vShiftLoad(word wLoad){ |
prof_al | 0:5ac32d240694 | 136 | word wMask = Bit15; |
prof_al | 0:5ac32d240694 | 137 | pinLoad = 0; |
prof_al | 0:5ac32d240694 | 138 | while(wMask){ |
prof_al | 0:5ac32d240694 | 139 | if(wMask & wLoad) pinSdo = 1; |
prof_al | 0:5ac32d240694 | 140 | else pinSdo = 0; |
prof_al | 0:5ac32d240694 | 141 | pinSck = 1; |
prof_al | 0:5ac32d240694 | 142 | wMask >>= 1; |
prof_al | 0:5ac32d240694 | 143 | pinSck = 0; |
prof_al | 0:5ac32d240694 | 144 | } |
prof_al | 0:5ac32d240694 | 145 | pinLoad = 1; |
prof_al | 0:5ac32d240694 | 146 | } |
prof_al | 0:5ac32d240694 | 147 | |
prof_al | 0:5ac32d240694 | 148 | /*************************************************************************** |
prof_al | 0:5ac32d240694 | 149 | * main() |
prof_al | 0:5ac32d240694 | 150 | ***************************************************************************/ |
prof_al | 0:5ac32d240694 | 151 | int main() { |
prof_al | 0:5ac32d240694 | 152 | /* Variablen initialisieren */ |
prof_al | 0:5ac32d240694 | 153 | bIdx = 0; |
prof_al | 0:5ac32d240694 | 154 | bDigit = 0; |
prof_al | 0:5ac32d240694 | 155 | bLedShield = 0x00; |
prof_al | 0:5ac32d240694 | 156 | while(1){ |
prof_al | 0:5ac32d240694 | 157 | vCheckTasten(); |
prof_al | 0:5ac32d240694 | 158 | //wSerial = ???; /* 7-Segmentziffer bestimmen */ |
prof_al | 0:5ac32d240694 | 159 | vShiftLoad(wSerial /* Segmente verschieben und Digit festlegen */); |
prof_al | 0:5ac32d240694 | 160 | //bLedShield = ??? /* Bargraph bestimmen */ |
prof_al | 0:5ac32d240694 | 161 | wait_us(10000); |
prof_al | 0:5ac32d240694 | 162 | } |
prof_al | 0:5ac32d240694 | 163 | } |