Advertisement
JosipFranjic

Untitled

May 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1.  
  2. #include "mbed.h"
  3. #define dp23 P0_0
  4.  
  5. DigitalOut enable(dp14);
  6.  
  7. BusOut displej(dp26, dp27, dp5, dp6, dp28, dp4, dp18, dp17);
  8. BusOut odabir_cifre(dp25, dp24, dp23);
  9.  
  10. InterruptIn taster1(dp1);
  11. InterruptIn taster2(dp2);
  12.  
  13. const int lookup_tabela[] = {
  14. 0x40 ^ (1 << 7),
  15. 0x79 ^ (1 << 7),
  16. 0x24 ^ (1 << 7),
  17. 0x30 ^ (1 << 7),
  18. 0x19 ^ (1 << 7),
  19. 0x12 ^ (1 << 7),
  20. 0x02 ^ (1 << 7),
  21. 0x78 ^ (1 << 7),
  22. 0x00 ^ (1 << 7),
  23. 0x10 ^ (1 << 7)
  24. };
  25.  
  26. //tabela sa tackama
  27. const int lookup_tabela_tacka[] = {
  28. 0x40 ,
  29. 0x79 ,
  30. 0x24 ,
  31. 0x30 ,
  32. 0x19 ,
  33. 0x12 ,
  34. 0x02 ,
  35. 0x78 ,
  36. 0x00 ,
  37. 0x10
  38. };
  39.  
  40. int pozicija_cifre_za_ispis(1);
  41. int brojac(999);
  42.  
  43. const float T(0.1);
  44. const float DT(0.1);
  45. const float TI(0.001);
  46.  
  47. bool broji(false);
  48.  
  49. Ticker t_ispis, t_brojac;
  50. Timer debounce_t1, debounce_t2;
  51.  
  52. int nta_cifra(int broj, int n) {
  53. for(int i = 1; i < n; i++)
  54. broj /= 10;
  55. return broj % 10;
  56. }
  57.  
  58. void ispisi_cifru(int cifra, int pozicija) {
  59. if(pozicija == 4)
  60. return;
  61. odabir_cifre = 7 - (1 << (pozicija - 1));
  62. if(pozicija != 2)
  63. displej = lookup_tabela[cifra];
  64. else
  65. displej = lookup_tabela_tacka[cifra];//druga cifra treba sadrzavati tacku
  66. }
  67.  
  68. void ispisi_na_displej() {
  69. ispisi_cifru(nta_cifra(brojac, pozicija_cifre_za_ispis),
  70. pozicija_cifre_za_ispis);
  71. pozicija_cifre_za_ispis = (pozicija_cifre_za_ispis + 1) % 4;
  72. if(pozicija_cifre_za_ispis == 0)
  73. pozicija_cifre_za_ispis++;
  74. }
  75.  
  76. void start_stop() {
  77. if(debounce_t1.read() > DT) {
  78. broji = 1 - broji;
  79. debounce_t1.reset();
  80. }
  81. }
  82.  
  83. void reset() {
  84. if(debounce_t2.read() > DT) {
  85. broji = false;
  86. brojac = 0;
  87. debounce_t2.reset();
  88. }
  89. }
  90.  
  91. void ink() {
  92. if(broji)
  93. brojac++;
  94. if(brojac == 999)
  95. brojac = 0;
  96. }
  97.  
  98. int main() {
  99.  
  100. enable = 1;
  101.  
  102. t_ispis.attach(&ispisi_na_displej, TI);
  103. t_brojac.attach(&ink, T);
  104. taster1.rise(&start_stop);
  105. taster2.rise(&reset);
  106. debounce_t1.start();
  107. debounce_t2.start();
  108. while(1);
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement