Watch The Video Tutorial

The 7-segment display is the earliest type of an electronic display that uses 7 LEDs bars arranged in a way that can be used show the numbers 0 – 9. (actually 8 segments if you count the decimal point, but the generic name adopted is 7-segment display.) These devices are commonly used in digital clocks, electronic meters, counters, signalling, and other equipment for displaying numeric only data.

Connection of a 7-Segment display to a PIC microcontroller

                Figure 1: 7-Segment display connected to PIC microcontroller


  Figure 2: 7-Segment displaying 8 with decimal point         Figure 3: 7-Segment displaying 3

The segments of the displays are normally referred to by letters ‘a’ to ‘g’.
Figures 2 and 3 show how a 7-segment display can display digits. 
In figure 2, all the segments (LEDs) are switched on to display the digit “8” with the decimal point. On the other hand, in figure 3, segments a, b, c, d and g are switched on to display the digit “3”.  any combination can be used to display any desired digit.
The segments can also be used to display some letters, but this is limited. For example, the letter “b” can be displayed by switching on the segments  c, d, e and f and the letter “F” by switching on segments a, e, f and g.

7-segment displays are available in two configurations: common anode and common cathode. As shown in Figures 4 and 5 below.

    Figure 4: Common Anode 7-Segment              Figure 5: Common Cathode 7-Segment
In figure 4, the anode pins of all the segments are connected together and in figure 5 as well as in figure 1, all the cathodes of all the segments are connected together. Flowcode has components for both a quad 7-segment display which can display 4 digits and for a single 7-segment display.

—>>To insert an 7-Segment display component, on the components tool bar click on 7seg1 to insert a single digit 7-Segment display on click on 7seg4 to insert a quad 7-Segment display under the Outputs group.
An single digit 7-Segment (led7seg(0)) or a quad 7-Segment (led7seg4(0)) will be inserted on the panel as shown on figure 6 below.

Inserting a 7-Segment component

Figure 6: Inserting a 7-Segment component

—>> Select the 7-segment then click on the “….” next to connections properties of the 7-segment to open its connection properties. Here you can set the Port and pins that the 7-segment display is connected to, and the individual pins for the various connections.

Single digit seven segment Pin Connections

Figure 7: Single digit 7-Segment Pin Connections

By default the single digit 7-segment display is connected to all 8 pins on Port B, and the ‘common’ pin is connected to PORTA.0 (A0). You can change this, but we will keep the default connections for now. If a quad 7-Segment is selected, by default the 7-segment quad display is connected to all 8 pins on Port B, and the the common pins are set to Port A.0, Port A.1, Port A.2 and Port A.3 (A0-A3). You can change this, but we will keep the default connections for now. Figure 8 below shows the quad 7-Segment display pin connections.

Quad 7-Segment Pin Connections

Figure 8: Quad 7-Segment Pin Connections

—>>Click again on the “….” next to the Ext Properties to edit the 7-Segment properties. Here you can set whether the 7-Segment is connected in Common Anodes or Common Cathodes mode. You can also choose the colour of the display. On figure 9 below, the 7-Segment is set to Common Anodes and the Red colour is selected.

7-Segment Properties

Figure 9: 7-Segment Properties

Component Macros

Drag and drop the Component Macros from the Icons toolbar.

Component Macro

Figure 10: Component Macro

Double click the component macro to open its properties. Click on the led7seg(0) to see the single digit 7-Segment macros.
The single digit 7-Segment Component provides the following macros:

ShowDigit(): The ‘ShowDigit’ macro takes two parameters – ‘DecimalPoint’ and ‘Value’. Value is the number we wish to display, lets set this to display the number 7. DecimalPoint determines whether to show the decimal point or not. Set this to 0 to disable the decimal point or set it to 1 to display/enable the decimal point. Set this to 0 to hide the decimal point.

ClearDigit(): Disables the common enable pin, switching off the 7-segment display and therefore allowing other 7-segment displays to be activated without causing corruption to the current display.

Example: Display the digit ‘7’ on the 7-Segment display:

Displaying the digit 7

Figure 11: Displaying the digit 7

If the quad 7-Segment was inserted on the panel, double click the component macro to open its properties. Click on the led7seg4(0) to see the quad 7-Segment macros.
The quad 7-Segment Component provides only one macro:

ShowDigit(): The ‘ShowDigit’ macro for the 7 Segment Quad display is the same as that used for the 7 Segment Single display , but with an extra parameter. The Digit is used to select which of the 4 7-segment displays to show the value on. These are numbered 0 to 3. Let’s display 1234 on the quad 7-segment display . Enter 0,4,0 into the parameters box and click on ‘OK’. This will display the number 1 in the rifgt-most 7-segment display. Next add 3 more macros with 1,3,0 in the second macro, 2,32,0 in the third macro and 3,1,0 in the last macro respectively.

Now run the program, If you are observant, or if you are runing slowly your simulation, you’ll see the first 7-segment display lit, then the next, then the next, then the last one. The problem is that unlike the LCD we can’t light more than 1 7-segment display at any one time. The complexity comes when we need to calculate the values to be displayed, or to run another part of the program. If the time taken between updating the different 7-segment displays is too great then the display will stop, or become disjointed. So how do we get around that? The best way is to run the program into a separate routine and use the main program with some interrupt to call the separate routine to refresh the quad 7-Segment display. We will learn more about interrupts in a future tutorial.

Example: Display the numbers ‘1234’ on the 7-Segment display:

Displaying the numbers '1234'

Figure 12: Displaying the numbers ‘1234’

Let us create a circuit as shown on the figure 1 above and display a simple decimal counter to display ‘0’ to ‘9’ in an interval of 1 second.

Decimal Counter

Figure 13: Decimal Counter

You can download the full project files (Flowcode and Proteus Schematic design) below here. 
All the files are zipped, you will need to unzip them (Download a free version of the Winzip utility to unzip files).  

Download Flowcode Decimal Counter