Seven Segment Display Programming with Structured Text

We have seen how a seven segment display plays a very important role in many types of indications that we see in our daily lives. If we need to control its logic through PLC, then a new programmer has many options to choose from the language to write it. One of the most highly used and efficient level languages is structured text.

In this post, we will see how to write a seven segment display logic in a PLC program using structured text language.

Seven Segment Display

seven-segment-display-working-animation
Example

Let us understand the case scenario first. There are four PLC digital inputs and seven PLC digital outputs. For a number to be displayed, the inputs will come in sequence as per the below truth table.

In correspondence to the input sequence received, the outputs will turn on accordingly and display the LED segment with numbers. Refer to the second image for more understanding, where you can co-relate this table with the display.

Input I0Input I1Input I2Input I3Output O1Output O2Output O3Output O4Output O5Output O6Output O7Display
000011111100
000101100001
001011011012
001111110013
010001100114
010110110115
011010111116
011111100007
100011111118
100111110119
Seven Segment Display

Programming with Structured Text

Now, let us write this program. Refer to the below image. In the first four lines, we are moving the values of four inputs in the corresponding bits of a single word. Due to this, we get different values of the word.

The value of this word is the same as the display number.

Seven Segment Display Programming with Structured Text

Now, after these first four lines, we are using a case statement. A case statement is used to execute different conditions based on the value of the variable referred. In our case, we are referring to the input status variable. So, based on its current value, we write 0 or 1 to the seven outputs. Each case value ends with “:” and each statement ends with “;”.

Basically, we are just moving true or false values in the digital outputs based on the input conditions. Whatever may be the input value, it will write a corresponding value to the word and this word will then be used as a reference for writing the outputs.

In place of case statements, we can also use if-else statements. But then, the logic would have become a little bulkier and larger to look at. This means, that we would have to write a total of 10 if conditions for the logic. So, we simplified it more by using a case statement.

This logic looks simple in structured text. Imagine using it in ladder language. We would have to write so many rungs with various parallel conditions for turning the output on.

Task For You: Now program the 7 segment display to show the alphabets as shown in the above animation.

In this way, we saw how to write a seven-segment display logic in a PLC program using structured text language.

Read Next:

Don't Miss Our Updates
Be the first to get exclusive content straight to your email.
We promise not to spam you. You can unsubscribe at any time.
Invalid email address

Leave a Comment

Share via
Follow us and never miss an update!