main.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <msp430g2553.h>
  2. // 74HC Pins
  3. #define DATA BIT0 //DS 1.0
  4. #define CLOCK BIT4 // SH_CP 1.4
  5. #define LATCH BIT5 // ST_CP 1.5
  6. //4017 Pins
  7. #define CLOCKCP BIT6 // Clock 1.2
  8. #define RESET BIT3 // Reset 1.3
  9. //Declaration des prototypes de fonctions
  10. void delay(unsigned int ms);
  11. void pushRegister(int val);
  12. void pinWrite(unsigned int bit, unsigned char val);
  13. void main(void) {
  14. WDTCTL = WDTPW + WDTHOLD; //stop watchdog
  15. P1DIR |= (DATA + CLOCK + LATCH + CLOCKCP + RESET); //mise en sortie
  16. P1OUT |= RESET; //on reset le 4017
  17. P1OUT &= ~RESET;
  18. for(;;) {
  19. pushRegister(0b11111100);
  20. pushRegister(0b11111000);
  21. pushRegister(0b11110000);
  22. pushRegister(0b11100000);
  23. pushRegister(0b11000000);
  24. pushRegister(0b10000000);
  25. pushRegister(0b00000000);
  26. pushRegister(0b11111111);
  27. P1OUT |= RESET;
  28. P1OUT &= ~RESET;
  29. }
  30. }
  31. void delay(unsigned int ms) {
  32. while(ms--) {
  33. __delay_cycles(1000);
  34. }
  35. }
  36. void pushRegister(int val) {
  37. P1OUT &= ~LATCH;
  38. int i;
  39. for(i=0; i<8; i++) {
  40. pinWrite(DATA, (val & (1 << i)));
  41. P1OUT |= CLOCK; //clock 74HC
  42. P1OUT &= ~CLOCK;
  43. }
  44. P1OUT |= LATCH;
  45. P1OUT &= ~LATCH;
  46. for(i=0; i<8; i++) {
  47. pinWrite(DATA, 0);
  48. P1OUT |= CLOCK; //clock 74hc
  49. P1OUT &= ~CLOCK;
  50. }
  51. P1OUT |= LATCH;
  52. P1OUT |= CLOCKCP; //clock 4017
  53. P1OUT &= ~CLOCKCP;
  54. }
  55. void pinWrite(unsigned int bit, unsigned char val) {
  56. if(val) P1OUT |= bit;
  57. else P1OUT &= ~bit;
  58. }