HELP: 2 7 segment display (0-F) using 74LS595 shift register with 8 bit inputs

HI GUYS!
Please bear with me if you think Im too stupid for you.
Im doing a project for my school(yes, during this Christmas break, ughh, this is not a break though).

Now, after a couple of days staying up super late, I finally figured out how to burn (REALLY! 100% no error) the bootloader for arduino duemilanove using the ARDUINO ISP + breadboard. And Im happy.
What's the point? My point is... I did my best to have a research about my problem, and I luckily solved that, BUT, here comes my new problem (yes I already did some searching).

Here's the last website I have visited:
http://www.sweeting.org/mark/blog/2011/11/27/arduino-74hc595-shift-register-and-a-7-segment-led-display#comment-147068

That taught me many things. It uses only 1 7segment for the readers to fully understand the concept.
Unfortunately, I have no much time remaining to study and study and study many concepts.

I posted this comment on the author's page:

"yo mark. thanks for the code! thanks for the explanation as well.
However, I have a question. Is it possible for me to do this?
I have 4 switches. Representing ABCD (4 bits) binary numbers.
Say, my inputs are 1001, that is 9. I want the 9 to be displayed in my 7segment. I tried my best to modify the code, but I just wasn't able to do it. :frowning: mind to help?

PS: I have to do this for 8 bits. two 4-inputs(that is 8 inputs) and 2 7segment. would my arduino pins be enough for this?

glenn"

anyways, I modified the code: But Im doing it wrong.

void loop()
{
    // update digit every two seconds
    t2 = millis();
  
    if(Ain == HIGH && Bin == High && Cin == HIGH && Din == HIGH) show(numbers[15]); //to display F
}

This is for my HEX Display Decoder. All of the HEX Display Drivers IC are not available in my country. Such as Fairchild DM9368 :((

:frowning: help please.
Ill come back after 5 hours.

Hi guys, Forgive me, But I think I will get more answers here. I have posted same post in other board.

Anyway...
Here's the last website I have visited:
http://www.sweeting.org/mark/blog/2011/11/27/arduino-74hc595-shift-register-and-a-7-segment-led-display#comment-147068

That taught me many things. It uses only 1 7segment for the readers to fully understand the concept.
Unfortunately, I have no much time remaining to study and study and study many concepts.

I posted this comment on the author's page:

"yo mark. thanks for the code! thanks for the explanation as well.
However, I have a question. Is it possible for me to do this?
I have 4 switches. Representing ABCD (4 bits) binary numbers.
Say, my inputs are 1001, that is 9. I want the 9 to be displayed in my 7segment. I tried my best to modify the code, but I just wasn't able to do it. mind to help?

PS: I have to do this for 8 bits. two 4-inputs(that is 8 inputs) and 2 7segment. would my arduino pins be enough for this?

glenn"

anyways, I modified the code: But Im doing it wrong.

void loop()
{
    // update digit every two seconds
    t2 = millis();
  
    if(Ain == HIGH && Bin == High && Cin == HIGH && Din == HIGH) show(numbers[15]); //to display F
}

This is for my HEX Display Decoder. All of the HEX Display Drivers IC are not available in my country. Such as Fairchild DM9368 (

help please.
Ill come back after 5 hours.

up!

Ill come back after 5 hours.

Yet you're bumping your thread after 30 minutes! Be reasonable.

LOL! I just copied and pasted my post. Didn't notice the 5 hours thing. zzzz. IS that a big thing for you anyway?

Well you didn't read the sticky or your code would be in code tags. Yes, it's a big thing. A really big thing.

Read this before posting a programming question

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator

glenn_boy13:
LOL! I just copied and pasted my post.

LOL! It's called cross-posting and that gets you banned from some forums. Don't do it, thanks.

Whether it works or nor will depend, in part, on your hardware setup.

The article you referenced used a static display: each led segment display has its own register. So to display two digits, you will need to pump in two bytes, one for the first digit and another for the 2nd digit.

If you have 4 switches, one option is to convert those 4 inputs into a number:

BCD_number = 0; // clear the variable to start
BCD_number = digitalRead(Din);  // result is 0 or 1
BCD_number = BCD_Number <<1 + digitalRead(Cin); // shift over 1 bit, and add in next bit
BCD_number = BCD_Number <<1 + digitalRead(Bin); // shift over 1 bit, and add in next bit
BCD_number = BCD_Number <<1 + digitalRead(Ain); // shift over 1 bit, and add in next bit 
Serial.println (BCD_Number, DEC); // check the result

// Now use your display mapping:
shiftout(dataPin, clockPin, MSBFIRST, numbers[BCD_number] ); // lookup the mapping in the array and send it to the shift register

As an alternative to the bit-shifting approach CrossRoads describes, you could use bitWrite() to put the digital input value into a specific bit of your number. For example, if you put your input numbers into an array, you could use the array index as the bit index too. Then a for loop could be used to read the value of each input and put it in the corresponding bit of the result.

How about an example of that PeterH?

Well, I was thinking of something along these lines (untested):

const int PIN_COUNT = 4;
int pins[PIN_COUNT] = {3, 4, 5, 6};

...

byte result = 0;
for(int i = 0; i < PIN_COUNT; i++)
{
   bitWrite(result, i, digitalRead(pins[i]));
}

You still need some math then to turn that array into a number that the seven segment array definition can use, yes?

numbers[need_0-F_here]

No, that result is a number whose binary representation matches the binary states of those inputs. If the input states are 0011 then the result will be the integer 3.

numbers[result]

I see now - I had misread what the bitWrite was doing. The array only holds the pin numbers, not the actual result.

Thanks sir Nick. I was talking about the 5-hour thing and about my "UP" reply. noted.

CrossRoads:
If you have 4 switches, one option is to convert those 4 inputs into a number:

BCD_number = 0; // clear the variable to start

BCD_number = digitalRead(Din);  // result is 0 or 1
BCD_number = BCD_Number <<1 + digitalRead(Cin); // shift over 1 bit, and add in next bit
BCD_number = BCD_Number <<1 + digitalRead(Bin); // shift over 1 bit, and add in next bit
BCD_number = BCD_Number <<1 + digitalRead(Ain); // shift over 1 bit, and add in next bit
Serial.println (BCD_Number, DEC); // check the result

// Now use your display mapping:
shiftout(dataPin, clockPin, MSBFIRST, numbers[BCD_number] ); // lookup the mapping in the array and send it to the shift register

Thank you so much sir! By the way, I just have to
add this:
BCD_number = BCD_Number <<1 + digitalRead(Din); // shift over 1 bit, and add in next bit

and then copy-paste all these lines to the loop function, right?

Also, is there anything else I need to modify in the codes to display two hex digits in two 7 segment display? How am I suppose to connect the second shift register to the first one?

Yes, read the switches, make the result into a number.
Use the number to look up the character you want to send out.
Shift registers connect like this.
I don't know if your mapping has 1 = on for a segment, or if your display uses common cathode or common anode parts.
With common cathode, 1 = on for a segment. WIth common anode, 0 = on for a segment.
Don't forget the caps on the +5V pin for reliable operation.