0
\$\begingroup\$

I have designed and built the following 7-segment driving circuit utilising an Arduino Micro in order to try and further understand electronic circuit design:

schematic

simulate this circuit – Schematic created using CircuitLab

When turning it on and applying a HIGH voltage to the \$\text{LT}\$ and \$\text{BI}\$ inputs and a LOW voltage to the \$\text{LE}\$ input, regardless of what BCD code I supply to the CD4511BE BCD to 7-segment display driver the LED display just flashes while displaying \$0\$. If I set the \$\text{LE}\$ input to HIGH then the LED display no longer flashes but instead just displays \$0\$.

Here is the test code for the Arduino that I am using:

void setup()
{
  pinMode( 2, OUTPUT );
  pinMode( 3, OUTPUT );
  pinMode( 4, OUTPUT );
  pinMode( 5, OUTPUT );
  pinMode( 6, OUTPUT );
  pinMode( 7, OUTPUT );
  pinMode( 8, OUTPUT );
}

void loop()
{
  digitalWrite( 6, HIGH );
  digitalWrite( 7, HIGH );  

  for( int i = 0; i < 10; ++i )
  {
    digitalWrite( 8, LOW );
    digitalWrite( 2, i & 0x0001 != 0 ? HIGH : LOW );
    digitalWrite( 3, i & 0x0002 != 0 ? HIGH : LOW );
    digitalWrite( 4, i & 0x0004 != 0 ? HIGH : LOW );
    digitalWrite( 5, i & 0x0008 != 0 ? HIGH : LOW );
    digitalWrite( 8, HIGH );
    delay( 1000 );
  }

}

Further Information: The following code works as expected:

void setup()
{
  pinMode( 2, OUTPUT );
  pinMode( 3, OUTPUT );
  pinMode( 4, OUTPUT );
  pinMode( 5, OUTPUT );
  pinMode( 6, OUTPUT );
  pinMode( 7, OUTPUT );
  pinMode( 8, OUTPUT );
}

void loop()
{
  digitalWrite( 6, HIGH );
  digitalWrite( 7, HIGH );

  digitalWrite( 2, HIGH );
  digitalWrite( 3, HIGH );
  digitalWrite( 4, LOW );
  digitalWrite( 5, LOW );
  digitalWrite( 8, HIGH );
  delay( 1000 );

  digitalWrite( 8, LOW );
  digitalWrite( 2, HIGH );
  digitalWrite( 3, LOW );
  digitalWrite( 4, HIGH );
  digitalWrite( 5, LOW );
  digitalWrite( 8, HIGH );
  delay( 1000 );
}
\$\endgroup\$
3
\$\begingroup\$

From a first look and a glance at the datasheet, generally speaking this seems fine. But the Arduino isn't exactly nippy at changing those outputs and while they are changing (with LE low), the outputs will also be changing. Could that be what you mean by "flashing" display? I'd guess that the display isn't really flashing per-se, it's just changing slowly enough for you to see it as a big mess.

I would suggest setting pin 8 HIGH to begin with - which will block any changes from the BCD pins - then changing all the BCD outputs and finally setting pin 8 LOW to reflect those changes. Then delay and loop. Something like this maybe:

Important note from your code: In C at least, & has lower precedence than !=. So the expression:

i & 0x1 != 0

resolved as if you'd typed:

i & (0x1 != 0)

which is:

i & 1

That's a trap I've seen before. Use brackets to clearly state what you mean and always do so where & and | is concerned, especially if there's an == or != nearby. I've changed it below:

  ...
  for( int i = 0; i < 10; ++i )
  {
    digitalWrite( 8, HIGH );
    digitalWrite( 2, ((i & 0x0001) != 0) ? HIGH : LOW );
    digitalWrite( 3, ((i & 0x0002) != 0) ? HIGH : LOW );
    digitalWrite( 4, ((i & 0x0004) != 0) ? HIGH : LOW );
    digitalWrite( 5, ((i & 0x0008) != 0) ? HIGH : LOW );
    digitalWrite( 8, LOW );
    delay( 1000 );
  }
\$\endgroup\$
  • \$\begingroup\$ By a flashing display, I meant the entire display would go dark and then illuminate the 0 again and alternate, however your code has worked so I think you were right about the cause of the issue! Also, I totally forgot about operator precedence; thanks!! :D Actually, thinking about it, the operator precedence was the whole issue; the display blanks if the code is higher than \$1001\$, in this case the code was either \$0000\$ or \$1111\$, which would explain the issue! \$\endgroup\$ – Thomas Russell Apr 20 '14 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.