Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <p89lpc9351.h>
  4.  
  5.  
  6. #define B1 P1_3
  7. #define B2 P1_4
  8. #define B3 P1_6
  9. #define MAX_UPPER_LIMIT 90
  10. #define MIN_LOWER_LIMIT -90
  11. #define UPPER_LIMIT 1
  12. #define LOWER_LIMIT 0
  13.  
  14. #define HEX0 0x0C0
  15. #define HEX1 0x0F9
  16. #define HEX2 0x0A4
  17. #define HEX3 0x0B0
  18. #define HEX4 0x099
  19. #define HEX5 0x092
  20. #define HEX6 0x082
  21. #define HEX7 0x0F8
  22. #define HEX8 0x080
  23. #define HEX9 0x090
  24. #define OFF 0x080
  25.  
  26. int limit [2];
  27.  
  28. void initMC()
  29. {
  30. P0M1 = 0;
  31. P0M2 = 0;
  32. P1M1 = 0;
  33. P1M2 = 0;
  34. P2M1 = 0;
  35. P2M2 = 0;
  36. P3M1 = 0;
  37. P3M2 = 0;
  38. B1 = 1;
  39. B2 = 1;
  40. B3 = 1;
  41. }
  42.  
  43. void display(int num)
  44. {
  45. int hexVal[] = {HEX0, HEX1, HEX2, HEX3, HEX4,
  46. HEX5, HEX6, HEX7, HEX8, HEX9};
  47. int digit = 0;
  48. if(num < 0)
  49. {
  50. P1_7 = 1;
  51. num *= -1;
  52. }
  53. else
  54. P1_7 = 0;
  55. digit = hexVal[num % 10];
  56. digit ^= 0xFF;
  57. P0 = digit;
  58. num /= 10;
  59. digit = hexVal[num];
  60. digit ^= 0xFF;
  61. P2 = digit;
  62. }
  63.  
  64. void mydelay(int ms)
  65. {
  66. int i;
  67. int j;
  68. for (j=0; j<ms; j++)
  69. {
  70. for (i=0; i<1840; i++)
  71. {
  72. // do nothing
  73. }
  74. }
  75. }
  76.  
  77.  
  78.  
  79. void changeLimit (int i, int limit[])
  80. {
  81. while (1)
  82. {
  83. P0 = OFF;
  84. P2 = OFF;
  85. P1_7 = 0;
  86. mydelay(30);
  87. display(limit[i]);
  88. mydelay(50);
  89.  
  90. if (B2 == 0){
  91. if(!((i == LOWER_LIMIT && (limit[i] + 1 == limit[UPPER_LIMIT]) ) || limit[i] == MAX_UPPER_LIMIT ))
  92. limit [i]++;
  93. }
  94.  
  95. if (B3 == 0){
  96. if(!((i == UPPER_LIMIT && (limit[i] - 1 == limit[LOWER_LIMIT]) ) || limit[i] == MIN_LOWER_LIMIT ))
  97. limit [i]--;
  98. }
  99.  
  100. if (B1 == 1)
  101. {
  102. while (B1 == 1);
  103. break;
  104. }
  105. }
  106. }
  107.  
  108. void ext_int(void)
  109. {
  110.  
  111. int i = 0;
  112.  
  113. while (1)
  114. {
  115.  
  116. display(limit[i]);
  117.  
  118. if (B1 == 1)
  119. {
  120. while (B1 == 1);
  121. changeLimit(i,limit);
  122. }
  123.  
  124. if (B2 == 0)
  125. {
  126. while(B2 == 0); // do nothing
  127. i ^= 1;
  128. }
  129.  
  130. if (B3 == 0)
  131. {
  132. while(B3 == 0);
  133. break;
  134. }
  135. }
  136. }
  137.  
  138. int main (void)
  139. {
  140. initMC();
  141. limit[LOWER_LIMIT] = MIN_LOWER_LIMIT;
  142. limit[UPPER_LIMIT] = MAX_UPPER_LIMIT;
  143. while(1)
  144. {
  145. display(10);
  146. if (P1_3 == 1){
  147. mydelay(250);
  148. ext_int();
  149. }
  150. }
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement