Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #define TH0_RELOAD 0xF1
  2. #define TL0_RELOAD 0x00
  3. #define TIK 1
  4. int limit = 50;
  5. int glob=1;
  6.  
  7. char state[4] = {0, 0, 0, 0};
  8. char number[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
  9. int btn_before[4] = {1, 1, 1, 1};
  10. int btn_current[4] = {0, 0, 0, 0};
  11. int debounce_cnt[4] = {0, 0, 0, 0};
  12.  
  13.  
  14. void timer0_init(void)
  15. {
  16. TH0 = TH0_RELOAD; // za.adowanie czasu odliczania
  17. TL0 = TL0_RELOAD; // TH0 . starszy bajt, TL0 - m.odszy
  18. TMOD = TMOD | 0x01; // tryb nr 1 uk.adu TIMER 0
  19. TR0 = 1; // TIMER 0 start
  20. ET0 = 1; // odblokowanie przerwa. od TIMER 0
  21. }
  22. void timer_isr (void) __interrupt (1) __using (0)
  23. {
  24. static int count=0;
  25. TH0 = TH0_RELOAD; // za.adowanie czasu odliczania
  26. TL0 = TL0_RELOAD;
  27. count++;
  28. if (count==TIK)
  29. {
  30. glob*=2;
  31. if(glob>8)
  32. {
  33. glob=1;
  34. }// dodatkowy licznik przerwa.
  35. count=0; // umo.liwiaj.cy uzyskanie dodatk.
  36. P2_7=!P2_7; // opo.nie.
  37. }
  38. }
  39. void main(void)
  40. {
  41. int a[4] = {0, 0, 0, 0};
  42.  
  43. EA = 0; // zablokowanie przerwa.
  44. timer0_init(); // przygotowanie uk.adu Timer0
  45. EA = 1; // odblokowanie przerwa.
  46. P2=0xFF; // wygaszenie wszystkich diod
  47. while(1) {
  48. P2_6 = P3_6; // obs.uga przycisku i diody
  49. btn_current = P3_0;
  50. for( int i = 0; i<4 ; i++){
  51.  
  52. if(state[i] == 0)
  53. {
  54. if(btn_before[i] != btn_current[i])
  55. {
  56. state[i]=1;
  57. btn_before[i] = btn_current[i];
  58. }
  59. }
  60. else if(state[i] == 1)
  61. {
  62. if(btn_before[i] == btn_current[i])
  63. {
  64. if(debounce_cnt[i] >= limit)
  65. {
  66. state[i]=2;
  67. a[i]++;
  68. if(a[i]>9)
  69. {
  70. a[i]=0;
  71. }
  72. }
  73. else
  74. debounce_cnt[i] = debounce_cnt[i] + 1;
  75. }
  76. else
  77. {
  78. state[i] = 0;
  79. btn_before[i] = btn_current[i];
  80. debounce_cnt[i] = 0;
  81. }
  82. }
  83. else if(state[i]==2)
  84. {
  85. if(btn_before[i] != btn_current[i])
  86. {
  87. state[i] = 0;
  88. btn_before[i] = btn_current[i];
  89. debounce_cnt[i] = 0;
  90. }
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement