Decode, or no decode
One bit per digit decides whether the chip reads a byte as a number or as seven segments. The second path gives you every shape the display can draw, and one trap: the MAX7219 numbers its segment bits backwards from every other display in the shop.
The same byte, two meanings
Switch the decode bit and watch what the eight cells are labelled. That is the whole feature: the byte is unchanged and what the chip does with it is not.
Decoder on. The chip reads the low four bits as a character and looks it up in its own font, called code B. Bits 4 to 6 are ignored entirely. You get sixteen characters:
0 1 2 3 4 5 6 7 8 9 - E H L P and a blank.
That is enough for a clock, a counter, a voltage, and - for out of range. It
is also why Error on a seven-segment display is so often spelled with E, H, L
and P in it — those four are the letters the decoder happens to have.
Decoder off. The eight bits are the eight segment lines, one each, and all 128 patterns are available. A, b, C, d, F, n, o, r, t, u, degree signs, bare bars, half a box. The cost is that you now own the font.
The bit order
This is the part that catches people, and it is worth stating flatly:
On a MAX7219, bit 7 is the decimal point, bit 6 is segment A, and it counts down to segment G at bit 0.
Almost every other seven-segment part counts the other way — segment A at bit 0, climbing to the point at bit 7. The TM1637 display in the same shop does. Every 74HC595 tutorial does. So a segment table copied from one of those into a MAX7219 sketch compiles, uploads, and draws the reflection of what you wanted.
There is no warning because there is nothing wrong: the byte is valid, the chip lights the segments it names, and they are the wrong segments. Symmetric characters — 0, 1, 8 — survive the mirroring and look correct, which is what makes the fault confusing to diagnose. Press the wrong-order button in the figure above and step through the characters to see which ones give the game away.
Per digit, not per chip
The decode-mode register is one byte at address 0x09, and each bit is one
digit. So the modes can be mixed:
// Decoder on for the low four digits, off for the top four.
lc.setScanLimit(0, 7);
sendRaw(0x09, 0x0F); // 0b000011110x0F is the useful one. It gives you four decoded number digits and four raw
ones, which is how a unit or a symbol goes beside a reading on the same display
— 23.5 in the decoder's font and a degree sign drawn by hand.
LedControl does not expose the decode-mode register directly. setDigit and
setChar go through the decoder; setRow writes a raw byte and quietly turns
that digit's decoding off first. If you want the mixed arrangement above,
setRow on the digits you want raw and setDigit on the rest gets you there
without touching 0x09 yourself.
Which to use
Use the decoder. It is smaller, faster to write, immune to the bit-order trap, and it is what the chip is for.
Turn it off for the specific digit that needs a shape the font does not have, and leave the rest alone. A whole display in raw mode is a font you are maintaining for no reason.
When it does not work
A segment table written for the wrong bit order. The MAX7219 puts the point at bit 7 and then counts down — A at bit 6, B at 5, G at bit 0. TM1637 and 74HC595 tables count up from A at bit 0, so every asymmetric character comes out as its own reflection. Reverse the low seven bits of each entry, or use the decoder and send numbers.
setChar goes through the code B decoder, and code B has exactly sixteen characters: 0 to 9, minus, E, H, L, P and blank. Anything else is a blank. For A, b, C, d, F, n, r, t and the rest you have to turn that digit's decode bit off and send the segments.
The decode-mode register is one byte for all eight digits, so writing 0x00 to it takes the decoder off everything at once — and the numbers already in the digit registers are then read as segment patterns, which mostly look like nothing. Rewrite the digits after changing the mode, and use a mask like 0x0F if you only wanted it off for some of them.
It did not; bit 7 is outside the decoder entirely and behaves identically in both modes. What changes is what the other seven bits mean. If the point vanished when you switched modes, the byte you are sending has bit 7 clear.
Decoder on for the number digits, off for the last one, and send 0b01100011 there — segments A, B, F and G, which draws a small circle at the top of the digit. That is the standard use of a mixed decode-mode byte.
One of them is a resistor soldered to the board and the other is a register, and only the second is yours.
Brightness is two numbers →Edit this page — content/books/max7219-tube-clock/decode-or-no-decode.mdx
Questions about this product
See what other owners have asked, and read their solutions.
MAX7219 Vintage Tube LED Clock Kit
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.