Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. #include <iom128.h>
  2. #include <inavr.h>
  3. #include "sys_event.h"
  4. #include "kb_drv.h"
  5.  
  6. //Program configuration
  7. //#define ISR_PROCESSING
  8. #define PTR_ACCESS
  9.  
  10. #define LED_SEG PORTE
  11. #define LED_SEG_DIR DDRE
  12. #define LED_DG PORTB
  13. #define LED_DG_DIR DDRB
  14.  
  15. #define DV_480Hz 15
  16. #define DV_DEMO 40
  17. #define DV_NEXT 13
  18.  
  19. #define DEC_OFF 0x3F
  20. #define DISP_MAX 6
  21. #define LED_BLANK 10
  22.  
  23. //Decoding table based on CD4056 -> '0123456789LHPA- '
  24. __flash unsigned char BCD_2_LED[] = {
  25. 0xDE, 0x82, 0xEC, 0xE6,
  26. 0xB2, 0x76, 0x7E, 0xC2,
  27. 0xFE, 0xF6, 0x1C, 0xBA,
  28. 0xF8, 0xFA, 0x20, 0x00 };
  29.  
  30. __flash unsigned char DEC_1_OF_6[] =
  31. {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF};
  32.  
  33. //Global variables
  34. unsigned char disp[6] = {0,0,0,0,0,0};
  35. unsigned char dv_demo = DV_DEMO;
  36. unsigned char dv_next = DV_NEXT;
  37. unsigned char arr[20] = {1,2,1,3,7,2,1,3,4,2,2,1,3,2,3,4,1,2,3,2};
  38. __no_init unsigned char idx;
  39. #define UPDATE_DISP_RQ 0x01
  40. volatile TSystemEvent rq;
  41. unsigned char cnt;
  42. int diff;
  43. int counter;
  44. volatile unsigned char start=0;
  45.  
  46. void InitDevices()
  47. {
  48. LED_DG = 0xFE;
  49. LED_DG_DIR = 0xFF;
  50. LED_SEG_DIR = 0xFF;
  51. kbInit();
  52. //Prescaler fclk / 1024 = 7200Hz
  53. //Prescaler for T0 is different than for T1,T2,T3
  54. OCR0 = DV_480Hz - 1;
  55. TCCR0 = (1 << WGM01) | (1 << CS02) | (1 << CS01) | (1 << CS00);
  56. TCCR1B = (1<<CS12);//|(1<<CS10);
  57. TIMSK = (1 << OCIE0)|(1<<TOIE1);
  58. __enable_interrupt();
  59. }
  60.  
  61.  
  62. void display()
  63. {
  64. for(unsigned char i = 0; i <= 19; i++)
  65. {
  66. disp[5] = arr[i];
  67.  
  68. }
  69. }
  70.  
  71. #pragma vector = TIMER1_OVF_vect
  72. __interrupt void T1_OVF_ISR()
  73. {
  74. static unsigned char cur_disp = 0;
  75. if (start==1)
  76. {
  77. disp[5] = arr[cur_disp];
  78. if((++cur_disp) == 5)
  79. {
  80. cur_disp = 0;
  81. }
  82. }
  83. }
  84.  
  85. #pragma vector = TIMER0_COMP_vect
  86. __interrupt void T0_COMP_ISR()
  87. {
  88. static unsigned char cur_disp = 0;
  89. LED_DG |= DEC_OFF;
  90. LED_SEG = BCD_2_LED[disp[cur_disp]];
  91. LED_DG = DEC_1_OF_6[cur_disp];
  92. if((++cur_disp) == DISP_MAX)
  93. {
  94. cur_disp = 0;
  95. kbService();
  96. }
  97. }
  98.  
  99. void incVal()
  100. {
  101. if((++cnt) == 9) cnt = 0;
  102. disp[5] = BCD_2_LED[cnt];
  103. }
  104.  
  105. void decVal()
  106. {
  107. if((--cnt) == 255) cnt = 9;
  108. disp[5] = BCD_2_LED[cnt];
  109. }
  110.  
  111.  
  112.  
  113.  
  114. void main()
  115. {
  116. InitDevices();
  117. while(1)
  118. {
  119. if(rq.kb)
  120. {
  121. rq.kb = 0;
  122. switch(kb_reg) {
  123.  
  124. case KEY_0:
  125. incVal();
  126. break;
  127. case KEY_1:
  128. decVal();
  129. break;
  130. case KEY_2:
  131. start=1;
  132. break;
  133. case KEY_3:
  134. break;
  135. case KEY_4:
  136. break;
  137.  
  138. }
  139. }
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement