Driving 7-segment Displays with MAX7219
In a previous tutorial, we introduced the basic ideas about a seven-segment display and how to drive it with a 74HC595 shift register. In this tutorial, we'll show another LED driving IC: MAX7219, which is designed to drive 7-segment displays (up to 8 digits are supported), or 64 LEDs equivalently. By modifying the example used in the 74HC595 tutorial, we will go through major functionalities of MAX7219 by using LinkIt 7697 with a 8-digit 7-segment display module (with MAX7219 built in).
Table of Contents
Command Format
Before going into details of MAX7219, let's first look at how to communicate with it. All operations on MAX7219 are triggered by commands to update the values of its registers. And all commands share a unified format: a 16-bit "register address / data value" pair format (X stands for "don't care"):
By latching the LOAD pin and sending a 16-bit command with DIN pin in 16 clocks on CLK pin, a command is thus sent into the MAX7219. The timing diagram of a command sequence is:
This operation can be coded as below in Arduino. The shiftOut() API is used to send bits with clock pulses:
Hardware Setup
5 pins are needed from LinkIt 7697 to communicate with the 8-digit display module:
5V
GND
P15
P16
P17
And they are connected to:
VCC
GND
CLK
CS (i.e. LOAD pin of MAX7219)
DIN
pins of the display module, respectively:
5V power is needed for the display module. If 3.3V is supplied, there would be a decrease in the display brightness of the module.
Register Map
For controlling the display, several registers of MAX7219 need to be set correctly. In the example of this tutorial, six types of registers will be accessed:
Decode Mode
0x09
Turn on / off the decode mode
Intensity
0x0A
Adjust the brightness of the display
Scan Limit
0x0B
Determine how many digits are enabled
Shutdown
0x0C
Turn on / off the display module
Display Test
0x0F
Enter the test mode (all LED segments light on) or not
Digit 0 ~ Digit 7 data
0x01 ~ 0x08
The address to control digit 0 ~ digit 7
And they are defined in the Arduino code as:
For each of those registers, here we show some examples of applications:
Decode Mode (0x09)
MAX7219 supports two types of input data for each digit: 1) raw data or 2) BCD Code B. And each digit can run in different modes. For example:
Because only bit 1, 3 and 4 are set to 1, this command sets Digit 1 / 3 / 4 to BCD Code B decode mode and leaves Digit 0 / 2 / 5 / 6 / 7 to non-decode (raw data) mode.
Digit 0 ~ Digit 7 data (0x01 ~ 0x08)
In the raw data mode, users control all segments of a 7-segment display by themselves as what they did with 74HC595:
For instance, if a character "7" is going to be displayed on Digit 3, the segements "A", "B" and "C" (refer to the figure above) needs to be turned on, which means bit 6, bit 5 and bit 4 for the data byte of Digit 3 register need to be 1:
Although the raw mode adds complexities to describe the display data, it provides the flexibility for users to define all display patterns they need as below:
On the other hand, for the decode mode, characters defined in the BCD Code B set (see the table below) can be recognized by MAX7219 and indexed by a single value directly:
*For displaying the decimal point, set the bit 7 (D7) to 1 no matter in decode mode or in raw data mode.
That is, you can ask MAX7219 to drive the display to show 16 different characters: "0" to "9", "-", "E", "H", "L", "P" and " " (blank) directly without specifying segment data by yourself. For example to show a character "E", first configure Digit 5 to decode mode and set value 11 (B1011, see the table above) to the data byte of Digit 5, this makes it display the "E" character:
Intensity (0x0A)
Define the LED brightness of the display. The valid range is between 0x0 ~ 0xF.
Scan Limit (0x0B)
Use this value to decide how many digits are turned on for display. Here are some examples:
Shutdown (0x0C)
Turn on / off the display:
Display Test (0x0F)
Turn on the test mode makes all segments of the display light on.
The Counting Example
Let's put everything mentioned above together and modify the example used in the 74HC595 tutorial. A hexadecimal counting example with floating decimal point is shown in the following video and with the accompanying Arduino sketch code.
The default parameters of the setup are:
Count in hexadecimal mode
Use the raw data (non-decode) mode
Set to medium brightness
To change the hexadecimal mode to decimal / octal / binary counting mode, you can modify Line 52 to 10, 8 or 2. Below codes change the counting mode from hexadecimal to the decimal mode:
To enable the BCD Code B decode mode, you need to modify Line 74 and Line 111 as below:
and
Summary
By going through this tutorial, major functionalities of MAX7219 are introduced. Although it's designed to drive 7-segment displays, it can also be used to drive LEDs in a more general scenario. For example, a 8x8 dot-matrix display is another popular application which uses MAX7219 as the driving IC. This gives a good demonstration about how to use the raw data mode on driving such matrix displays. And we will take a closer look at it with another tutorial.
Last updated