Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include "pic24_all.h"
  2. #if __PIC24HJ128GP502__
  3. #define LED1 _LATA0 // MicroStick II definitions
  4. #define LED2 _LATA1
  5. #define LED3 _LATA2
  6. #define SW1 _LATA3
  7. #define SW2 _LATA4
  8. #define CONFIG_LED1() CONFIG_RB15_AS_DIG_OUTPUT()
  9. #define CONFIG_LED2() CONFIG_RB14_AS_DIG_OUTPUT()
  10. #define CONFIG_LED3() CONFIG_RB13_AS_DIG_OUTPUT()
  11. inline void CONFIG_SW1()
  12. {
  13. CONFIG_RB12_AS_DIG_INPUT();
  14. ENABLE_RB12_PULLUP();
  15. }
  16. inline void CONFIG_SW2()
  17. {
  18. CONFIG_RB11_AS_DIG_INPUT();
  19. ENABLE_RB11_PILLUP();
  20. }
  21. #endif
  22.  
  23. int task5(int x)
  24. {
  25. int temp = x >> 1;
  26. return temp;
  27. }
  28.  
  29. int main(void)
  30. {
  31. CONFIG_LED1();
  32. CONFIG_LED2();
  33. CONFIG_LED3();
  34. CONFIG_SW1();
  35. CONFIG_SW2();
  36.  
  37. LED1=0;
  38. LED2=0;
  39. LED3=0;
  40.  
  41. while (1)
  42. {
  43. if(SW1 == 0 && SW2 == 0)
  44. {
  45. LED1 = 1;
  46. LED2 = 1;
  47. LED3 = 1;
  48. }
  49. if(SW1 == 0 && SW2 == 1)
  50. {
  51. while(SW1 == 0 && SW2 == 1)
  52. {
  53. int i = 0, j = 0, k = 0;
  54. for(; i < 2; i++)
  55. {
  56. for(; j < 2; j++)
  57. {
  58. for(; k < 2; k++)
  59. {
  60. led3 = !led3;
  61. DELAY_MS(500);
  62. }
  63. led2 = !led2;
  64. DELAY_MS(500);
  65. }
  66. led1 = !led1;
  67. DELAY_MS(500);
  68. }
  69. }
  70. }
  71. if(SW1 == 1 && SW2 == 0)
  72. {
  73. while(SW1 == 1 && SW2 == 0)
  74. {
  75. LED1 = 0;
  76. LED2 = 0;
  77. LED3 = 0;
  78. DELAY_MS(500);
  79. LED1 = 0;
  80. LED2 = 0;
  81. LED3 = 1;
  82. DELAY_MS(500);
  83. LED1 = 0;
  84. LED2 = 1;
  85. LED3 = 1;
  86. DELAY_MS(500);
  87. LED1 = 0;
  88. LED2 = 1;
  89. LED3 = 0;
  90. DELAY_MS(500);
  91. LED1 = 1;
  92. LED2 = 1;
  93. LED3 = 0;
  94. DELAY_MS(500);
  95. LED1 = 1;
  96. LED2 = 1;
  97. LED3 = 1;
  98. DELAY_MS(500);
  99. LED1 = 1;
  100. LED2 = 0;
  101. LED3 = 1;
  102. DELAY_MS(500);
  103. LED1 = 1;
  104. LED2 = 0;
  105. LED3 = 0;
  106. DELAY_MS(500);
  107.  
  108. }
  109. }
  110. if(SW1 == 1 && SW2 == 1)
  111. {
  112. int i = 0x000;
  113. LED1 = i % 10;
  114. LED2 = (i % 100)/10;
  115. LED3 = (1 % 1000)/100;
  116. while(SW1 == 1 && SW2 == 1)
  117. {
  118. i += 1;
  119. int temp = task5(i);
  120. LED1 = temp % 10;
  121. LED2 = (temp % 100)/10;
  122. LED3 = (temp % 1000)/100;
  123. DELAY_MS(500);
  124. if(i == 8)
  125. i = 0;
  126. }
  127. }
  128. }
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement