Tuesday , February 21 2017
Home / Embedded Systems / Basics / Interface 7 Segment Display with Microcontroller

Interface 7 Segment Display with Microcontroller

The 7 segment display is widely used to display numeric data. They are limited by the number of segments (LEDs) they have and hence are not suitable for displaying text. There are some variants of this kind of displays that have 11 segments which enables them to display text also.

name

This post will deal with the basics of 7 segment displays and how to interface them with microcontrollers. As the name suggests, there are 7 segments to display a number and an additional decimal point. These are essentially LED that turn on according to the excitation given by the controller that gives the appearance of the number.

These segments are named with alphabets A through G with a DP (Decimal Point) or in some cases an eighth alphabet H. These 8 pins corresponding to each the segments are connected to the port pins of a microcontroller.

While addressing these segments, (in most cases) A is the LSB and DP is the MSB. If you are using a development board, you should read it’s documentation before addressing them.

Types of 7 Segment Displays

Are there two of ’em?

Yes, there are two types of 7 segment displays. They look alike and there is no way to tell which one you have by just seeing it. If you desoldered it from somewhere, hope you have some marking over it. Though it is not impossible, you will have a difficult time making out what-is-what without part names.

Types 7 segment displays

These types are based on which type of pin each LED is tied together. If all the cathodes are grouped to give a singe cathode it called Common Cathode type displays. Similarly there is a Common Anode type which as the name suggests, has the cathode of all the LED put together to form a single cathode.

Wiring them up to a Microcontroller

Here is the circuit diagram my development board has. I guess this is the best way to connect these displays. Any other method I can think off uses more pins for the microcontroller.

circuit

 

This connection has a common data bus for all the segments and has a separate enable line for each segment that is used to turn ON and turn OFF that particular segment.

So far it appears as though, only one segment can be used at time as the data lines are shared with all the 4 segments.

ie., If you latch something to the data bus, and enable all the pins,(send it a logic HIGH from the MCU) then the same data will be displayed on all the four segments.

If that were the case, then the whole point of having a 4 digit display would be lost. That is when we will exploit the disability (well not exactly) of the human eye.

Concept of Persistence of Vision (POV)

The human eye has the ability to hold a memory of light signal for some time after they are gone. Put it numerically, your eye will hold the light signal for a little over one quarter of a second. This time is directly proportional to the brightness of the light signal.

So if you turn ON and OFF a light faster than that, you won’t be able to notice the light going OFF. Our microcontroller instructions are operated in a few hundred nanoseconds, toggling a pin or a set of pins at 50 or 60 Hertz is no big deal.

Here is a small video to demonstrate the concept of POV,

Logic to use all the 4 digits of the display

To use all the 4 displays to display 4 different data at the same time, you should follow this sequence.

  1. Write data to be displayed to Segment 1 into the data latch.
  2. Enable First Segment.
  3. Wait for some time.
  4. Disable First Segment.
  5. Write the data for the next segment.
  6. Enable the Next Segment
  7. Wait for some time.
  8. Disable that Segment
  9. Do it for all the segments
  10. Repeat all the above steps.

This way you will be able to use all the 4 digits to do some useful work. The key is to know how fast is enough. If you are running too fast, it’s a waste of processor time which prevents any other useful work from happening.

Framing the data

The data (bitmap) has to be sent the 7 segment display fr0m the controller to the data bus. So we have to have a pre determined set of bitmaps for the numbers that we would be using.

In any kind of application, it’s good practice to have a Look-up-Table for the data to be displayed on the 7 segment. The data to be displayed has to be framed separately for common cathode and common anode type displays

Common Cathode Configuration
Number To display H G F E D C B A HEX
0 0 0 1 1 1 1 1 1 0x3F
1 0 0 0 0 0 0 1 1 0x06
2 0 1 0 1 1 0 1 1 0x5B
3 0 1 0 0 1 1 1 1 0x4F
4 0 1 1 0 0 1 1 0 0x66
5 0 1 1 0 1 1 0 1 0x6D
6 0 1 1 1 1 1 0 1 0x7D
7 0 0 0 0 0 1 1 1 0x07
8 0 1 1 1 1 1 1 1 0x7F
9 0 1 1 0 1 1 1 1 0x6F
Common Anode Configuration
Number To display H G F E D C B A HEX
0 1 1 0 0 0 0 0 0 0xC0
1 1 1 1 1 1 1 0 0 0xFC
2 1 0 1 0 0 1 0 0 0xA4
3 1 0 1 1 0 0 0 0 0xB0
4 1 0 0 1 1 0 0 1 0x99
5 1 0 0 1 0 0 1 0 0x92
6 1 0 0 0 0 0 1 0 0x82
7 1 1 1 1 1 0 0 0 0xF8
8 1 0 0 0 0 0 0 0 0x80
9 1 0 0 1 0 0 0 0 0x90

Look Up Table

Once you have all the values to be written to the display you have to create the lookup table. The lookup table is nothing but an array which has all the above values. So the code looks into this array and fetches the data to be written to the display.

So a reference to lookup[5] will return the actual display equivalent of 5 for the 7 segment display.

In upcoming posts we will discuss a lot more about the programming of 7 segment displays.

About Siddharth

Siddharth is a Firmware Engineer, techie, and a movie-buff. His interests include, Programming, Embedded Systems, Linux, Robotics, CV, Carpentry and a lot more. At times, you could see some of his sunday projects converge on release quality. You get to know him on the following social channels.

Check Also

c2000_lauchpad

Interfacing 16×2 LCD with C2000 launchpad

  The C2000 Launchpad is an inexpensive evaluation module based on Piccolo family microcontrollers from …

  • 7 SEG ,4DIGIT LED NONSERIAL INTERFACE TO PIC 18F452 , SOURCE CODES TO RUN ON PIC DEVPT BOARD WITH US

  • Jan

    how you can transform from the hex value in the lookup table to control signals for the mcu?

  • bipin

    In Common Anode Configuration, the correct hex code for 1 is : F9 ( not FC ) !

Keep in touch with the current trends!
Did you like this article? Sign up and get our latest posts delivered to your inbox!
  We hate spam and never share your details.