Advertisement
Guest User

Untitled

a guest
Oct 19th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include "pic24_all.h"
  2.  
  3. void a_delay(void)
  4. {
  5. uint16_t i, k;
  6. for(k = 1800; --k;)
  7. {
  8. for(i = 3600; --i;);
  9. }
  10. }
  11.  
  12. void b_delay(void)
  13. {
  14. uint16_t i, k;
  15. for(k = 900; --k;)
  16. {
  17. for(i = 3600; --i;);
  18. }
  19. }
  20.  
  21. void blinkLed1(unsigned times) {
  22. unsigned i = 0;
  23. for(i = 0; i < times; ++i) {
  24. _LATB2 = 1;
  25. a_delay();
  26. _LATB2 = 0;
  27. a_delay();
  28. }
  29. }
  30.  
  31. void blinkLed2(unsigned times) {
  32. unsigned i = 0;
  33. for(i = 0; i < times; ++i) {
  34. _LATB5 = 1;
  35. b_delay();
  36. _LATB5 = 0;
  37. b_delay();
  38. }
  39. }
  40.  
  41. int main(void)
  42. {
  43. configClock();
  44.  
  45. ODCB = 0;
  46. _ODCB14 = 1;
  47. _ODCB12 = 1;
  48.  
  49. TRISB = 0;
  50. _TRISB14 = 1;
  51. _TRISB12 = 1;
  52.  
  53. _LATB2 = 1;
  54.  
  55. unsigned state = 1;
  56. unsigned lastSwitchStateA = 0
  57. unsigned lastSwitchStateB = 0;
  58.  
  59. unsigned currentSwitchStateA = 0;
  60. unsigned currentSwitchStateB = 0;
  61.  
  62. while(1)
  63. {
  64. currentSwitchA = _LATB14;
  65. currentSwitchB = _LATB12;
  66.  
  67. if(state == 1) {
  68. if(!currentSwitchA && lastSwitchA) {
  69. _LATB2 = 0;
  70. state = 2;
  71. }
  72. } else if(state == 2) {
  73. if(!currentSwitchA && lastSwitchA) {
  74. blindLed1(2);
  75.  
  76. _LATB2 = 1;
  77. _LATB5 = 1;
  78. state = 3;
  79. }
  80. } else if(state == 3) {
  81. if(!currentSwitchA && lastSwitchA) {
  82. if(currentSwitchB)
  83. state = 1;
  84. else
  85. state = 2;
  86. }
  87. } else if(state == 4) {
  88. if(currentSwitchA) {
  89. while(1) {
  90. blinkLed1(1);
  91.  
  92. if(!currentSwitchA) {
  93. state = 5;
  94. break;
  95. }
  96. }
  97. }
  98. } else if(state == 5) {
  99. while(1) {
  100. blinkLed2(1);
  101.  
  102. if(!currentSwitchA && lastSwitchA) {
  103. state = 6;
  104. break;
  105. }
  106. }
  107. } else if(state == 6) {
  108. while(1) {
  109. blinkLed1(1);
  110. blinkLed2(1);
  111.  
  112. if(!currentSwitchA && lastSwitchA) {
  113. _LATB2 = 0;
  114. _LATB5 = 0;
  115. state = 1;
  116. }
  117. }
  118. }
  119.  
  120. lastSwitchStateA = currentSwitchStateA;
  121. lastSwitchStateB = currentSwitchStateB;
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement