Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include <8051.h>
  2.  
  3. #define LIMIT 300
  4.  
  5. int i[4] = {1, 1, 1, 1};
  6.  
  7. void action(int key) {
  8. i[key] = i[key] + 1;
  9. if(i[key]>9)
  10. i[key]=0;
  11. }
  12.  
  13. void main(void) {
  14. int btn_before[4] = {1, 1, 1, 1};
  15. int state[4] = {0, 0, 0, 0};
  16. int btn_current[4] = {4, 4, 4, 4};
  17. int debounce_cnt[4] = {0, 0, 0, 0};
  18. char cyfry[10]={0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
  19. int display[4] = {1, 2, 4, 8};
  20. int index = 1;
  21. while(1) {
  22. P1 = display[index];
  23. P0 = cyfry[i[index]];
  24.  
  25. if(index == 0)
  26. btn_current[index] = P3_0;
  27. if(index == 1)
  28. btn_current[index] = P3_1;
  29. if(index == 2)
  30. btn_current[index] = P3_2;
  31. if(index == 3)
  32. btn_current[index] = P3_3;
  33.  
  34. if(state[index] == 0) {
  35. if(btn_before[index] != btn_current[index]) {
  36. state[index] = 1;
  37. btn_before[index] = btn_current[index];
  38. }
  39. }
  40.  
  41. if (state[index] == 1) {
  42. if (btn_before[index] == btn_current[index]) {
  43. if (debounce_cnt[index] > LIMIT) {
  44. state[index] = 2;
  45. action(index);
  46. } else {
  47. debounce_cnt[index] = debounce_cnt[index] + 1;
  48. }
  49. } else {
  50. state[index] = 0;
  51. btn_before[index] = btn_current[index];
  52. debounce_cnt[index] = 0;
  53. }
  54. }
  55.  
  56. if (state[index] == 2) {
  57. if (btn_before[index] != btn_current[index]) {
  58. state[index] = 0;
  59. btn_before[index] = btn_current[index];
  60. debounce_cnt[index] = 0;
  61. }
  62. }
  63.  
  64. index = index + 1;
  65. if(index > 3) {
  66. index = 0;
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement