Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include "pic24_all.h"
  2. #if __PIC24HJ128GP502__
  3. #define LED1 _RB15 // MicroStick II definitions
  4. #define LED2 _RB14
  5. #define LED3 _RB13
  6. #define SW1 _RB12
  7. #define SW2 _RB11
  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. return ((x >> 1) ^ x);
  26. }
  27.  
  28. int main(void)
  29. {
  30. CONFIG_LED1();
  31. CONFIG_LED2();
  32. CONFIG_LED3();
  33. CONFIG_SW1();
  34. CONFIG_SW2();
  35.  
  36. LED1=0;
  37. LED2=0;
  38. LED3=0;
  39.  
  40. while (1)
  41. {
  42. if(SW1 == 0 && SW2 == 0)
  43. {
  44. LED1 = 1;
  45. LED2 = 1;
  46. LED3 = 1;
  47. }
  48.  
  49. if(SW1 == 0 && SW2 == 1)
  50. {
  51. int i = 0x000;
  52. LED1 = i % 10;
  53. LED2 = (i % 100)/10;
  54. LED3 = (1 % 1000)/100;
  55. while(SW1 == 1 && SW2 == 1)
  56. {
  57. i += 1;
  58. LED1 = ((i | 0x01) % 10);
  59. LED2 = ((i | 0x02) % 100)/10;
  60. LED3 = ((i | 0x04) % 1000)/100;
  61. DELAY_MS(500);
  62. if(i == 8)
  63. i = 0;
  64. }
  65. }
  66.  
  67. if(SW1 == 1 && SW2 == 0)
  68. {
  69. int i = 0x000;
  70. LED1 = i % 10;
  71. LED2 = (i % 100)/10;
  72. LED3 = (1 % 1000)/100;
  73. while(SW1 == 1 && SW2 == 1)
  74. {
  75. i += 1;
  76. int temp = task5(i);
  77. LED1 = ((temp | 0x01) % 10);
  78. LED2 = ((temp | 0x02) % 100)/10;
  79. LED3 = ((temp | 0x04) % 1000)/100;
  80. DELAY_MS(500);
  81. if(i == 8)
  82. i = 0;
  83. }
  84. }
  85.  
  86. if(SW1 == 1 && SW2 == 1)
  87. {
  88. while(SW1 == 1 && SW2 == 1)
  89. {
  90. LED1 = !LED1;
  91. LED2 = !LED2;
  92. LED3 = !LED3;
  93. DELAY_MS(10);
  94. }
  95. }
  96. }
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement