max7219 is a driver chip for driving 8-bit 7-segment digital LED or 8x8 dot matrix LED. It uses 16 pins to manage 64 light points in a column scan mode. The refresh rate is 500-1300Hz when displaying 8 digits, and the typical value is 800Hz.
Pin Function
DIG0 - DIG7: These 8 pins represent a 7-segment number + a dot.
SEGA - SEGG, DP: AG represents each segment of the 7-segment number, DP represents the decimal point between the numbers
The driving current of each section is 40mA. If the load requires a higher current, an external hardware driver is required.
V+, GND: Voltage and Ground
DIN: Serial data input
CS: Chip select, when the level is pulled down, the data is shifted into the shift register according to the clock from the serial port, and when the level is pulled up, it is latched
DOUT: serial data output, this port is used for cascading
N MAX7219s in cascade can be viewed as N 16-bit shift registers in series.
If you want to operate on the Nth bit, the data will arrive after 16*N clocks. At this time, CS is pulled up to latch the command.
way of communication
The communication protocol is SPI, accepts input from the SPI Master, and does not return data
MAX7219, no matter what the CS level is, the data on DIN will be written into the shift register along with the clock.
MAX7221, data is written from DIN or written to DOUT only when CS is pulled down
CS must be pulled high after the 16th number is written and before the next rising edge of the clock, otherwise the data will be lost.
Data is MSB, large value first
For 16 bits, the first 8 bits (D15-D08) are addresses, and only 4 bits D11-D8 are actually used. The last 8 bits D7-D0 are data.
Previous address of correspondence
There are 14 in total
0x?0: No-Op, used to output data to DOUT
0x?1: the first number
0x?2: The second one
0x?3: The third one
0x?4: The fourth
0x?5: The fifth
0x?6: The sixth
0x?7: The seventh
0x?8: The eighth
0x?9: Digital decoding mode
0x?A: Brightness, 0x00 to 0xFF
0x?B: Scan limit (limit the number of columns displayed), the value is 0-7, the smaller the number, the brighter the single column, generally should not be less than 3.
0x?C: Status (off, normal)
0x?F: test status (test, normal)
Cascade transmission
Using No-Op address operation to achieve cascade transmission
For example, write to the fourth MAX7219
First, write the address according to the preset address, write the value
Write three NoOp operations (0x?0??), where ? represents a random value
When CS is pulled high, the four MAX7219s will receive the operation address and operation value, but the first three blocks see NoOp, so the first three blocks have no action
Use STC12 hardware SPI driver
The STC12C5A60S2 series has built-in SPI support. Based on the HML_FwLib_STC12 package library, the dot matrix driver of MAX7219 can be easily implemented. Code:
/********************************************************************************/
/**
* file spi_max7219.c
* author IOsetting | iosetting@outlook.com
* date
* brief Example code of SPI driving dot matrix module
* note The module chip is MAX7219, pin connection:
* P1_3 => CS,
* P1_5(MOSI) => DIN,
* P1_7(SPCLK) => CLK
*
* version v0.1
* ingroup example
* remarks test-board: Minimum System; test-MCU: STC12C5AF56S2
**********************************************************************************/
/********************************************************************************
* header file *
*********************************************************************************/
#include "hml/hml.h"
#define CS P1_3
#define DECODE_MODE 0x09
#define INTENSITY 0x0A
#define SCAN_LIMIT 0x0B
#define SHUT_DOWN 0x0C
#define DISPLAY_TEST 0x0F
const byte numbers[] = {
0x00,0x00,0x7C,0xC6,0xC6,0xCE,0xD6,0xD6, // -0-.
0xE6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x38,0x78,0x18,0x18,0x18, // -1-
0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0x06,0x0C,0x18,0x30, // -2-
0x60,0xC0,0xC6,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0x06,0x06,0x3C,0x06, // -3-
0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x1C,0x3C,0x6C,0xCC,0xFE, // -4-
0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xC0,0xC0,0xC0,0xFC,0x0E, // -5-
0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x60,0xC0,0xC0,0xFC,0xC6, // -6-
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xC6,0x06,0x06,0x0C,0x18, // -7-
0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7C,0xC6, // -8-
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7E,0x06, // -9-
0x06,0x06,0x0C,0x78,0x00,0x00,0x00,0x00};
void Write7219(byte addr, byte dat)
{
CS = 0;
SPI_RW(addr);
SPI_RW(dat);
CS = 1;
}
/********************************************************************************/
/**
* author IOsetting
* date
* briefly initialize MAX7219
* param[in]
* return none
* ingroup example
* remarks
**********************************************************************************/
void Init7219(void)
{
Write7219(SHUT_DOWN,0x01); // 0x00: shutdown, 0x01: normal
Write7219(DECODE_MODE,0x00); // No decode
Write7219(SCAN_LIMIT,0x07); // Display 8 digits
Write7219(INTENSITY,0x00); // 0x00:min, 0xFF:max
Write7219(DISPLAY_TEST,0x00); // 0x00:normal, 0x01:test mode
}
/********************************************************************************/
/**
* author IOsetting
* date
* briefly initialize SPI
* param[in]
* return none
* ingroup example
* remarks
**********************************************************************************/
void initSys(void)
{
SPI_configTypeDef sc;
sc.baudRatePrescaler = SPI_BaudRatePrescaler_64;
sc.cpha = SPI_CPHA_1Edge;
sc.cpol = SPI_CPOL_low;
sc.firstBit = SPI_FirstBit_MSB;
sc.pinmap = SPI_pinmap_P1;
sc.nss = SPI_NSS_Soft;
sc.mode = SPI_Mode_Master;
SPI_config(&sc);
SPI_cmd(ENABLE);
}
void main()
{
initSys();
Init7219();
P1_3 = 1;
byte pos = 0, size = sizeof(numbers), i, j;
while(1)
{
for (i = 0; i < 8; i++)
{
j = (pos + i) % size;
Write7219(i + 1, numbers[j]);
}
pos = (pos + 1) % size;
sleep(100);
}
}
refer to
Very useful instructions for MAX7219 https://wayoda.github.io/LedControl/pages/software
Previous article:STC8 MCU OLED is driven by SPI hardware interrupt (Part 1)
Next article:51 MCU package library HML_FwLib_STC89/STC11
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- [Bluesun AB32VG1 RISC-V evaluation board] IDE installation and use
- It's New Year's Eve soon. I wish you all a happy New Year.
- 【DIY Creative LED】Add touch button and install it on LED lamp
- [RISC-V MCU CH32V103 Review] - 2: Making an LED flash is not easy
- SensorTile.box uses air pressure sensors to analyze environmental changes
- When using an oscilloscope probe to measure the AC waveform between the two ends of a component, how should the probe ground wire be connected?
- 【ST NUCLEO-H743ZI Review】(2)Ethernet Test
- TI.com Online Purchasing Special (Smart Building) has a limited time offer, with discounts as low as 30%!
- DLP Lightcrafter 4500 EVM FAQ Summary
- NRF24L01 module usage