Sinanović Hamdija

Dependencies:   mbed

Committer:
tim003
Date:
Thu Apr 10 13:41:28 2014 +0000
Revision:
0:b4655a58de3c
LV6 - PAI - Grupa 5 - Tim003

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tim003 0:b4655a58de3c 1 #include "mbed.h"
tim003 0:b4655a58de3c 2
tim003 0:b4655a58de3c 3 #define NULA 0x01
tim003 0:b4655a58de3c 4 #define JEDAN 0x4F
tim003 0:b4655a58de3c 5 #define DVA 0x12
tim003 0:b4655a58de3c 6 #define TRI 0x06
tim003 0:b4655a58de3c 7 #define CETIRI 0x4C
tim003 0:b4655a58de3c 8 #define PET 0x24
tim003 0:b4655a58de3c 9 #define SEST 0x20
tim003 0:b4655a58de3c 10 #define SEDAM 0x0F
tim003 0:b4655a58de3c 11 #define OSAM 0x00
tim003 0:b4655a58de3c 12 #define DEVET 0x04
tim003 0:b4655a58de3c 13 #define A 0x08
tim003 0:b4655a58de3c 14 #define B 0x60
tim003 0:b4655a58de3c 15 #define C 0x31
tim003 0:b4655a58de3c 16 #define D 0x42
tim003 0:b4655a58de3c 17 #define E 0x30
tim003 0:b4655a58de3c 18 #define F 0x38
tim003 0:b4655a58de3c 19 #define HASH 0x48
tim003 0:b4655a58de3c 20 #define ZVIJEZDA 0x7E
tim003 0:b4655a58de3c 21
tim003 0:b4655a58de3c 22 #define PRVA 0x3
tim003 0:b4655a58de3c 23 #define DRUGA 0x5
tim003 0:b4655a58de3c 24 #define TRECA 0x6
tim003 0:b4655a58de3c 25 #define OFF 0x7
tim003 0:b4655a58de3c 26
tim003 0:b4655a58de3c 27 Timer T;
tim003 0:b4655a58de3c 28 Timer deb;
tim003 0:b4655a58de3c 29 InterruptIn taster1(dp1);
tim003 0:b4655a58de3c 30 InterruptIn taster2(dp2);
tim003 0:b4655a58de3c 31
tim003 0:b4655a58de3c 32 Ticker tic;
tim003 0:b4655a58de3c 33
tim003 0:b4655a58de3c 34 DigitalOut enabled (dp14);
tim003 0:b4655a58de3c 35 BusOut vrijednost (dp18, dp4, dp28, dp6, dp5, dp27, dp26);
tim003 0:b4655a58de3c 36
tim003 0:b4655a58de3c 37 BusOut cifra (dp23, dp24, dp25);
tim003 0:b4655a58de3c 38 DigitalOut tacka (dp17);
tim003 0:b4655a58de3c 39
tim003 0:b4655a58de3c 40 int vrijednosti[10] = {NULA, JEDAN, DVA, TRI, CETIRI, PET, SEST, SEDAM, OSAM, DEVET};
tim003 0:b4655a58de3c 41 int cifre[3] = {TRECA, DRUGA, PRVA};
tim003 0:b4655a58de3c 42 int v1, v2, v3, tacka1;
tim003 0:b4655a58de3c 43
tim003 0:b4655a58de3c 44 void resetuj(){
tim003 0:b4655a58de3c 45 if(deb.read_ms() > 400) {
tim003 0:b4655a58de3c 46 T.stop();
tim003 0:b4655a58de3c 47 T.reset();
tim003 0:b4655a58de3c 48 deb.reset();
tim003 0:b4655a58de3c 49 }
tim003 0:b4655a58de3c 50 }
tim003 0:b4655a58de3c 51
tim003 0:b4655a58de3c 52
tim003 0:b4655a58de3c 53 void toggle(){
tim003 0:b4655a58de3c 54 static int on(0);
tim003 0:b4655a58de3c 55 if(deb.read_ms() > 400) {
tim003 0:b4655a58de3c 56 if(on) {T.stop();} else {T.start();}
tim003 0:b4655a58de3c 57 on = (on+1)%2;
tim003 0:b4655a58de3c 58 deb.reset();
tim003 0:b4655a58de3c 59 }
tim003 0:b4655a58de3c 60 }
tim003 0:b4655a58de3c 61
tim003 0:b4655a58de3c 62 void refresh();
tim003 0:b4655a58de3c 63
tim003 0:b4655a58de3c 64 int main() {
tim003 0:b4655a58de3c 65 //T.start();
tim003 0:b4655a58de3c 66 deb.start();
tim003 0:b4655a58de3c 67 taster1.fall(&toggle);
tim003 0:b4655a58de3c 68 taster2.fall(&resetuj);
tim003 0:b4655a58de3c 69 tic.attach(&refresh, 0.006);
tim003 0:b4655a58de3c 70 int br = 0;
tim003 0:b4655a58de3c 71
tim003 0:b4655a58de3c 72 v1 = 0;
tim003 0:b4655a58de3c 73 v2 = 0;
tim003 0:b4655a58de3c 74 v3 = 0;
tim003 0:b4655a58de3c 75
tim003 0:b4655a58de3c 76 enabled = 1;
tim003 0:b4655a58de3c 77
tim003 0:b4655a58de3c 78 tacka1 = 1;
tim003 0:b4655a58de3c 79 cifra = PRVA;
tim003 0:b4655a58de3c 80 vrijednost = NULA;
tim003 0:b4655a58de3c 81 tacka = 1;
tim003 0:b4655a58de3c 82 cifra = DRUGA;
tim003 0:b4655a58de3c 83 vrijednost = NULA;
tim003 0:b4655a58de3c 84 tacka = 0;
tim003 0:b4655a58de3c 85 cifra = TRECA;
tim003 0:b4655a58de3c 86 vrijednost = NULA;
tim003 0:b4655a58de3c 87 tacka = 1;
tim003 0:b4655a58de3c 88
tim003 0:b4655a58de3c 89 while(1) {
tim003 0:b4655a58de3c 90 br = T.read_ms()/100;
tim003 0:b4655a58de3c 91 v3 = br%10;
tim003 0:b4655a58de3c 92 br /= 10;
tim003 0:b4655a58de3c 93 v2 = br%10;
tim003 0:b4655a58de3c 94 br /= 10;
tim003 0:b4655a58de3c 95 v1 = br%10;
tim003 0:b4655a58de3c 96 }
tim003 0:b4655a58de3c 97 }
tim003 0:b4655a58de3c 98
tim003 0:b4655a58de3c 99
tim003 0:b4655a58de3c 100
tim003 0:b4655a58de3c 101 void refresh(){
tim003 0:b4655a58de3c 102 static int c(0);
tim003 0:b4655a58de3c 103 if(c == 0) {
tim003 0:b4655a58de3c 104 vrijednost = vrijednosti[v1];
tim003 0:b4655a58de3c 105 tacka = 1;
tim003 0:b4655a58de3c 106 cifra = cifre[c];
tim003 0:b4655a58de3c 107 c = (c+1)%3;
tim003 0:b4655a58de3c 108 }
tim003 0:b4655a58de3c 109 else if(c == 1) {
tim003 0:b4655a58de3c 110 vrijednost = vrijednosti[v2];
tim003 0:b4655a58de3c 111 tacka = 0;
tim003 0:b4655a58de3c 112 cifra = cifre[c];
tim003 0:b4655a58de3c 113 c = (c+1)%3;
tim003 0:b4655a58de3c 114 }
tim003 0:b4655a58de3c 115 else {
tim003 0:b4655a58de3c 116 vrijednost = vrijednosti[v3];
tim003 0:b4655a58de3c 117 tacka = 1;
tim003 0:b4655a58de3c 118 cifra = cifre[c];
tim003 0:b4655a58de3c 119 c = (c+1)%3;
tim003 0:b4655a58de3c 120 }
tim003 0:b4655a58de3c 121 }