Go Down

Topic: Controling 3 SHIFT REGISTERS with 5 pins (Read 499 times) previous topic - next topic

zholy

May 22, 2010, 09:01 pm Last Edit: May 22, 2010, 10:47 pm by zholy Reason: 1
Hi ... could someone help me ???

I'm trying to control 3 SR(shift registers) by using 5 pins (not 3 like it is in the tutorial). I know that I can connect the registers through the 9pin and shift out the data like this :

SHIFTOUT (blabla);
SHIFTOUT (blabla);
SHIFTOUT (blabla);

But what I'm trying to do, is to make the CLOCK(12)&LATCH(8) pin common for all three SR ... but for each SR to use individual PIN (9-11) for DATA transfer.

This is the code, what I have done so far :
Code: [Select]
// pin 8 = LATCH
// pin 9-11 = DATA
// pin 12 = CLOCK


void setup(){

//DDRB = B11111010;
pinMode(8,OUTPUT);  
pinMode(9,OUTPUT);  
pinMode(10,OUTPUT);  
pinMode(11,OUTPUT);  
pinMode(12,OUTPUT);

digitalWrite(8, HIGH);  
for (int i=0; i<8; i++)
 {
 digitalWrite(9, 20&(1<<i)); //20=00010100 is the pattern for LED
 digitalWrite(10, 8&(1<<i)); //8 - pattern
 digitalWrite(11, 4&(1<<i)); //4 - pattern
 
 digitalWrite(12, HIGH);
 digitalWrite(12, LOW);
 
digitalWrite(8, LOW);

 }
}

void loop(){}


This is the one, that is working fine.

But this one is not :

Code: [Select]
// pin 8 = LATCH
// pin 9-11 = DATA
// pin 12 = CLOCK

void setup(){
DDRB = B11111000; //set pin 8-12 to OUTPUT

PORTB = B10000000; //digitalWrite(8, HIGH)

for (int i=0; i<8; i++)
 {
   PORTB = B10000000;
   if ((B00101000&(128>>i))!=0) PORTB = PORTB|64; //B00101000 is the LED pattern for 1SR
   if ((B00001000&(128>>i))!=0) PORTB = PORTB|32; //B00001000 is the LED pattern for 2SR
   if ((B00000100&(128>>i))!=0) PORTB = PORTB|16; //B00000100 is the LED pattern for 3SR
   PORTB = PORTB|8; //CLOCK HIGH  
   PORTB = PORTB^8; //CLOCK LOW
 }
PORTB = B00000000; //digitalWrite(8, LOW)
}
 

void loop(){}


When I run this code ... each ShiftRegister has several pins ON ?!?! I don't know why ??? And ... after I press RESET on the arduino the pins on SR change randomly/differently.

Thank you in advance, for your advise/help.


Go Up