#include #define TRIGGER 12000 #define DATA BIT0 //DS 1.0 #define CLOCK BIT4 // SH_CP 1.4 #define LATCH BIT5 // ST_CP 1.5 #define ENABLE BIT6 // OE 1.6 #define BUTTON BIT3 // BP 1.3 #define DIGIT1 BIT3 #define DIGIT2 BIT2 #define DIGIT3 BIT1 #define DIGIT4 BIT0 #define B0 0b11111100 #define B1 0b01100000 #define B2 0b11011010 #define B3 0b11110010 #define B4 0b01100110 #define B5 0b10110110 #define B6 0b10111110 #define B7 0b11100000 #define B8 0b11111110 #define B9 0b11110110 //Declaration des prototypes de fonctions void delay(unsigned int ms); void enable(void); void shiftOut(unsigned char val); void pinWrite(unsigned int bit, unsigned char val); void pulseClock(void); void configTimerA2(void); void main(void) { WDTCTL = WDTPW + WDTHOLD; //stop watchdog P1DIR |= (DATA + CLOCK + LATCH + ENABLE); //mise en sortie P2DIR |= (DIGIT1 + DIGIT2 + DIGIT3 + DIGIT4); P1OUT |= ENABLE; //activer le OE sur shift P2OUT &= ~DIGIT1; P2OUT &= ~DIGIT2; P2OUT &= ~DIGIT3; P2OUT &= ~DIGIT4; int i, m=0, c=0, d=0, u=0; for(;;) { P2OUT |= DIGIT1; switch(u) { case 0: { shiftOut(B0); break;} case 1: { shiftOut(B1); break;} case 2: { shiftOut(B2); break;} case 3: { shiftOut(B3); break;} case 4: { shiftOut(B4); break;} case 5: { shiftOut(B5); break;} case 6: { shiftOut(B6); break;} case 7: { shiftOut(B7); break;} case 8: { shiftOut(B8); break;} case 9: { shiftOut(B9); break;} } u++; if(u>9) { d++; u=0; } P2OUT &= ~DIGIT1; P2OUT |= DIGIT2; switch(d) { case 0: { shiftOut(B0); break;} case 1: { shiftOut(B1); break;} case 2: { shiftOut(B2); break;} case 3: { shiftOut(B3); break;} case 4: { shiftOut(B4); break;} case 5: { shiftOut(B5); break;} case 6: { shiftOut(B6); break;} case 7: { shiftOut(B7); break;} case 8: { shiftOut(B8); break;} case 9: { shiftOut(B9); break;} } if(d>9) { c++; d=0; } P2OUT &= ~DIGIT2; P2OUT |= DIGIT3; switch(c) { case 0: { shiftOut(B0); break;} case 1: { shiftOut(B1); break;} case 2: { shiftOut(B2); break;} case 3: { shiftOut(B3); break;} case 4: { shiftOut(B4); break;} case 5: { shiftOut(B5); break;} case 6: { shiftOut(B6); break;} case 7: { shiftOut(B7); break;} case 8: { shiftOut(B8); break;} case 9: { shiftOut(B9); break;} } P2OUT &= ~DIGIT3; P2OUT |= DIGIT4; switch(m) { case 0: { shiftOut(B0); break;} case 1: { shiftOut(B1); break;} case 2: { shiftOut(B2); break;} case 3: { shiftOut(B3); break;} case 4: { shiftOut(B4); break;} case 5: { shiftOut(B5); break;} case 6: { shiftOut(B6); break;} case 7: { shiftOut(B7); break;} case 8: { shiftOut(B8); break;} case 9: { shiftOut(B9); break;} } P2OUT &= ~DIGIT4; } } void configTimerA2(void) { CCTL0 = CCIE; CCR0 = 12000; TACTL = TASSEL_1 + MC_2; // TimerA control register = select ACLK2 + Continous mode _BIS_SR(GIE); } void delay(unsigned int ms) { while(ms--) { __delay_cycles(1000); } } void shiftOut(unsigned char val) { P1OUT &= ~LATCH; int i; for(i=0; i<8; i++) { pinWrite(DATA, (val & (1 << i))); pulseClock(); } P1OUT |= LATCH; P1OUT &= ~LATCH; } void pinWrite(unsigned int bit, unsigned char val) { if(val) P1OUT |= bit; else P1OUT &= ~bit; } void pulseClock(void) { P1OUT |= CLOCK; P1OUT &= ~CLOCK; } #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A(void) { }