// sr.c //RLT 10.6.06 #define F_CPU 16000000 #include #include uint8_t out_var; //global for holding output data void clk_shift_reg(){ //toggle bit 1 -- shift register clock PORTB = PORTB | 0x02; PORTB = PORTB & 0xFD; // PORTB = 0x02; // PORTB = 0xFD; } void clk_output_reg(){ //toggle bit 2 -- output register clock PORTB = PORTB | 0x04; PORTB = PORTB & 0xFB; // PORTB = 0x04; // PORTB = 0xFB; } void send_data(){ //send eight bits of data uint8_t mask; uint8_t i; mask = 0x01; //setup bit mask //for(i=0; i<=8; i++){ //do for 8 bits for(i=0; i<=7; i++){ //do for 8 bits //clk_shift_reg(); //clock in data bit if(out_var & mask) //test each bit of out_var PORTB = PORTB | 0x01; //set data bit to 1 else PORTB = PORTB & 0xFE; //set data bit to 0 mask = mask << 1; //shift mask left once clk_shift_reg(); //clock in data bit }//for }//send_data int main() { uint8_t i,j; DDRB = 0x07; //lower three bits of port b form interface PORTB = 0x00; //initalize to zero while(1){ out_var = 0x01; //start with bit in zero position for(i=0; i<=7; i++){ //rotate through all positions send_data(); //send 8 bits clk_output_reg(); //send data to output register out_var = out_var << 1; //shift the bit left for next time for(j=0; j<=5; j++){ _delay_ms(200);} //wait to make it visible }//for i }//while }//main