#define CLOCKPIN BIT0 //i put all the lines at port 2 to have the Port 1 free for other things #define LATCHPIN BIT1 #define DATAIN BIT2 int i;// variable for the for loop int ticks[8]; //only needed to see what the bizarre (val & (1 << i)) in the shiftOut method does void shiftOut(int val){ //the shiftOut method to make it easier to send values to the shiftregister it contains all needed steps, and takes an eight bit value (0 to 255) P2OUT &= ~LATCHPIN; //make sure the Latch Pin is low for(i = 0; i < 8; i++) //start a loop with 8 steps from zero to eight { if((val & (1 << i))!= 0) //check if the bit at position "i" is zero or not { P2OUT |= DATAIN; //if not it should send a high to the shift register } else { P2OUT &= ~DATAIN;//if its zero send a low to the shift register } ticks[i] = val & (1 << i); //feed the array "ticks" with the result of the operation that we did in the if loop to see what happens there P2OUT |= CLOCKPIN; //Clockpin high P2OUT &= ~CLOCKPIN; // and then low to push the value to the register. } P2OUT |= LATCHPIN; //pulse the latchpin to P2OUT &= ~LATCHPIN; //send all eight states to the register } int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P2OUT = 0x00; //switch all P2 Ports off P2DIR = 0x07; //put P2.0, 2.1 and 2.2 to outputs shiftOut(149); //this starts the shift register with the given value while(1){} //endless loop }