Pajić Enil Đenašević Emir
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 DigitalOut ENBL = dp14; 00003 BusOut bDISP (dp23, dp24, dp25); 00004 BusOut dDISP[3] = {dp23, dp24, dp25}; 00005 00006 BusOut bDIGIT(dp18, dp4, dp28, dp6, dp5, dp27, dp26); // (dp26, dp27, dp5, dp6, dp28, dp1, dp2); 00007 DigitalOut dDIGIT[7] = {dp18, dp4, dp28, dp6, dp5, dp27, dp26}; 00008 DigitalOut DECP (dp17); 00009 DigitalOut eA(dp26), eB(dp27), eC(dp5), eD(dp6), eE(dp28), eF(dp1), eG(dp2); 00010 00011 InterruptIn T1 (dp1), T2 (dp2); 00012 typedef unsigned long T; 00013 template <T N> 00014 class eBIN 00015 { 00016 public: 00017 enum {VAL = (N % 8) + (eBIN<N/8>::VAL << 1)}; 00018 }; 00019 template <> 00020 class eBIN<0> 00021 { 00022 public: 00023 enum {VAL = 0}; 00024 }; 00025 #define BIN(N) eBIN<0##N>::VAL 00026 00027 enum Keys {N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, A, B, C, D, Star, Hash, None = -1}; 00028 enum Diodes {D1 = 6, D2 = 5, D3 = 3}; 00029 void Display (Keys Key, Diodes Diode, bool DisplayPoint) 00030 { 00031 if (Key == None) return; 00032 DECP = DisplayPoint ? 0 : 1; 00033 switch (Key) 00034 { 00035 case N0: 00036 bDIGIT = BIN(0000001); //1 00037 break; 00038 case N1: 00039 bDIGIT = BIN(1001111); //79 00040 break; 00041 case N2: 00042 bDIGIT = BIN(0010010); //18 00043 break; 00044 case N3: 00045 bDIGIT = BIN(0000110); //6 00046 break; 00047 case N4: 00048 bDIGIT = BIN(1001100); //76 00049 break; 00050 case N5: 00051 bDIGIT = BIN(0100100); //36 00052 break; 00053 case N6: 00054 bDIGIT = BIN(0100000); //32 00055 break; 00056 case N7: 00057 bDIGIT = BIN(0001111); //15 00058 break; 00059 case N8: 00060 bDIGIT = BIN(0000000); //0 00061 break; 00062 case N9: 00063 bDIGIT = BIN(0000100); //4 00064 break; 00065 case A: 00066 bDIGIT = BIN(0001000); //A //8 00067 break; 00068 case B: 00069 bDIGIT = BIN(1100000); //b //96 00070 break; 00071 case C: 00072 bDIGIT = BIN(1110010); //c //114 00073 break; 00074 case D: 00075 bDIGIT = BIN(0000010); //d //2 00076 break; 00077 case Star: 00078 //xD ovo je 'e' slovo. Za gornje 'o' slovo je 0011100, za 'u' je 1100011 a za donje 'o' je 1100010 00079 bDIGIT = BIN(0010000); // 16 //za 'P' = 0011000 00080 break; 00081 case Hash: 00082 bDIGIT = BIN(1001000); //slovo H kao HASH :D //72 00083 break; 00084 case None: 00085 bDIGIT = BIN(1111111); //127 00086 break; 00087 } 00088 bDISP = (int)Diode; 00089 00090 } 00091 int refCnt = 0; 00092 unsigned int pPoint = 2; 00093 Keys pK1 = N0, pK2 = N0, pK3 = N0; 00094 void RefreshDisplay () 00095 { 00096 if (!refCnt) 00097 Display (pK1, D1, pPoint == 1); 00098 else if (refCnt == 1) 00099 Display (pK2, D2, pPoint == 2); 00100 else if (refCnt == 2) 00101 Display (pK3, D3, pPoint == 3); 00102 refCnt++; 00103 if (refCnt == 3) 00104 refCnt = 0; 00105 } 00106 int s1 = 0, s2 = 0, ds = 0; 00107 void Count () 00108 { 00109 if (++ds > 9) s2++, ds = 0; 00110 if (s2 > 9) s1++, s2 = 0; 00111 if (s1 > 9) s1 = s2 = ds = 0; // Resetujemo kada ne moze vise brojati 00112 pK1 = (Keys)s1; 00113 pK2 = (Keys)s2; 00114 pK3 = (Keys)ds; 00115 } 00116 bool pStart = true; 00117 Ticker tRefresh, tCount; 00118 Timer Dbnc, DbncReset; 00119 void StartStop () 00120 { 00121 if (Dbnc.read() > 0.2) // Provjeriti 00122 { 00123 if (pStart) 00124 { 00125 pStart = false; 00126 tCount.attach (&Count, 0.1); 00127 } 00128 else 00129 { 00130 pStart = true; 00131 tCount.detach(); 00132 } 00133 } 00134 Dbnc.reset(); 00135 } 00136 void Reset () 00137 { 00138 if (DbncReset.read () > 0.2) 00139 { 00140 tCount.detach(); 00141 pStart = true; 00142 s1 = s2 = ds = 0; 00143 pK1 = pK2 = pK3 = N0; 00144 } 00145 DbncReset.reset(); 00146 } 00147 int main() 00148 { 00149 tRefresh.attach (&RefreshDisplay, 0.001); 00150 Dbnc.start(); 00151 T1.rise (&StartStop); 00152 DbncReset.start(); 00153 T2.rise (&Reset); 00154 while (7); 00155 }
Generated on Wed Sep 7 2022 01:00:34 by
1.7.2