LV4-Grupa1-Tim003

Dependencies:   mbed

Committer:
tim003
Date:
Mon Mar 24 07:41:25 2014 +0000
Revision:
0:8ae139073d5a
LV4-Grupa1-Tim001

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tim003 0:8ae139073d5a 1 #include "mbed.h"
tim003 0:8ae139073d5a 2 DigitalOut ENBL = dp14;
tim003 0:8ae139073d5a 3 BusOut bDISP (dp23, dp24, dp25);
tim003 0:8ae139073d5a 4 BusOut dDISP[3] = {dp23, dp24, dp25};
tim003 0:8ae139073d5a 5
tim003 0:8ae139073d5a 6 BusOut bDIGIT(dp2, dp1, dp28, dp6, dp5, dp27, dp26); // (dp26, dp27, dp5, dp6, dp28, dp1, dp2);
tim003 0:8ae139073d5a 7 DigitalOut dDIGIT[7] = {dp2, dp1, dp28, dp6, dp5, dp27, dp26};
tim003 0:8ae139073d5a 8 DigitalOut DECP (dp4);
tim003 0:8ae139073d5a 9 DigitalOut eA(dp26), eB(dp27), eC(dp5), eD(dp6), eE(dp28), eF(dp1), eG(dp2);
tim003 0:8ae139073d5a 10
tim003 0:8ae139073d5a 11 typedef unsigned long T;
tim003 0:8ae139073d5a 12 template <T N>
tim003 0:8ae139073d5a 13 class eBIN
tim003 0:8ae139073d5a 14 {
tim003 0:8ae139073d5a 15 public:
tim003 0:8ae139073d5a 16 enum {VAL = (N % 8) + (eBIN<N/8>::VAL << 1)};
tim003 0:8ae139073d5a 17 };
tim003 0:8ae139073d5a 18 template <>
tim003 0:8ae139073d5a 19 class eBIN<0>
tim003 0:8ae139073d5a 20 {
tim003 0:8ae139073d5a 21 public:
tim003 0:8ae139073d5a 22 enum {VAL = 0};
tim003 0:8ae139073d5a 23 };
tim003 0:8ae139073d5a 24 #define BIN(N) eBIN<0##N>::VAL
tim003 0:8ae139073d5a 25
tim003 0:8ae139073d5a 26 enum Keys {N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, A, B, C, D, Star, Hash, None = -1};
tim003 0:8ae139073d5a 27 enum Diodes {D1 = 6, D2 = 5, D3 = 3};
tim003 0:8ae139073d5a 28 void Display (Keys Key, Diodes Diode, bool DisplayPoint)
tim003 0:8ae139073d5a 29 {
tim003 0:8ae139073d5a 30 if (Key == None) return;
tim003 0:8ae139073d5a 31
tim003 0:8ae139073d5a 32 DECP = DisplayPoint ? 0 : 1;
tim003 0:8ae139073d5a 33 switch (Key)
tim003 0:8ae139073d5a 34 {
tim003 0:8ae139073d5a 35 case N0:
tim003 0:8ae139073d5a 36 bDIGIT = BIN(0000001); //1
tim003 0:8ae139073d5a 37 break;
tim003 0:8ae139073d5a 38 case N1:
tim003 0:8ae139073d5a 39 bDIGIT = BIN(1001111); //79
tim003 0:8ae139073d5a 40 break;
tim003 0:8ae139073d5a 41 case N2:
tim003 0:8ae139073d5a 42 bDIGIT = BIN(0010010); //18
tim003 0:8ae139073d5a 43 break;
tim003 0:8ae139073d5a 44 case N3:
tim003 0:8ae139073d5a 45 bDIGIT = BIN(0000110); //6
tim003 0:8ae139073d5a 46 break;
tim003 0:8ae139073d5a 47 case N4:
tim003 0:8ae139073d5a 48 bDIGIT = BIN(1001100); //76
tim003 0:8ae139073d5a 49 break;
tim003 0:8ae139073d5a 50 case N5:
tim003 0:8ae139073d5a 51 bDIGIT = BIN(0100100); //36
tim003 0:8ae139073d5a 52 break;
tim003 0:8ae139073d5a 53 case N6:
tim003 0:8ae139073d5a 54 bDIGIT = BIN(0100000); //32
tim003 0:8ae139073d5a 55 break;
tim003 0:8ae139073d5a 56 case N7:
tim003 0:8ae139073d5a 57 bDIGIT = BIN(0001111); //15
tim003 0:8ae139073d5a 58 break;
tim003 0:8ae139073d5a 59 case N8:
tim003 0:8ae139073d5a 60 bDIGIT = BIN(0000000); //0
tim003 0:8ae139073d5a 61 break;
tim003 0:8ae139073d5a 62 case N9:
tim003 0:8ae139073d5a 63 bDIGIT = BIN(0000100); //4
tim003 0:8ae139073d5a 64 break;
tim003 0:8ae139073d5a 65 case A:
tim003 0:8ae139073d5a 66 bDIGIT = BIN(0001000); //A //8
tim003 0:8ae139073d5a 67 break;
tim003 0:8ae139073d5a 68 case B:
tim003 0:8ae139073d5a 69 bDIGIT = BIN(1100000); //b //96
tim003 0:8ae139073d5a 70 break;
tim003 0:8ae139073d5a 71 case C:
tim003 0:8ae139073d5a 72 bDIGIT = BIN(1110010); //c //114
tim003 0:8ae139073d5a 73 break;
tim003 0:8ae139073d5a 74 case D:
tim003 0:8ae139073d5a 75 bDIGIT = BIN(0000010); //d //2
tim003 0:8ae139073d5a 76 break;
tim003 0:8ae139073d5a 77 case Star:
tim003 0:8ae139073d5a 78 //xD ovo je 'e' slovo. Za gornje 'o' slovo je 0011100, za 'u' je 1100011 a za donje 'o' je 1100010
tim003 0:8ae139073d5a 79 bDIGIT = BIN(0010000); // 16 //za 'P' = 0011000
tim003 0:8ae139073d5a 80 break;
tim003 0:8ae139073d5a 81 case Hash:
tim003 0:8ae139073d5a 82 bDIGIT = BIN(1001000); //slovo H kao HASH :D //72
tim003 0:8ae139073d5a 83 break;
tim003 0:8ae139073d5a 84 case None:
tim003 0:8ae139073d5a 85 bDIGIT = BIN(1111111); //127
tim003 0:8ae139073d5a 86 break;
tim003 0:8ae139073d5a 87 }
tim003 0:8ae139073d5a 88 bDISP = (int)Diode;
tim003 0:8ae139073d5a 89
tim003 0:8ae139073d5a 90 }
tim003 0:8ae139073d5a 91 void DisplayKeys (Keys K1, Keys K2, Keys K3, unsigned int Point, int DelayMS = 10)
tim003 0:8ae139073d5a 92 {
tim003 0:8ae139073d5a 93 Display (K1, D1, Point == 1);
tim003 0:8ae139073d5a 94 if (K1 != None) wait_ms (DelayMS);
tim003 0:8ae139073d5a 95 Display (K2, D2, Point == 2);
tim003 0:8ae139073d5a 96 if (K2 != None) wait_ms (DelayMS);
tim003 0:8ae139073d5a 97 Display (K3, D3, Point == 3);
tim003 0:8ae139073d5a 98 if (K3 != None) wait_ms (DelayMS);
tim003 0:8ae139073d5a 99 }
tim003 0:8ae139073d5a 100 double Zaokruzi (double broj) //Na 2 dec
tim003 0:8ae139073d5a 101 {
tim003 0:8ae139073d5a 102 return double(int(broj * 100.0 + .5) / 100.0);
tim003 0:8ae139073d5a 103 }
tim003 0:8ae139073d5a 104 double Zaokruzi2 (double broj) //Na 3 dec
tim003 0:8ae139073d5a 105 {
tim003 0:8ae139073d5a 106 return double(int(broj * 1000.0 + .5) / 1000.0);
tim003 0:8ae139073d5a 107 }
tim003 0:8ae139073d5a 108 void DajCifre (double N, int &Cio, int &PrvaDec, int &DrugaDec) //broj u #.## formatu
tim003 0:8ae139073d5a 109 {
tim003 0:8ae139073d5a 110 double dec = (N - (int)N);
tim003 0:8ae139073d5a 111 dec = Zaokruzi(dec * 100.);
tim003 0:8ae139073d5a 112 DrugaDec = (int)dec % 10;
tim003 0:8ae139073d5a 113 PrvaDec = ((int)dec / 10) % 10;
tim003 0:8ae139073d5a 114 Cio = (int)N;
tim003 0:8ae139073d5a 115 }
tim003 0:8ae139073d5a 116
tim003 0:8ae139073d5a 117 void DajCifre (double N, int &Cio, int &PrvaDec, int &DrugaDec, int &TrecaDec) //broj u #.### formatu
tim003 0:8ae139073d5a 118 {
tim003 0:8ae139073d5a 119 double dec = (N - (int)N);
tim003 0:8ae139073d5a 120 dec = Zaokruzi2(dec * 1000.);
tim003 0:8ae139073d5a 121 TrecaDec = (int)dec % 10;
tim003 0:8ae139073d5a 122 DrugaDec = ((int)dec / 10) % 10;
tim003 0:8ae139073d5a 123 PrvaDec = ((int)dec / 100) % 10;
tim003 0:8ae139073d5a 124 Cio = (int)N;
tim003 0:8ae139073d5a 125 }
tim003 0:8ae139073d5a 126 AnalogIn aIN (dp9);
tim003 0:8ae139073d5a 127
tim003 0:8ae139073d5a 128 int main() { //Zadatak 1.
tim003 0:8ae139073d5a 129 ENBL = 1; //Provjeri
tim003 0:8ae139073d5a 130 int C = 0, PD = 0, DD = 0, b = 0;
tim003 0:8ae139073d5a 131 double Napon = 0.;
tim003 0:8ae139073d5a 132 while(1)
tim003 0:8ae139073d5a 133 {
tim003 0:8ae139073d5a 134 if (b == 100) {Napon = aIN * 3.30; b = 0;}
tim003 0:8ae139073d5a 135 b++;
tim003 0:8ae139073d5a 136 DajCifre (Napon, C, PD, DD);
tim003 0:8ae139073d5a 137 DisplayKeys ((Keys)C, (Keys)PD, (Keys)DD, 1, 1);
tim003 0:8ae139073d5a 138 //wait (0.2);
tim003 0:8ae139073d5a 139 }
tim003 0:8ae139073d5a 140 }
tim003 0:8ae139073d5a 141 int main_2()
tim003 0:8ae139073d5a 142 {
tim003 0:8ae139073d5a 143
tim003 0:8ae139073d5a 144 }