6 digit 7 segment indicator. Arduino and four-digit seven-segment indicator. How to check a seven-segment indicator

6 digit 7 segment indicator.  Arduino and four-digit seven-segment indicator.  How to check a seven-segment indicator
6 digit 7 segment indicator. Arduino and four-digit seven-segment indicator. How to check a seven-segment indicator


Connection diagram for a one-digit seven-segment indicator
Connection diagram for a multi-digit seven-segment indicator

Digital information display device. This is the most simple implementation indicator that can display Arabic numerals. More complex multi-segment and matrix indicators are used to display letters.

As its name says, it consists of seven display elements (segments) that turn on and off separately. Including them in different combinations, from them you can create simplified images of Arabic numerals.
The segments are designated by letters A through G; eighth segment - decimal point (decimal point, DP), designed to display fractional numbers.
Occasionally, letters are displayed on the seven-segment indicator.

There are different colors, usually the colors are white, red, green, yellow and blue. In addition, they can be of different sizes.

Also, the LED indicator can be single-digit (as in the figure above) or multi-digit. Basically, one-, two-, three- and four-digit LED indicators are used in practice:

In addition to ten digits, seven-segment indicators are capable of displaying letters. But few letters have an intuitive seven-segment representation.
In Latin: capital A, B, C, E, F, G, H, I, J, L, N, O, P, S, U, Y, Z, lowercase a, b, c, d, e, g , h, i, n, o, q, r, t, u.
In Cyrillic: A, B, V, G, g, E, i, N, O, o, P, p, R, S, s, U, Ch, Y (two digits), b, E/Z.
Therefore, seven-segment indicators are used only to display simple messages.

In total, the seven-segment LED indicator can display 128 characters:

A typical LED indicator has nine leads: one goes to the cathodes of all segments, and the other eight go to the anode of each segment. This scheme is called "common cathode circuit", there are also schemes with common anode(then it's the other way around). Often, not one, but two common terminals are made at different ends of the base - this simplifies the wiring without increasing the dimensions. There are also so-called “universal” ones, but I personally have not encountered such ones. In addition, there are indicators with a built-in shift register, which greatly reduces the number of microcontroller port pins involved, but they are much more expensive and are rarely used in practice. And since the immensity cannot be grasped, we will not consider such indicators for now (but there are also indicators with much big amount segments, matrix).

Multi-digit LED indicators often work on a dynamic principle: the outputs of the segments of the same name of all digits are connected together. To display information on such an indicator, the control microcircuit must cyclically supply current to the common terminals of all digits, while current is supplied to the segment terminals depending on whether a given segment is lit in a given digit.

Connecting a one-digit seven-segment indicator to a microcontroller

The diagram below shows how connects single-digit seven segment indicator to the microcontroller.
It should be taken into account that if the indicator with COMMON CATHODE, then its common output is connected to "earth", and the segments are ignited by feeding logical unit to the port output.
If the indicator is COMMON ANODE, then it is supplied to its common wire "plus" voltage, and the segments are ignited by switching the port output to the state logical zero.

Indication in a single-digit LED indicator is carried out by applying a binary code to the pins of the microcontroller port of the corresponding digit of the corresponding logical level (for indicators with OK - logical ones, for indicators with OA - logical zeros).

Current limiting resistors may or may not be present in the diagram. It all depends on the supply voltage that is supplied to the indicator and technical characteristics indicators. If, for example, the voltage supplied to the segments is 5 volts, and they are designed for operating voltage 2 volts, then it is necessary to install current-limiting resistors (to limit the current through them for an increased supply voltage and not to burn not only the indicator, but also the microcontroller port).
It is very easy to calculate the value of current-limiting resistors, using the grandfather’s formula Ohm.
For example, the characteristics of the indicator are as follows (taken from the datasheet):
— operating voltage — 2 volts
— operating current — 10 mA (=0.01 A)
— supply voltage 5 volts
Formula for calculation:
R= U/I (all values ​​in this formula must be in Ohms, Volts and Amps)
R= (supply voltage - operating voltage)/operating current
R= (5-2)/0.01 = 300 Ohm

Connection diagram for a multi-digit seven-segment LED indicator Basically the same as when connecting a single-digit indicator. The only thing is that control transistors are added in the cathodes (anodes) of the indicators:

It is not shown in the diagram, but between the bases of the transistors and the pins of the microcontroller port, it is necessary to include resistors, the resistance of which depends on the type of transistor (the resistor values ​​are calculated, but you can also try using resistors with a nominal value of 5-10 kOhm).

Indication by discharges is carried out dynamically:
— the binary code of the corresponding digit is set at the outputs of the PB port for the 1st digit, then the logical level is applied to the control transistor of the first digit
— the binary code of the corresponding digit is set at the outputs of the PB port for the 2nd digit, then the logical level is applied to the control transistor of the second digit
— the binary code of the corresponding digit is set at the outputs of the PB port for the 3rd digit, then the logical level is applied to the control transistor of the third digit
- so in a circle
In this case, it is necessary to take into account:
— for indicators with OK control transistor structure is used NPN(controlled by logical unit)
- for indicator with OA- structure transistor PNP(controlled by logic zero)

Let's connect a seven-segment LED indicator to the Arduino board and learn how to control it using the Led4Digits.h library.

The previous lesson described in detail microcontrollers. Let's connect such an indicator to the Arduino board.

The diagram for connecting the indicator to the Arduino board looks like this.

I assembled it on a circuit board.

To manage indicators, I wrote the Led4Digits.h library:

And pay.

The library allows you to manage seven-segment indicators:

  • up to four digits in size;
  • with any variants of control pulse polarities (all);
  • works in a parallel process;
  • allows you to display on the indicator:
    • segments of each category;
    • the digit of each digit;
    • integer 0 ... 9999;
  • to output an integer, the number of digits can be specified;
  • There is a mode for suppressing insignificant digits.

You can download the Led4Digits.h library from this link:

And pay. Only 40 rub. per month for access to all site resources!

How to install is written in .

I will not provide the source texts. You can look them up in the library files. As always, there are plenty of comments there. I will describe in detail, with examples, how to use the library.

LED control library for Arduino Led4Digits.

Here is the class description. I only provided public methods and properties.

class Led4Digits (
public:
byte digit; // bit segment control codes
void regen(); // regeneration, the method must be called regularly
void tetradToSegCod(byte dig, byte tetrad); // converting tetrad to segment codes
boolean print(unsigned int value, byte digitNum, byte blank); // integer output



} ;

Constructor.

Led4Digits (byte typeLed, byte digitPin0, byte digitPin1, byte digitPin2, byte digitPin3,
byte segPinA, byte segPinB, byte segPinC, byte segPinD,
byte segPinE, byte segPinF, byte segPinG, byte segPinH);

typeLed Sets control pulse polarities for bit and segment selection signals. Supports any connection schemes ().

typeLed Selection of category Segment selection Circuit type
0 -_- -_- Common anode with discharge selection keys
1 _-_ -_- Common anode
2 -_- _-_ Common cathode
3 _-_ _-_ Common cathode with discharge selection keys

digitPin0...digitPin3– outputs for selecting digits. If digitPin = 255, then the digit is disabled. This allows you to connect indicators with fewer digits. digitPin0 – low (right) digit.

segPinA...segPinH– segment control outputs.

For example,

means: indicator type 1; discharge outputs 5,4,3,2; outputs of segments 6,7,8,9,10,11,12,13.

void regen() method

The method must be called regularly in a parallel process. It regenerates the image on the indicators. The regeneration cycle time is equal to the method call period multiplied by the number of bits.

For example,

// interrupt handler 2 ms
void timerInterrupt() (
disp.regen(); // indicator regeneration
}

Byte digit array

Contains the state of the segments. digit is the least significant bit, the least significant bit of digit is the “A” segment of the least significant bit. A bit state of 1 means the segment is lit.

For example,

digit = B0000101;

means that in the second digit, segments “A” and “C” are lit.

An example of a program that sequentially lights all segments of each digit.

// running segments
#include
#include

//
Led4Digits disp(1, 5,4,3,2, 6,7,8,9,10,11,12,13);

void setup() (
timer interrupt 2 ms
MsTimer2::start(); // interrupt enable
}

void loop() (
for (int i = 0; i< 32; i++) {
if (i == 0) disp.digit= 1;
else if (i == 8) disp.digit= 1;
else if (i == 16) disp.digit= 1;
else if (i == 24) disp.digit= 1;
else(
disp.digit = disp.digit<< 1;
disp.digit = disp.digit<< 1;
disp.digit = disp.digit<< 1;
disp.digit = disp.digit<< 1;
}
delay(250);
}
}

//interrupt handler 2 ms
void timerInterrupt() (
disp.regen(); // indicator regeneration
}

In the digit array, 1 is shifted and the indicators display this.

Method void tetradToSegCod(byte dig, byte tetrad)

The method allows you to display numbers and letters of hexadecimal code in individual digits. Has arguments:

  • dig – digit number 0 ... 3;
  • tetrad – decimal character code. Code 0 will display the number “0”, code 1 - the number “1”, code 14 - the letter “E”.

For example,

tetrad(2, 7);

will display the number “7” in the third digit.

An example of a program that changes characters in each digit in turn.

// numbers one by one
#include
#include

// indicator type 1; discharge outputs 5,4,3,2; segment outputs 6,7,8,9,10,11,12,13
Led4Digits disp(1, 5,4,3,2, 6,7,8,9,10,11,12,13);

void setup() (
MsTimer2::set(2, timerInterrupt); // timer interrupt 2 ms
MsTimer2::start(); // interrupt enable
}

void loop() (
for (int i = 0; i< 64; i++) {
disp.tetradToSegCod(i>>4, i);
delay(250);
}
}

// interrupt handler 2 ms
void timerInterrupt() (
disp.regen(); // indicator regeneration
}

Method boolean print(unsigned int value, byte digitNum, byte blank)

The method displays an integer on the indicators. It converts the binary number into BCD for each digit. Has arguments:

  • value – the number that is displayed on the indicator.
  • digitNum – number of digits for the number. This should not be confused with the number of indicator digits. You may want to display a number on 2 digits, and display characters on the other two using digit.
  • blank – a sign of suppression of insignificant digits. blank=0 means the number should be displayed with all zeros. The number "7" will look like "0007". If blank is different from 0, insignificant zeros will be suppressed.

If the number value exceeds the permissible number for the selected number of digits (digitNum), then the function will display “---” on the indicator and return false.

An example of a number output program.

// output number
#include
#include

// indicator type 1; discharge outputs 5,4,3,2; segment outputs 6,7,8,9,10,11,12,13
Led4Digits disp(1, 5,4,3,2, 6,7,8,9,10,11,12,13);

void setup() (
MsTimer2::set(2, timerInterrupt); // timer interrupt 2 ms
MsTimer2::start(); // interrupt enable
}

void loop() (
for (int i = 0; i< 12000; i++) {
disp.print(i, 4, 1);
delay(50);
}
}

// interrupt handler 2 ms
void timerInterrupt() (
disp.regen(); // indicator regeneration
}

The last two methods do not change the state of the “H” segment – ​​the decimal point. To change the state of a point, you can use the commands:

digit |= 0x80; // light the decimal point
digit &= 0x7f; // extinguish the decimal point

Output to indicators of negative numbers (int).

Negative numbers can be output as follows:

  • Check the sign of the number.
  • If the number is negative, then print a minus sign at the most significant digit and change the sign of the number to positive in the print() function.
  • If the number is positive, then turn off the sign bit and print the number using the print() function.

Here is a program that demonstrates this method. It outputs numbers from -999 to 999.

// output negative numbers
#include
#include

// indicator type 1; discharge outputs 5,4,3,2; segment outputs 6,7,8,9,10,11,12,13
Led4Digits disp(1, 5,4,3,2, 6,7,8,9,10,11,12,13);

void setup() (
MsTimer2::set(2, timerInterrupt); // timer interrupt 2 ms
MsTimer2::start(); // interrupt enable
}

void loop() (

for (int i = -999; i< 1000; i++) {

if (i< 0) {
// the number is negative
disp.digit= B01000000; // sign -
disp.print(i * -1, 3, 1);
}
else(
disp.digit= B00000000; // clear the sign
disp.print(i, 3, 1);
}

delay(50);
}
}

// interrupt handler 2 ms
void timerInterrupt() (
disp.regen(); // indicator regeneration
}

Output to indicators of fractional numbers, float format.

There are many ways to display floating point numbers (floats) on indicators using standard C language functions. This is, first of all, the sprint() function. It works very slowly, requires additional conversions of character codes to binary decimal codes, you need to extract a point from a string. Same problems with other functions.

I use a different method for displaying the values ​​of float variables on indicators. The method is simple, reliable, fast. Reduces to the following operations:

  • The floating point number is multiplied by 10 to the power corresponding to the required number of decimal places. If you need to display 1 decimal place on indicators, multiply by 10, if 2, then multiply by 100, 3 decimal places by 1000.
  • Next, the floating point number is explicitly converted to an integer (int) and displayed on the indicators using the print() function.
  • A dot is placed in the required digit.

For example, the following lines will output a float variable with two decimal places to the seven-segment LEDs.

float x = 2.12345;

disp.digit |= 0x80; //

We multiply the number by 100, and by placing a dot in the third digit, we divide the result by 100.

Here is a program that displays floating point numbers from 0.00 to 99.99 on the indicators.

// floating point output
#include
#include

// indicator type 1; discharge outputs 5,4,3,2; segment outputs 6,7,8,9,10,11,12,13
Led4Digits disp(1, 5,4,3,2, 6,7,8,9,10,11,12,13);

void setup() (
MsTimer2::set(2, timerInterrupt); // timer interrupt 2 ms
MsTimer2::start(); // interrupt enable
}

void loop() (
float x = 0;

for (int i = 0; i< 10000; i++) {
x += 0.01;

disp.print((int)(x * 100.), 4, 1);
disp.digit |= 0x80; // light up the third level point

delay(50);
}
}

//interrupt handler 2 ms
void timerInterrupt() (
disp.regen(); // indicator regeneration
}

As you can see, the Led4Digits.h library greatly simplifies working with seven-segment light-emitting diode (LED) indicators connected to the Arduino board. I have not found an analogue of such a library.

There are libraries for working with LED displays via a shift register. Someone wrote to me that they found a library that works with an LED display directly connected to the Arduino board. But when using it, the indicator digits glow unevenly and wink.

Unlike its analogues, the Led4Digits.h library:

  • Runs as a parallel process. In the main loop, the program loads data into certain variables, which are automatically displayed on the display. Information output and indicator regeneration occur in a timer interrupt, invisible to the main program.
  • The display numbers glow evenly, without blinking. This property is ensured by the fact that regeneration occurs in a cycle strictly defined by a timer interrupt.
  • The library has compact code, executes quickly, and minimally loads the controller.

In the next lesson, we will connect an LED indicator and a button matrix to the Arduino board at the same time. Let's write a library for such a design.

Category: . You can bookmark it.

Since the advent of radio engineering and electronics, feedback from an electronic device and a person has been accompanied by various signal lights, buttons, toggle switches, and bells (the microwave's ready signal - ding!). Some electronic devices provide a minimum of information, because more would be unnecessary. For example, a glowing LED on your Chinese phone charger indicates that the charger is plugged in and is receiving power. But there are also parameters for which it would be more convenient to provide objective information. For example, the air temperature outside or the time on the alarm clock. Yes, all this could also be done with glowing bulbs or LEDs. One degree - one burning diode or light bulb. How many degrees there are, so many indicators are on. Counting these fireflies may be a common thing, but again, how many of these lights will be needed to show the temperature with an accuracy of a tenth of a degree? And in general, what area will these LEDs and light bulbs occupy on an electronic device?

Practical seven-segment display devices must have at least eight external connection terminals; seven of them provide access to individual photovoltaic segments, and the eighth provides a common connection to all segments. In the first case, the device is known as a seven-segment common anode display; in the latter case the device is known as a seven-segment common-cathode display.

To drive a common anode display, the driver must have an active-low output, in which each segment drive is normally high but goes low to turn on the segment. To drive a common cathode display, the driver must have an active active output.

And at the beginning of the twentieth century, with the advent of electronic tubes, the first gas-discharge indicators appeared

With the help of such indicators it was possible to display digital information in Arabic numerals. Previously, it was these lamps that were used to make various indications for instruments and other electronic devices. Currently, gas-discharge elements are almost never used anywhere. But retro is always fashionable, which is why many radio amateurs collect wonderful gas discharge watches for themselves and their loved ones.

The full explanation of this is a little more complicated, as follows. When the voltage is zero, the segment is effectively invisible. However, when the input voltage is significantly positive or negative, the segment becomes effectively visible, but if the drive voltage is maintained for more than a few hundred milliseconds, the segment may become permanently visible and have no further meaning.

Under these conditions, the segment is disabled. Thus, the segment is included under these conditions. This form of drive is commonly known as a voltage doubling "bridge drive" system. The sequence of actions of the scheme is as follows. The simple cascade system described earlier suffers from a serious defect in that the display becomes blurred during the actual counting period, becoming stable and readable only when each count is completed and the input gate is closed. This "blurry and read" type of display is very annoying to look at.

Disadvantages of gas discharge lamps - they eat a lot. One can argue about durability. At our university, we still use frequency meters on gas dischargers in laboratory rooms.

With the advent of LEDs, the situation has changed dramatically. LEDs themselves consume a small amount of current. If you place them in the right position, you can display absolutely any information. In order to highlight all the Arabic numerals, just something was enough seven (hence the name seven-segment indicator) glowing LED strips arranged in a certain way:

Figure 13 shows an improved frequency counter circuit that uses display locking to overcome the above defect. This scheme works as follows. At the same time, the input gate opens and the counters begin to sum up the input signal pulses. This counter continues for exactly one second, and during this period the four-bit latches prevent the counter output from reaching the display drivers; the display remains stable during this period.

After a few seconds the sequence is repeated again, with the counters rebooting and then counting input frequency pulses for one second, during which the display gives a continuous readout of the previous count, etc.

Almost all such seven-segment indicators also add an eighth segment - a dot, so that it is possible to show the integer and fractional value of any parameter

Thus, the circuit in Figure 13 produces a stable display that updates once per second; in practice, the actual counting period of this and the diagram in Figure 12 can be made to be in any decade with multiple or partial seconds, provided the output display is scaled appropriately.

Note that a three-digit frequency counter can indicate maximum frequencies of 999 Hz when using a one-second time base, 99 kHz when using a 100 ms time base, 9 kHz when using a 10 ms time base, and 999 kHz when using a 1 ms time base.

In theory, it turns out to be an eight-segment indicator, but in the old fashioned way it is also called seven-segment, and there is no mistake in that.

In short, a seven-segment indicator is LEDs located relative to each other in a certain order and enclosed in one housing.

This method can be understood with the help of Figures 14 and 15. These switches are connected together and provide the actual multiplexer action and should be considered as high speed electronic switches which are switched repeatedly through positions 1, 2 and the sequence of operations of the circuit is as follows. Let's first assume that the switch is in position.

A few moments later, the switch moves to position 3, causing display 3 to display a number after a few minutes, the whole cycle begins to repeat again and so on, adding infinity. In practice, about 50 of these cycles occur every second, so the eye does not see the displays turning on and off separately, but perceives them as an apparently steady display that shows the number 327, or some other number dictated by the data segment.

If we consider the diagram of a single seven-segment indicator, it looks like this:

As we see, the seven-segment indicator can be either with common anode (CA), so with common cathode (OC). Roughly speaking, if we have a seven-segment with a common anode (OA), then in the circuit we should hang a “plus” on this pin, and if with a common cathode (OC), then a “minus” or ground. To which pin we apply voltage, this LED will light up. Let's demonstrate all this in practice.

In practical multiplexers, the peak display current is quite high to ensure sufficient display brightness. In fig. Figure 15 shows an example of an improved multiplexing method applied to a three-digit frequency counter. This method has two main advantages.

If these terminals are active high, they will have the following characteristics. Fig. 18 and 19. Figure 18 shows the ripple suppression technique used to provide leading zero suppression on a four-digit display that reads quantity.

We have the following LED indicators in stock:

As we can see, seven-segment devices can be single and multi-bit, that is, two, three, four seven-segment devices in one case. In order to check a modern seven-segment device, we only need a multimeter with a diode testing function. We are looking for a general conclusion - it can be either OA or OK - at random and then we look at the performance of all segments of the indicator. We check the three-bit seven-segment:

So the display shows. Basically, they're easy to use, power them up, and they light up. They can be annoying because they have some kind of polarity, which means they will only work if you connect them correctly. If you cancel the positive and negative voltage, they won't light up at all.

Annoying as it is, it's also quite useful. The other wire is the cathode. The cathode is connected to ground. Basically, it will come down to that. For common cathode, you apply current to the pins you want to turn on. Multiplexing. There are even display controllers for this if you don't want to worry about switching in your software.

Oops, one segment caught fire, we're checking the other segments in the same way.

Sometimes the voltage on the cartoon is not enough to check the indicator segments. Therefore, we take the power supply, set it to 5 Volts, attach a 1-2 kiloOhm resistor to one terminal of the power supply and begin checking the seven-segment unit.

7-segment display control

So when you have a 4-digit, multiplexed 7 segment, common anode. First, we need to know what type of display we have, since there are two possible shapes: common cathode and common anode. Things you will need for this tutorial. Left: A graphical view of a 7-segment display showing one general layout for internal wiring and pin locations.

At this point, pay attention to the initial output, as you will need it later when loading the program. If the display were a regular cathode, we would cancel it. At the bottom of the article is a photo of the circuitry that goes on my prototype board. We also provide a library to control more than one display.

Why do we need a resistor? When voltage is applied to the LED, it begins to sharply consume current when turned on. Therefore, at this moment it may burn out. To limit the current, a resistor is connected in series with the LED. You can read more in this article.

Hex counting on one 7-segment display

The downside is that they are resource intensive. This particular display has four digits and two colon displays. However, the device also provides digital control of display brightness via an internal wideband modulator. In such cases, the output can be made on multiple 7-segment displays.

This saves contacts on the housing and then on control. Accordingly, common anode or common cathode displays are referred to. The output that corresponds to a segment or decimal point is best extracted from the data sheet for display. A 7-segment display that is rated for the usual 10-20mA will still light up, albeit dimly. But this does not require assigning contacts. The following distribution of this segment is based on.

In the same way we check the four-digit seven-segment from a Chinese radio

I think there shouldn’t be any particular difficulties with this. In the circuits, seven-segment circuits are connected to resistors at each pin. This is also due to the fact that LEDs, when voltage is applied to them, frantically consume current and burn out.

If a different purpose is used, this is possible in principle, but must be taken into account when programming. Converting individual digits into a specific output pattern can be done using something called. All other segments should be dark. If this checkbox is checked for all digits, the following table is given.

The test program displays digits 0 to 9 sequentially on a 7-segment display. The output number is stored in a register counter and incremented by 1 within the cycle. If the register reaches a value of 10, it is reset to 0 again. Once raised, a wait loop occurs that ensures that a certain amount of time has passed in the next release. Normally you wouldn't do such long wait cycles, but this isn't about waiting, it's about controlling a 7-segment display. Using a timer for this is too much effort.

In our modern world, seven-segment devices are already being replaced by LCD indicators that can display completely different information

but in order to use them, you need certain skills in the circuit design of such devices. So far, there is nothing simpler or cheaper than seven-segment LED indicators.

The actual problem, and therefore the interesting part of this article, however, occurs directly after the label loop. Please note that the counter value must be doubled. This is directly related to the fact that flash memory is word-wise and not byte-wise. The second example on this page does it differently. It shows how, through another table entry, the generation of padding bytes can be prevented by the assembler. It is also interesting that the calculation requires a register that contains the value 0.

Therefore, this constant must first be loaded into a register and only then can addition be performed using this register. The interesting thing is that this fact occurs in many programs, and constants in the vast majority of cases are the constant 0. Therefore, many programmers reserve a register from the very beginning for this and call it the zero register.

In this article we will talk about digital display.
Seven-segment LED indicators are designed to display Arabic numerals from 0 to 9 (Fig. 1).

Such indicators are single-digit, which display only one number, but there may be more seven-segment groups combined into one housing (multi-digit). In this case, the numbers are separated by a decimal point (Fig. 2)

Unfortunately there is a problem because the display requires eight ports - four advertisements would require 32 ports. But there are several ways. Shift registers are already described in another tutorial. This would make it easier to create the required 32 output lines with only three pins. The control principle is no different from driving a single 7-segment display, only how the "output pins" approach their values ​​is different and is determined by the use of shift registers. At this point, however, another control option should be shown.



Fig.2.

The indicator is called seven-segment due to the fact that the displayed symbol is built from seven separate segments. Inside the housing of such an indicator there are LEDs, each of which illuminates its own segment.
It is problematic to display letters and other symbols on such indicators, so 16-segment indicators are used for these purposes.

We'll look at multiplexing again below. Multiplexing means that not all four displays are turned on at the same time, but only one for a short time. If the change between displays happens faster than we humans can perceive, all four lights appear to be working simultaneously, although only one is lit for one short period of time. In this way, four displays can share individual segment segments, and all that is required is 4 additional control lines for the 4 displays that the display is enabled with.

One aspect of this type of control is the frequency of multiplexing, that is, the complete cycle of transition from one display to another. It should be high enough to prevent the display from flickering. The human eye is sluggish, in a cinema 24 frames per second, with the TV to be on the safe side that also still images are calm, each segment must be controlled at least 100 Hz, so it is connected at least every 10 ms. In exceptional cases, however, even 100 Hz may still flicker, such as when the display moves quickly or when interference occurs with artificial light sources that operate with alternating current.

LED indicators come in two types.
In the first of them, all cathodes, i.e. the negative terminals of all LEDs are combined together and a corresponding terminal is allocated for them on the case.
The remaining terminals of the indicator are connected to the anode of each LED (Fig. 3, a). This circuit is called a “common cathode circuit”.
There are also indicators in which the LEDs of each segment are connected according to a circuit with a common anode (Fig. 3, b).



Fig.3.

Each segment is designated by a corresponding letter. Figure 4 shows their location.

Fig.4.

As an example, consider a two-digit seven-segment indicator GND-5622As-21 red. By the way, there are other colors, depending on the model.
Using a three-volt battery, you can turn on the segments, and if you combine a group of pins into a bunch and apply power to them, you can even display numbers. But this method is inconvenient, so shift registers and decoders are used to control seven-segment indicators. Also, often, the indicator pins are connected directly to the microcontroller outputs, but only when indicators with low current consumption are used. Figure 5 shows a fragment of a circuit using PIC16F876A.



Fig.5.

To control the seven-segment indicator, the K176ID2 decoder is often used.
This chip is capable of converting binary code consisting of zeros and ones into decimal digits from 0 to 9.

To understand how it all works, you need to assemble a simple circuit (Fig. 6). The K176ID2 decoder is housed in a DIP16 package. It has 7 output pins (pins 9 - 15), each dedicated to a specific segment. Point control is not provided here. The microcircuit also has 4 inputs (pins 2 - 5) for supplying binary code. The 16th and 8th pins are supplied with plus and minus power, respectively. The remaining three conclusions are auxiliary, I will talk about them a little later.



Fig.6.

DD1 - K176ID2
R1 - R4 (10 - 100 kOhm)
HG1 - GND-5622As-21

There are 4 toggle switches in the circuit (any buttons are possible), when you press them, a logical one is supplied to the decoder inputs from the power supply plus. By the way, the microcircuit itself is powered with a voltage of 3 to 15 Volts. In this example, the entire circuit is powered by a 9-volt power supply.

There are also 4 resistors in the circuit. These are so-called pull-up resistors. They are needed to ensure that the logic input is low when there is no signal. Without them, the readings on the indicator may not be displayed correctly. It is recommended to use the sameresistance from 10 kOhm to 100 kOhm.

In the diagram, pins 2 and 7 of the HG1 indicator are not connected. If you connect the DP pin to the minus power supply, the decimal point will light up. And if you apply a minus to the Dig.2 output, then the second group of segments will also light up (will show the same symbol).

The decoder inputs are designed in such a way that to display the numbers 1, 2, 4 and 8 on the indicator, you only need to press one button (toggle switches corresponding to inputs D0, D1, D2 and D3 are installed on the layout). If there is no signal, the number zero is displayed. When a signal is applied to input D0, the number 1 is displayed. And so on. To display other numbers, you need to press a combination of toggle switches. Table 1 will tell us which ones we need to press.


Table 1.

To display the number "3" you need to apply a logical one to the input D0 and D1. If you apply a signal to D0 and D2, the number “5” will be displayed(Fig. 6).



Fig.6.

Here is an extended table in which we see not only the expected figure, but also those segments (a - g) that will make up this figure.



Table 2.

The 1st, 6th and 7th pins of the microcircuit are auxiliary (S, M, K, respectively).

In the diagram (Fig. 6), the 6th pin “M” is grounded (to the power supply minus) and there is a positive voltage at the output of the microcircuit for working with an indicator with a common cathode. If an indicator with a common anode is used, then one should be applied to the 6th pin.

If a logical one is applied to the 7th pin “K”, then the indicator sign is extinguished, zero allows the indication. In the circuit, this pin is grounded (to the power supply minus).

A logical unit (plus power) is supplied to the first output of the decoder, which allows the converted code to be displayed on the indicator. But if you apply a logical zero to this pin (S), the inputs will stop receiving a signal, and the current displayed sign will freeze on the indicator.

One interesting thing to note is that we know that toggle switch D0 turns on the number "1", and toggle switch D1 turns on the number "2". If you press both toggle switches, the number 3 will be displayed (1+2=3). And in other cases, the indicator displays the sum of the numbers that make up this combination. We come to the conclusion that the decoder inputs are arranged thoughtfully and have very logical combinations.

You can also watch the video for this article.

Seven-segment LED indicators are very popular among digital value display devices and are used in the front panels of microwave ovens, washing machines, digital clocks, counters, timers, etc. Compared with LCD indicators, LED indicator segments glow brightly and are visible over a long distance and in a wide viewing angle. To connect a seven-segment 4-bit indicator to a microcontroller, at least 12 I/O lines will be required. Therefore, it is almost impossible to use these indicators with microcontrollers with a small number of pins, for example, series from the company. Of course, you can use different multiplexing methods (a description of which can be found on the website in the “Schemes” section), but even in this case there are certain limitations for each method, and they often use complex software algorithms.

We will look at the method of connecting an indicator via the SPI interface, which will require only 3 I/O lines of the microcontroller. At the same time, control of all indicator segments will remain.

To connect a 4-bit indicator to a microcontroller via the SPI bus, a specialized driver chip produced by the company is used. The microcircuit is capable of driving eight seven-segment indicators with a common cathode and includes a BCD decoder, segment drivers, a multiplexing circuit and static RAM for storing digit values.

The current through the indicator segments is set using only one external resistor. Additionally, the chip supports control of indicator brightness (16 brightness levels) using built-in PWM.

The circuit discussed in the article is a display module circuit with an SPI interface that can be used in amateur radio designs. And we are more interested not in the circuit itself, but in working with the microcircuit via the SPI interface. The +5 V module power is supplied to the Vcc pin, the MOSI, CLK and CS signal lines are intended for communication between the master device (microcontroller) and the slave (MAX7219 chip).

The microcircuit is used in a standard connection; the only external components needed are a resistor that sets the current through the segments, a protective diode for the power supply, and a filter capacitor for the power supply.

Data is transferred to the chip in 16-bit packets (two bytes), which are placed in the built-in 16-bit shift register on each rising edge of the CLK signal. We denote a 16-bit packet as D0-D15, where bits D0-D7 contain data, D8-D11 contain the register address, bits D12-D15 have no meaning. Bit D15 is the most significant bit and is the first bit received. Although the chip is capable of controlling eight indicators, we will consider working with only four. They are controlled by the outputs DIG0 - DIG3, located in sequence from right to left, the 4-bit addresses (D8-D11) that correspond to them are 0x01, 0x02, 0x03 and 0x04 (hexadecimal format). The digit register is implemented using on-chip RAM with an 8x8 organization and is directly addressable so that each individual digit on the display can be updated at any time. The following table shows the addressable digits and control registers of the MAX7219 chip.

Register

Address

HEX value

No operation

Decoding mode

Number of indicators

Shutdown

Indicator test

Control registers

The MAX1792 chip has 5 control registers: decoding mode (Decode-Mode), indicator brightness control (Intensity), register of the number of connected indicators (Scan Limit), on/off control (Shutdown), test mode (Display Test).

Turning the chip on and off

When power is applied to the chip, all registers are reset and it goes into Shutdown mode. In this mode the display is turned off. To switch to normal operation mode, bit D0 of the Shutdown register (address 0Сh) must be set. This bit can be cleared at any time to force the driver to turn off, leaving the contents of all registers unchanged. This mode can be used to save energy or in alarm mode by flashing the indicator (sequential activation and deactivation of the Shutdown mode).

The microcircuit is switched to Shutdown mode by sequentially transmitting the address (0Сh) and data (00h), and transferring 0Ch (address) and then 01h (data) returns to normal operation.

Decoding mode

Using the decoding mode selection register (address 09h), you can use BCD code B decoding (display characters 0-9, E, H, L, P, -) or without decoding for each digit. Each bit in the register corresponds to one digit, setting a logical one corresponds to turning on the decoder for this bit, setting 0 means the decoder is disabled. If a BCD decoder is used, then only the lowest nibble of data in the digit registers (D3-D0) is taken into account, bits D4-D6 are ignored, bit D7 does not depend on the BCD decoder and is responsible for turning on the decimal point on the indicator if D7 = 1. For example, when bytes 02h and 05h are sent in sequence, the DIG1 indicator (second digit from the right) will display the number 5. Similarly, when sending 01h and 89h, the DIG0 indicator will display the number 9 with the decimal point included. The table below shows a complete list of characters displayed when using the IC's BCD decoder.

Symbol

Data in registers

Enabled segments = 1

Empty

*The decimal point is set by bit D7=1

When the BCD decoder is excluded from operation, data bits D7-D0 correspond to the segment lines (A-G and DP) of the indicator.

Indicator brightness control

The chip allows you to programmatically control the brightness of the indicators using the built-in PWM. The PWM output is controlled by the low-order nibble (D3-D0) of the Intensity register (address 0Ah), which allows you to set one of 16 brightness levels. When all bits of a nibble are set to 1, the maximum brightness of the indicator is selected.

Number of connected indicators

The Scan-Limit register (address 0Bh) sets the value of the number of bits serviced by the microcircuit (1 ... 8). For our 4-bit version, the value 03h should be written to the register.

Indicator test

The register responsible for this mode is located at address 0Fh. By setting the D0 bit in the register, the user turns on all indicator segments, while the contents of the control and data registers do not change. To disable Display-Test mode, bit D0 must be 0.

Interface with microcontroller

The indicator module can be connected to any microcontroller that has three free I/O lines. If the microcontroller has a built-in SPI hardware module, then the indicator module can be connected as a slave device on the bus. In this case, the SPI signal lines SDO (serial data out), SCLK (serial clock) and SS (slave select) of the microcontroller can be directly connected to the MOSI, CLK and CS pins of the MAX7219 chip (module), the CS signal is active low.

If the microcontroller does not have hardware SPI, the interface can be organized in software. Communication with the MAX7219 begins by pulling the CS line low and holding it low, then sending 16 bits of data sequentially (MSB first) on the MOSI line on the rising edge of the CLK signal. Upon completion of the transmission, the CS line goes high again.

In the downloads section, users can download the source text of the test program and the HEX file of the firmware, which implements a conventional 4-bit counter with display of values ​​on an indicator module with an SPI interface. The microcontroller used is an interface implemented in software, the signal lines CS, MOSI and CLK of the indicator module are connected to ports GP0, GP1 and GP2, respectively. The mikroC compiler for PIC microcontrollers is used (mikroElektronika

To comment on materials from the site and gain full access to our forum, you need register .

This time, the article will consider one of the most interesting modules, namely - multi-digit seven-segment indicator based on the MAX7219 chip. Why multi-bit? The answer is simple - the number of digits is the number of digits that the module can display. For example, in the photo below, three types of multi-digit indicators are shown, from left to right - 4-digit, 6-digit, 8-digit. Moreover, the first one is 4-digit dial indicator. The difference between a dial indicator and a regular one is that it has a sign colons, whereas in any regular indicator this sign is replaced by a dot at the bottom, next to the number.

In this article, the modules in question operate on the basis of a microcircuit MAX7219. This chip is a driver for seven-segment LED indicators, as well as 8x8 LED matrices, and we will not consider the circuit diagrams for connecting this driver. The ready-made module is simply taken as a basis; examples of connection to the board will be given Arduino UNO and worked with library functions LedControl. By the way, as already mentioned, 8x8 LED matrices also work based on a driver MAX7219, and if anyone is interested, welcome to the articles:

So, let's begin... I think that a good description was given about multi-bit, but here's why seven-segment? The answer is also not so complicated - because seven LEDs, indexed by letters, are used to form a symbol or display a number A, B, C, D, E, F, G, The table below shows how this is indicated:

As can be seen from the table, there is also an eighth LED - D.P. You can completely encode a character or digit in 1 byte by setting or clearing a specific bit, as shown with the character encoding example J. In the example the bits are set B, C, D, E, which allows you to display a specified character on a seven-segment indicator.

From theory to practice - let's connect an 8-bit module to the Arduino Uno board according to the diagram below:

To display symbols, several functions from the LedControl.h plug-in library are used. Let's look at each of these functions in order, starting with the setDigit() function.

The prototype of the function declaration for displaying the number and the arguments passed to the function:

setDigit(int addr, int digit, byte value, boolean dp);

Where -

int addr -module address on the busSPI 0 SPI starts from scratch)

int digit - 0 , 7

byte value -value (a number from 0 to 9) that needs to be displayed in the digit whose number is specified in the int digit parameter

boolean dp - int digit. If the parameter is true then the point will be displayed if false then the point will not be displayed.

The prototype of the function declaration for displaying the symbol and the arguments passed to the function:

setChar(int addr, int digit, char value, boolean dp);

int addr - module address on the busSPI for which the function is called, if there is only one module, then this parameter is equal to0 (default addressing of devices on the busSPI starts from scratch)

int digit - the serial number of the digit in the display module; by default, for multi-digit indicators, the numbering of digits begins with the rightmost digit, respectively, the number of the rightmost digit is equal to0 , and the number of the leftmost digit in our case is equal to7

char value - the character that should be displayed in the digit whose number is specified by the parameterint digit

boolean dp - this parameter is responsible for displaying a dot at the digit whose number is specified in the parameter int digit. If the parameter is true then the point will be displayed if false then the point will not be displayed.

A separate point worth mentioning is that the function setChar() can only display a limited set of characters, such as:

  • 0 1 2 3 4 5 6 7 8 9 the digit is displayed as a symbol
  • A a
  • B b
  • With with the character will be displayed in lower case
  • D d the character will be displayed in lower case
  • E e the character will appear in uppercase
  • F f the character will appear in uppercase
  • H h the character will be displayed in lower case
  • Ll the character will appear in uppercase
  • P p the character will appear in uppercase
  • - minus sign"
  • . , point display
  • _ underscore
  • <Пробел> set space character

In a test sketch, you can set a task like this:

  1. Display numbers from 1 to 8 one by one without a dot
  2. Fill in all the digits of the display module with numbers from 1 to 8, plus display all the points of the indicated digits
  3. Draw a bitwise array with characters pre-encoded in binary code, the result should be “Arduino rules!!!”

Due to the limited character set, the function setChar() is not suitable for a test sketch, since it will not be able to normally draw the phrase specified in point 3. Instead of this function, we will use the function setRow(). So... function setRow() has already been tested by us in articles about studying 8x8 LED matrices, let's again describe the prototype of the call and the parameters of this function.

Function Declaration Prototype setRow() and the arguments passed to the function:

setRow(int addr, int row, byte value);

int addr - module address on the busSPI for which the function is called, if there is only one module, then this parameter is equal to0 (default addressing of devices on the busSPI starts from scratch)

int row - the serial number of the digit in the display module; by default, for multi-digit indicators, the numbering of digits begins with the rightmost digit, respectively, the number of the rightmost digit is equal to0 , and the number of the leftmost digit in our case is equal to7

byte value- a value in binary format (example B00000000, alternatives in decimal and hexadecimal are also possible), which encodes the required character. The character encoding table will help you correctly encode the desired character.

Well, at the end of the article, a test sketch and a video of how it works:

#include "LedControl.h" /* * Include the LedControl.h library * and create an object of the LedControl class * in this case, a 7-segment display with a MAX72xx driver * must be connected to the Arduino board as follows: * Arduino -> Display Module MAX72xx * Arduino -> Display Module MAX72xx * Arduino -> Display Module MAX72xx * Arduino -> Display Module MAX72xx * Arduino -> Display Module MAX72xx * */ LedControl lc = LedControl(12, 11, 10, 1); //Array with encoded characters, //Phrase "Arduino ruLES!!!" Byte AR = (b0111101111, // A b00000101, // R B001111101, // D B00011100, // U B00010000, // I B00010101, // N B000111101, // O B00000101, // R B0001111100, // U B00001100 , //l B01001111, //E B01011011, //S B10110000, //! B10110000, //! void setup() ( //The device (7-segment display) is brought out of sleep mode lc.shutdown(0, false); //Set the display brightness to 8 //Total possible brightness modes from 0 to 15 lc.setIntensity(0 ,8); //Clear the display lc.clearDisplay(0); void loop() ( //The simplest iteration of numbers from 1 to 8 by digits for(int i = 0, j = 7; i< 8, j >= 0; i++, j--) ( lc.setDigit(0, j, byte(i + 1), false); delay(400); lc.clearDisplay(0); ) //Iterate through numbers without clearing the screen for(int i = 0, j = 7;< 8, j >= 0; i++, j--) ( lc.setDigit(0, j, byte(i + 1), true); delay(400); ) lc.clearDisplay(0); //Rendering the phrase "Arduino ruLES!!!" int n = 0; for(int i = 0; i< 2; i ++) { for(int j = 7; j >= 0; j --) ( if(n > 6 && !(i % 2)) ( continue; ) else ( lc.setRow(0, j, ar[n]); delay(400); n ++; ) ) lc .clearDisplay(0); ) delay(400); lc.clearDisplay(0); )


Please enable javascript for comments to work.