74LS47N

74LS47N BCD-to-7-segment-decoder

In the last tutorial we used a 7-segment display and connected this with our Arduino Uno directly. To do this, we used 8 wires. It’s a lot!
There are two things we want to change now. First, we reduce the number of wires to communicate with the Arduino. And second, we “talk” with it binary!
We use the IC 74LS47N. This circuit is a binary-to-decimal to 7-segment decoder. It has two task: translate a binary input in a decimal output and prepare the output to connect a 7-segment display directly.
The input is a digit in binary format, i.e. the input is “5”, we send “0101” to the IC. As the result are the pins a, f, g,c and d active and we will see “5” at the 7-segment-display.

The advantage to use the 74LS47N is, we need only 4 wires for the input, no more. And, we can reduce our array to store the different values.

Task:

Control a 7-segment Display by using the IC 74LS47N!

In this tutorial, I use an 7-segment display with common anode:

The circuit:

1.4.1 BCD to 7-segment

I think, my own draft is better than the “fritzing draft” for understanding, so I show you both.

2014-01-12 14.28.06

74LS47N:
We have 4 pins for data input and 7 pins for data output. Ground and Vcc. The remaining 3 pins are not in use in this tutorial. Necessary only to connect this pins to Vcc.  For more informations please look at the datasheet for the 74LS47N!

Attention! The output pins are active LOW! Therefore we must use an 7-segment display with a common anode!
You can identify the active LOW state at the negate letters. Simplified you can say, if an output pin is active, there is GND at this pin.

For this tutorial, wee need the following components:

  • SA56-11GMA (common anode, green) or similar
  • 7x resistors (min. 150 ohm), I use 270 ohm

Here is the wiring diagram:

1.4.1 BCD to 7-segment-circuit

The Arduino sketch:

/*
BCD to 7-segment-display
playground2014.wordpress.com
*/

int dtime;
byte ziffer[11][4] = { { 0,0,0,0 }, // = 0
                       { 0,0,0,1 }, // = 1
                       { 0,0,1,0 }, // = 2
                       { 0,0,1,1 }, // = 3
                       { 0,1,0,0 }, // = 4
                       { 0,1,0,1 }, // = 5
                       { 0,1,1,0 }, // = 6
                       { 0,1,1,1 }, // = 7
                       { 1,0,0,0 }, // = 8
                       { 1,0,0,1 }, // = 9
                       { 1,1,1,1 }  // = define as off - more information refer the datasheet 74LS47N
                     };

void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  digitalWrite(2, 1);
  digitalWrite(3, 1);
  digitalWrite(4, 1);
  digitalWrite(5, 1);
  delay(2000);
}

void ziffer_schreiben(byte digit) {
  digitalWrite(2,ziffer[digit][3]);
  digitalWrite(3,ziffer[digit][2]);
  digitalWrite(4,ziffer[digit][1]);
  digitalWrite(5,ziffer[digit][0]);
}

void loop() {
  dtime=700 ;
  for (int i=0; i<=9; ++i) {
    ziffer_schreiben(i) ;
    delay(dtime);
  }

  dtime=300 ;
  for (int i=8; i>=0; --i) {
    ziffer_schreiben(i) ;
    delay(dtime);
  }
}

We use (define) a function to set a digit. We start the function with the digit, which we want to see. The digit number and the row numer in our array are the same. The loop pick up each value from the array and send the correct value with digitalWrite to the related pin.

void setup() { … }
We define the direction – we use all pins as output pins.
void loop() { … }
The first part used a loop to count up to 9, starting with 0. The other loop counts down until 0. In both loop a use a different delay. It’s a little bit easier to store the delay value in a variable and to play with it.

One thought on “74LS47N

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s