Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #include "io430.h"
  2.  
  3.  
  4. enum dioda {
  5. STATUS,
  6. REL1,
  7. REL2
  8. };
  9.  
  10. enum button {
  11. pierwszy,
  12. drugi,
  13. trzeci,
  14. czwarty
  15. };
  16.  
  17.  
  18. void init()
  19. {
  20. P1DIR = P1DIR | (BIT5 | BIT6); // diody REL1 i REL2
  21. P2DIR = P2DIR | BIT1; // dioda status
  22. P4DIR = P4DIR & ~(BIT4 | BIT5 | BIT6 | BIT7); // przyciski
  23. P2OUT = P2OUT | BIT1; // zgaszenie diody status
  24. P1OUT = P1OUT & ~(BIT5 | BIT6); // zgaszenie diod REL1 i REL2
  25. }
  26.  
  27. void delay (int x) // funkcja realizujaca opoznienie
  28. {
  29. int i,j;
  30. for (i=0;i<1000;i++)
  31. for (j=0;j<x;j++)
  32. {
  33. }
  34. }
  35.  
  36. int isButtonPressed(button b)
  37. {
  38. if(b == pierwszy) return ((P4IN & BIT4) == 0);
  39. if(b == drugi) return ((P4IN & BIT5) == 0);
  40. if(b == trzeci) return ((P4IN & BIT6) == 0);
  41. if(b == czwarty) return ((P4IN & BIT7) == 0);
  42. return 0;
  43. }
  44.  
  45. void diodaOn(dioda d)
  46. {
  47. if(d == REL1) P1OUT = P1OUT | BIT5;
  48. if(d == REL2) P1OUT = P1OUT | BIT6;
  49. if(d == STATUS) P2OUT = P2OUT & ~BIT1;
  50. }
  51.  
  52. void diodaOff(dioda d)
  53. {
  54. if(d == REL1) P1OUT = P1OUT & ~BIT5;
  55. if(d == REL2) P1OUT = P1OUT & ~BIT6;
  56. if(d == STATUS) P2OUT = P2OUT | BIT1;
  57. }
  58. int main( void )
  59. {
  60. // Stop watchdog timer to prevent time out reset
  61. WDTCTL = WDTPW + WDTHOLD;
  62.  
  63. init();
  64.  
  65.  
  66. while(1)
  67. {
  68.  
  69. if(isButtonPressed(pierwszy))
  70. {
  71. diodaOn(REL1);
  72. delay(1000);
  73. //if(button_pressed(pierwszy))
  74. diodaOn(REL2);
  75. }
  76. //delay(1000);
  77. // if(button_pressed(pierwszy)) dioda_off();
  78.  
  79. if(isButtonPressed(drugi)) diodaOff(REL1);
  80.  
  81. if(isButtonPressed(trzeci)) diodaOn(REL2);
  82. if(isButtonPressed(czwarty)) diodaOff(REL2);
  83. if(isButtonPressed(pierwszy)) diodaOn(STATUS);
  84. else diodaOff(STATUS);
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement