Go Down

Topic: 74HC595 used for shift input not output! (Read 1 time) previous topic - next topic

jjrabie

May 01, 2013, 04:46 am Last Edit: May 01, 2013, 10:24 am by Coding Badly Reason: 1
I recently saw a guy using 74HC595 shift registers for input rather than output and couldn't understand how the hell he did that. He also was sending only 4 wires to his Arduino (for 5v, GND, Serial and Clock.....no Latch)....and it worked? How did this happen?

Has anybody here done that before?

Here is his code that does the shifting but I don't really understand it...(i know there are some other parts which this code refers to and if u want to see it I can post more but this was the part I was having trouble understanding)

//This is the meat of the code.   It shifts bits down the shift registers until a signal is received back at the KEYpin, which tells it what key has been pressed.

Code: [Select]
byte waitForKeystroke(){

 byte key = 0;
 byte doublecheckkey  = 0;
 unsigned int keypress_count = 0;

 //LOOP UNTIL A KEY IS PRESSED  
 while(key == 0){

   if(waitcount<30000){
     waitcount++;
   }

   digitalWrite(SERpin,HIGH);
   pulseHigh(RCLKpin);
   digitalWrite(SERpin,LOW);

   // 1500 nanoseconds = 1.5 uS = probably used because old Arduino delayMicroseconds used to disable interrupts
   asm("nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;");
   asm("nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;");

   for (int shift_i = 1; shift_i<95;shift_i++) {
     pulseHigh(RCLKpin);
     if (digitalRead(KEYpin) == HIGH){
       key = shift_i;
     }
   }

   if(digitalRead(7) != polarity7) {key = 96;}  
   if(digitalRead(8) != polarity8) {key = 97;}
   if(digitalRead(9) != polarity9) {key = 98;}
   if(digitalRead(10) != polarity10) {key = 99;}

   //if(digitalRead(TEACHpin) == 0){key = 96;}//teachpin used as general input for modvic
 } // END OF WHILE LOOP


 // DOUBLE-CHECK:
 digitalWrite(SERpin,HIGH);
 pulseHigh(RCLKpin);
 digitalWrite(SERpin,LOW);

 asm("nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;");
 asm("nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;");

 for (int shift_i = 1; shift_i<95;shift_i++){
   pulseHigh(RCLKpin);
   if (digitalRead(KEYpin) == HIGH){
     doublecheckkey = shift_i;
   }
 }

 if(doublecheckkey != key) {key = INVALID;}

 if(digitalRead(7) != polarity7) {key = 96;} // commented out for modvic
 if(digitalRead(8) != polarity8) {key = 97;}
 if(digitalRead(9) != polarity9) {key = 98;}
 if(digitalRead(10) != polarity10) {key = 99;}

 //   if(digitalRead(TEACHpin) == 0) {key = 96;} //teachpin used as general input for modvic

 return key;

}



Moderator edit: [code] [/code] tags added.

be80be

#1
May 01, 2013, 04:54 am Last Edit: May 01, 2013, 04:56 am by be80be Reason: 1
Its easy he is reading a keypad where you set just one columns high and scan the rows for a press.
Or set one row high and scan the columns which ever way you want to do it.
But he is not reading it as a input.

Grumpy_Mike

Quote
I recently saw a guy using 74HC595 shift registers for input rather than output

No you did not. You misunderstood.
Read the how to use this forum sticky post. Look at your code, is it how you posted it?

American2020

I think you probably not talking about this guy.

Take a look at his video and his follow up video:

http://www.youtube.com/watch?v=nXl4fb_LbcI

http://www.youtube.com/watch?v=1Vb2BpxPnjU

Both greats, and you will fully understand this and how it's done. I think it's ok for "playing" but... I read this comment on his videos

Quote
Why didn't you used a? parallel-in serial-out shift register,? like the 74165?


...so, for playing around its ok, otherwise you can get those type of Shift Registers for the job.
My 3x3x3 Led Cube

[url=http://arduino.cc/forum/index.php/topic,1642

jjrabie

any idea how he was only using 4 wires to the microcontroller? (5v, GND, Ser, Clk)

thanks for the help so far

be80be

He is pulling the latch to ground. It's in the datasheet outputs active when E pin is low so you tie it low and just use the data and the clock

Go Up