Pages: [1]   Go Down
Author Topic: 74HC595 used for shift input not output!  (Read 914 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
« Last Edit: May 01, 2013, 03:24:29 am by Coding Badly » Logged

Offline Offline
Sr. Member
****
Karma: 3
Posts: 259
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 30, 2013, 09:56:51 pm by be80be » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 637
Posts: 34597
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Sr. Member
****
Karma: 9
Posts: 252
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you probably not talking about this guy.

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





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.
Logged

My 3x3x3 Led Cube

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

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

thanks for the help so far
Logged

Offline Offline
Sr. Member
****
Karma: 3
Posts: 259
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
 
Logged

Pages: [1]   Go Up
Jump to: