Advertisement
Guest User

Projekcik

a guest
Dec 9th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. #include <ioavr.h>
  2. #include <inavr.h>
  3. #include "kb_drv.h"
  4. #include "sys_event.h"
  5. //#include "stdlib.h"
  6. //#include "features.h"
  7. //#include "time.h"
  8.  
  9.  
  10. #define DV_50Hz 144
  11. #define DV_1Hz 25
  12. #define DV_96Hz 5
  13.  
  14. #define SYS_IDLE 0x00
  15. #define TIME_UPDATE 0x01
  16. #define KB_HIT 0x02
  17.  
  18.  
  19. //Symbolic names for connecting 7-segment LED display
  20. #define LED_SEG PORTE
  21. #define LED_SEG_DIR DDRE
  22. #define LED_DG PORTB
  23. #define LED_DG_DIR DDRB
  24. #define KB DDRA
  25.  
  26. //Decoding table based on CD4056 -> '0123456789LHPA- '
  27. __flash unsigned char bcd_to_led[] = {
  28. 0xDE, 0x82, 0xEC, 0xE6,
  29. 0xB2, 0x76, 0x7E, 0xC2,
  30. 0xFE, 0xF6, 0x1C, 0xBA,
  31. 0xF8, 0xFA, 0x20, 0x00
  32. };
  33.  
  34. //Global variables
  35. unsigned char freq_dv, symb_ID;
  36. unsigned int arr[20] = {1,3,2,4,3,2,1,3,4,2,2,1,3,2,3,4,1,2,3,2};
  37. unsigned int diff;
  38. unsigned int counter;
  39. static unsigned char kb_dv = DV_96Hz;
  40.  
  41.  
  42. void InitDevices()
  43. {
  44. KB = 0;
  45. kbInit();
  46. LED_DG = 0xFE;
  47. LED_DG_DIR = 0xFF;
  48. LED_SEG_DIR = 0xFF;
  49. //Prescaler fclk / 1024 = 7200Hz
  50. //Prescaler for T0 is different than for T1,T2,T3
  51. OCR0 = DV_50Hz - 1;
  52. TCCR0 = (1 << CS02) | (1 << CS01) | (1 << CS00);
  53. TIMSK = (1 << OCIE0);
  54. __enable_interrupt();
  55. }
  56.  
  57. #pragma vector = TIMER0_COMP_vect
  58. __interrupt void T0_COMP_ISR()
  59. {
  60. //static -> global variabl, visible insied declaration scope (file, function)
  61. static unsigned char freq_dv = DV_1Hz;
  62. if(--freq_dv) return;
  63. freq_dv = DV_1Hz;
  64. //Update to nexy symbol from bcd_to_led array
  65. symb_ID = (symb_ID + 1) & 0x0F; // & 0x0F -> mod 16
  66. if(symb_ID > 9)
  67. {
  68. symb_ID = 0;
  69. }
  70. LED_SEG = bcd_to_led[symb_ID];
  71.  
  72.  
  73.  
  74. if((--kb_dv) == 0)
  75. {
  76. kb_dv = DV_96Hz;
  77. kbService();
  78. }
  79. }
  80.  
  81. //void generateArray()
  82. //{
  83. // for( int i = 0; i < diff; i++)
  84. // {
  85. // arr[i] = (rand() % 4) + 1;
  86. // }
  87. //}
  88.  
  89. void start()
  90. {
  91.  
  92. }
  93.  
  94. void lose()
  95. {
  96.  
  97. }
  98.  
  99. void gz()
  100. {
  101.  
  102. }
  103.  
  104. void main()
  105. {
  106. rq.ev = SYS_IDLE;
  107. symb_ID = -1;
  108. InitDevices();
  109. kb_rep = 0x0F;
  110. diff = 4;
  111. counter = 0;
  112. while(counter < diff)
  113. {
  114. if(rq.kb)
  115. {
  116. rq.kb = EVENT_PROCESSED;
  117. if(kb_reg & 0x01)
  118. {
  119. if(arr[counter] == 1)
  120. {
  121. counter++;
  122. continue;
  123. }
  124. else
  125. lose();
  126. }
  127.  
  128. else if(kb_reg & 0x02)
  129. {
  130. if(arr[counter] == 2)
  131. {
  132. counter++;
  133. continue;
  134. }
  135. else
  136. lose();
  137. }
  138.  
  139. else if(kb_reg & 0x04)
  140. {
  141. if(arr[counter] == 3)
  142. {
  143. counter++;
  144. continue;
  145. }
  146. else
  147. lose();
  148. }
  149.  
  150. else if(kb_reg & 0x08)
  151. {
  152. if(arr[counter] == 4)
  153. {
  154. counter++;
  155. continue;
  156. }
  157. else
  158. lose();
  159. }
  160.  
  161. else if(kb_reg & 0x10)
  162. {
  163. start();
  164. }
  165. //else if(kb_reg & 0x20);
  166. //else if(kb_reg & 0x40);
  167. else if(kb_reg & 0x80)
  168. {
  169. lose();
  170. }
  171. else
  172.  
  173. //Remove notifications
  174. kb_reg = KB_IDLE;
  175. }
  176. }
  177. if (counter == diff)
  178. {
  179. gz();
  180. }
  181. else
  182. ;
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement