#include // 74HC Pins #define DATA BIT0 //DS 1.0 #define CLOCK BIT4 // SH_CP 1.4 #define LATCH BIT5 // ST_CP 1.5 //4017 Pins #define CLOCKCP BIT6 // Clock 1.2 #define RESET BIT3 // Reset 1.3 //Declaration des prototypes de fonctions void delay(unsigned int ms); void pushRegister(int val); void pinWrite(unsigned int bit, unsigned char val); void main(void) { WDTCTL = WDTPW + WDTHOLD; //stop watchdog P1DIR |= (DATA + CLOCK + LATCH + CLOCKCP + RESET); //mise en sortie P1OUT |= RESET; //on reset le 4017 P1OUT &= ~RESET; for(;;) { pushRegister(0b11111100); pushRegister(0b11111000); pushRegister(0b11110000); pushRegister(0b11100000); pushRegister(0b11000000); pushRegister(0b10000000); pushRegister(0b00000000); pushRegister(0b11111111); P1OUT |= RESET; P1OUT &= ~RESET; } } void delay(unsigned int ms) { while(ms--) { __delay_cycles(1000); } } void pushRegister(int val) { P1OUT &= ~LATCH; int i; for(i=0; i<8; i++) { pinWrite(DATA, (val & (1 << i))); P1OUT |= CLOCK; //clock 74HC P1OUT &= ~CLOCK; } P1OUT |= LATCH; P1OUT &= ~LATCH; for(i=0; i<8; i++) { pinWrite(DATA, 0); P1OUT |= CLOCK; //clock 74hc P1OUT &= ~CLOCK; } P1OUT |= LATCH; P1OUT |= CLOCKCP; //clock 4017 P1OUT &= ~CLOCKCP; } void pinWrite(unsigned int bit, unsigned char val) { if(val) P1OUT |= bit; else P1OUT &= ~bit; }