main.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include <msp430g2553.h>
  2. #define TRIGGER 12000
  3. #define DATA BIT0 //DS 1.0
  4. #define CLOCK BIT4 // SH_CP 1.4
  5. #define LATCH BIT5 // ST_CP 1.5
  6. #define ENABLE BIT6 // OE 1.6
  7. #define BUTTON BIT3 // BP 1.3
  8. #define DIGIT1 BIT3
  9. #define DIGIT2 BIT2
  10. #define DIGIT3 BIT1
  11. #define DIGIT4 BIT0
  12. #define B0 0b11111100
  13. #define B1 0b01100000
  14. #define B2 0b11011010
  15. #define B3 0b11110010
  16. #define B4 0b01100110
  17. #define B5 0b10110110
  18. #define B6 0b10111110
  19. #define B7 0b11100000
  20. #define B8 0b11111110
  21. #define B9 0b11110110
  22. //Declaration des prototypes de fonctions
  23. void delay(unsigned int ms);
  24. void enable(void);
  25. void shiftOut(unsigned char val);
  26. void pinWrite(unsigned int bit, unsigned char val);
  27. void pulseClock(void);
  28. void configTimerA2(void);
  29. void main(void) {
  30. WDTCTL = WDTPW + WDTHOLD; //stop watchdog
  31. P1DIR |= (DATA + CLOCK + LATCH + ENABLE); //mise en sortie
  32. P2DIR |= (DIGIT1 + DIGIT2 + DIGIT3 + DIGIT4);
  33. P1OUT |= ENABLE; //activer le OE sur shift
  34. P2OUT &= ~DIGIT1;
  35. P2OUT &= ~DIGIT2;
  36. P2OUT &= ~DIGIT3;
  37. P2OUT &= ~DIGIT4;
  38. int i, m=0, c=0, d=0, u=0;
  39. for(;;) {
  40. P2OUT |= DIGIT1;
  41. switch(u) {
  42. case 0: { shiftOut(B0); break;}
  43. case 1: { shiftOut(B1); break;}
  44. case 2: { shiftOut(B2); break;}
  45. case 3: { shiftOut(B3); break;}
  46. case 4: { shiftOut(B4); break;}
  47. case 5: { shiftOut(B5); break;}
  48. case 6: { shiftOut(B6); break;}
  49. case 7: { shiftOut(B7); break;}
  50. case 8: { shiftOut(B8); break;}
  51. case 9: { shiftOut(B9); break;}
  52. }
  53. u++;
  54. if(u>9) {
  55. d++;
  56. u=0;
  57. }
  58. P2OUT &= ~DIGIT1;
  59. P2OUT |= DIGIT2;
  60. switch(d) {
  61. case 0: { shiftOut(B0); break;}
  62. case 1: { shiftOut(B1); break;}
  63. case 2: { shiftOut(B2); break;}
  64. case 3: { shiftOut(B3); break;}
  65. case 4: { shiftOut(B4); break;}
  66. case 5: { shiftOut(B5); break;}
  67. case 6: { shiftOut(B6); break;}
  68. case 7: { shiftOut(B7); break;}
  69. case 8: { shiftOut(B8); break;}
  70. case 9: { shiftOut(B9); break;}
  71. }
  72. if(d>9) {
  73. c++;
  74. d=0;
  75. }
  76. P2OUT &= ~DIGIT2;
  77. P2OUT |= DIGIT3;
  78. switch(c) {
  79. case 0: { shiftOut(B0); break;}
  80. case 1: { shiftOut(B1); break;}
  81. case 2: { shiftOut(B2); break;}
  82. case 3: { shiftOut(B3); break;}
  83. case 4: { shiftOut(B4); break;}
  84. case 5: { shiftOut(B5); break;}
  85. case 6: { shiftOut(B6); break;}
  86. case 7: { shiftOut(B7); break;}
  87. case 8: { shiftOut(B8); break;}
  88. case 9: { shiftOut(B9); break;}
  89. }
  90. P2OUT &= ~DIGIT3;
  91. P2OUT |= DIGIT4;
  92. switch(m) {
  93. case 0: { shiftOut(B0); break;}
  94. case 1: { shiftOut(B1); break;}
  95. case 2: { shiftOut(B2); break;}
  96. case 3: { shiftOut(B3); break;}
  97. case 4: { shiftOut(B4); break;}
  98. case 5: { shiftOut(B5); break;}
  99. case 6: { shiftOut(B6); break;}
  100. case 7: { shiftOut(B7); break;}
  101. case 8: { shiftOut(B8); break;}
  102. case 9: { shiftOut(B9); break;}
  103. }
  104. P2OUT &= ~DIGIT4;
  105. }
  106. }
  107. void configTimerA2(void) {
  108. CCTL0 = CCIE;
  109. CCR0 = 12000;
  110. TACTL = TASSEL_1 + MC_2; // TimerA control register = select ACLK2 + Continous mode
  111. _BIS_SR(GIE);
  112. }
  113. void delay(unsigned int ms) {
  114. while(ms--) {
  115. __delay_cycles(1000);
  116. }
  117. }
  118. void shiftOut(unsigned char val) {
  119. P1OUT &= ~LATCH;
  120. int i;
  121. for(i=0; i<8; i++) {
  122. pinWrite(DATA, (val & (1 << i)));
  123. pulseClock();
  124. }
  125. P1OUT |= LATCH;
  126. P1OUT &= ~LATCH;
  127. }
  128. void pinWrite(unsigned int bit, unsigned char val) {
  129. if(val) P1OUT |= bit;
  130. else P1OUT &= ~bit;
  131. }
  132. void pulseClock(void) {
  133. P1OUT |= CLOCK;
  134. P1OUT &= ~CLOCK;
  135. }
  136. #pragma vector=TIMERA0_VECTOR
  137. __interrupt void Timer_A(void) {
  138. }