Fads to Obsessions and Beyond...




Free domain for life, exceptional technical support, website transfer

Max7221 LED Driver

A MAX7221 is interfaced to a PIC16F876A microcontroller. The MAX7221 is used to control three 8x8 LED matrices (64 LED's each) daisy chained for an animated scrolling text display. A 8x8inch DIY 64 LED matrix is also constructed and demonstrated.

The Animated LED Matrix Sign project, required the control of 320 LED's to form an animated text display. The MAX7221 was selected as it enables control of 64 individual LED's via a convenient 3-wire serial interface. Multiple MAX7221 chips can be daisy chained, and thus the PIC microcontroller can control large numbers of LED's (up to 320 in the following test circuit/program) with only 3 output pins.

The MAX7221 also provides the following from the datasheet:

    • Individual LED segment control
    • Decode/No-Decode digit selection (for 7-segment numeric displays)
    • Digital and Analog Brightness control
    • Common-cathode LED displays
    • SPI compatible
    • Individual digits (ie LED's) can be addressed/updated without rewriting entire the display

The MAX7219 and MAX7221 are identical except for two parameters: the MAX7221 segment drivers are slew-rate limited to reduce electromagnetic interference (EMI), and its serial interface is fully SPI compatible. The MAX7219 and MAX7221 cost approximately the same from ebay, and the SPI compatibility of the MAX7221 can be a possible advantage with microcontroller application. A MAX7221 was used during this component evaluation.

The advantage of a MAX7221 over an approach using for example 74HC595 8-bit shift registers is the lower part count when the number of LED's involved in a display circuit increases. For example, a 8x8 LED matrix would require 2 x 74HC595, a ULN2803 transistor array (because of the limited source current capacity of the shift register) and firmware/software to handle the multiplexing/strobing to control the on/off of individual LED's in the array.

Whereas, the same 8x8 LED matrix would require a single MAX7221. Although, interface firmware/software for the MAX7221 would be still required, this approach would allow brighter displays without 'flicker' with fast refresh rates if required. See the evaluation of 74HC595 8-bit shift registers for LED display control.

  • MAX7221 with 8 x 7-segment DisplaysMAX7221 with 8 x 7-segment Displays

    Silver Membership registration gives access to full resolution schematic diagrams.

    MAX7221 with 8 x 7-segment Displays

The circuit involves the usual minimum components to enable the operation of the PIC microcontroller with the addition of the MAX7221 connected via the 3-wire interface, and in turn the MAX7221 connected to the LED matrix.

Power Supply

A typical "wall-wart" power-supply is used (a surplus laptop charger in this case) in conjunction with a voltage regulator (LM7805) to provide the regulated 5V required by the PIC microcontroller.

Circuit Operation

A number of schematic diagrams are given. Schematic diagram 1 shows the basic connection of a single MAX7221 with a 8x8 LED matrix formed from individual LED's. Schematic diagram 2 shows a similar arrangement, except the LED matrix is a commercial bicolor (red/green) component. In this example, only the red LEDs are connected. Schematic diagram 3 shows how multiple MAX7221's are daisy chained to control multiple LED matrices (or a second MAX7221 could be used to control the green LED's of the bicolor matrix). In each case the circuit operation is basically similar.

The LM7805 provides the 5V circuit voltage, in this case, stepping down from the 12V input from a "wall-wart" power-supply.

The crystal X1 and associated capacitors C1 and C2 provide the oscillator for the PIC16F876A microcontroller. Incircuit serial programming (ICSP) of the PIC16F876A microcontroller is provided via connector J1 with switch SW1, resistor R1 and diode D2 providing voltage protecting during loading code into the PIC microcontroller.

Control signals from the PIC16F876A microcontroller are sent from port C (pins 12, 14 and 16) to the MAX7221 using SPI protocol. Via the SPI interface, the PIC16F876A can send the necessary commands to instruct which LED's are to be enabled by the MAX7221 (described in the Testing/Experimental Results Section).

The MAX7221 has the necessary internal circuity to enable BCD code-B decoding (i.e. BCD data can be sent to the MAX7221 which will then 'automatically' determine which LED segments need to be enabled to display the corresponding decimal digit), multiplex scan circuitry, segment and digit drivers, and an 8x8 static RAM to store data.

R2 sets the peak current on display LED's controlled by the MAX7221 as 100 times the current entering the ISET of the MAX7221 (pin 18). The datasheet recommends 9.53ohm, which then typically sets the LED current at 40mA. While R2 could be replaced with a potentiometer to enable brightness adjustment, LED intensity can also be controlled digitially via SPI/commands.

Decoupling capacitors C5 and C6 as close to the MAX7221 as possible were required on the large DIY 8x40inch display to stop 'glitching' as the power supply lines are long in this case. As recommended by the datasheet a 10uF electrolytic and a 0.1uF ceramic capacitor were used.

Note both GND pins (4 and 9) of the MAX7221 must be connected to ground.

The matrix displays (refer to Schematic Diagram 1) show how individual LEDs are connected with common anodes/cathodes in a rows by columns type arrangement. The MAX7221 handles the necessary multiplexing, which by the datasheet is typically 800Hz.

Software/Firmware

The PIC16F876A interfaces via SPI and therefore requires firmware to handle the data transfer and provide the logic/data to enable the desired display functionality.

SPI 'bit-banging' routines are described in the Testing/Experimental Results Section, together with example code that enables animated text scrolling LED displays on both commercial LED 8x8 matrix displays and a large (8x36 inch) DIY 320 LED display. See the Video Section for examples of the display in operation.


Note: Image loading can be slow depending on server load.

  • MAX7221 SchematicMAX7221 Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    MAX7221 Schematic with DIY 64xLED matrix

    Schematic 1: MAX7221 Schematic with 64xLED matrix

  • MAX7221 SchematicMAX7221 Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    MAX7221 Schematic with 8x8 Red/Green LED matrix

    Schematic 2: MAX7221 Schematic with 8x8 Red/Green LED matrix

  • MAX7221 SchematicMAX7221 Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    MAX7221 Schematic with Two 8x8 Red/Green LED matrix

    Schematic 3: MAX7221 Schematic with Two 8x8 Red/Green LED matrix

This project did not require a PCB as only evaluating the Max7221. However, the subsequent Animated LED Matrix Sign project utilises five Max7221's daisy-chained, with a corresponding PCB.

The construction of the evaluation of the Max7221 was done using prototyping board. See the photographs and schematic diagram sections.

Qty Schematic Part-Reference Value Notes/Datasheet
Resistors
3R1-R310k1/4W, 10% 
Capacitors
2C1,C222pFCeramic 
1C30.33uF 
3C4,C6,C80.1uF 
2C5,C710uF 
Integrated Circuits
1U1PIC16F876APIC microcontroller datasheet
1U278055V Linear Voltage Regulator datasheet
1U3,U4MAX7221Serially Interfaced, 8-Digit LED Driver datasheet
Diodes
1D21N-4004 
Miscellaeous
1J1CONN-H55-pin connector for ICSP
1SW1SW-SPDT 
1X110MHzCrystal Oscillator
1Z1,Z2 8x8 Dot Matrix Display

Description Downloads
MAX7221 LED Display Bill of Materials Text File Download

The majority of the testing simply involves exploring/developing the PIC16F876A code library to provide the necessary interfacing and control.

The Video Section shows the developed code in example software to control dot matrix LED displays and animated scrolling text displays.

MAX7221 SPI Interface/Control Registers

The MAX7221 datasheet gives full details, but the following is a summary of the interfacing via SPI/control registers.

Data is sent to the MAX7221 as a serial data stream of 16-bit packets. To clock data into the MAX7221, the CS line (pin 12) is held low, and then the data is clocked into DIN (pin 1) with each rising edge of CLK (pin 13). After the 16th bit, the data is latched when the CS line goes high. If more than one 16-bit data packet is clocked into the MAX7221, the data is propagated at DOUT (pin 24). Consequently, connecting DOUT from one MAX7221 to the DIN of a further MAX7221 allows daisy-chaining.

The MAX7221 register map and the BCD to Code B font mapping (together with the MAX7221 pin outs for when not using BCD decode mode) is summarised in the following diagram.

  • MAX7221 Instruction SetMAX7221 Instruction Set

    Silver Membership registration gives access to full resolution schematic diagrams.

    MAX7221 Register/Instruction Set

PIC Microcontroller Interface Code

The PIC micrcontroller code is based upon information given in a blog post discussing interfacing a PIC18F4550 with a 7-segment numeric LED display.(1). Various downloads are available in the table below.

The header file contains various #define's used to specify the MAX7221 command set, SPI/interface pin definitions and the following functions:


 void max7221_ClkOutData(char theData);  
     // 'bit-bang' sending a single byte of data to MAX7221                       
 void max7221_putData(char RegAddr,char theData, char addr7221);                 
     //RegAddr - Max7221 register address
     //theData - register data portion
     //add7221 - the Id number for cascaded Max7221 (1st chip is Id 1)
     //uses max7221_ClkOutData() to send the actual data to the MAX7221  
 void max7221_init();
     // Initialise all daisy-chained MAX7221. 
     // #define NUM_CASCADED_MAX7221 = number of cascaded chips 
     // Initialised state = no decode mode, scan limit all digits,
     //                     duty cycle 7, normal mode for shutdown     
                

The current code is targetted at controlling 8x8 dot matrix displays to enable scrolling text messages and animated displays. This means specific functions to enable output of 'decimal' digits to 7-segment LED displays is not specifically handled (i.e. using the MAX7221 capacity to decode BCD directly to 7-segment output display control).

The following example program (output shown in the Video Section) demonstrates the functionality of a scrolling message with a three 8x8 dot-matrix display.


#include "string.h"
#include "max7221.h"
//#define NUM_CASCADED_MAX7221 3 in max7221.h 

#define STRING_SIZE  6  //max chars allowed = STRING_SIZE-1

void main() {
   char dispChar;
   char input_str[STRING_SIZE]={'H','E','L','L','O'};
   int i;
   int j;
   int stringLen;
   int scrollEnd;

   max7221_init();
//!   max7221_putData(MAX7221Reg_DISPLAY_TEST,DISPLAY_TEST_MODE);
   
   stringLen=strlen(input_str);  
   scrollEnd=-6*stringLen; //6=character width
   do {
      for (i=24;i>scrollEnd;i--) { 
         currentPos=i;
         for (j=0; j < stringLen; j++) {
            max7221_PrintChar(input_str[j]);
            delay_ms(50); //scroll 'step' time
         }         
      }
   } while (TRUE);
}
			  

A more comprehensive example of the code for the MAX7221 incorporating scrolling text display with animations is given in the Animated LED Matrix Sign project which utilises five Max7221's daisy-chained to control a 8 x 36 inch DIY display composed of LED's.

PIC Microcontroller Code Downloads

Description Downloads
MAX7221 header file: CCS C Source Code Download

The construction was done using prototyping board. See the photographs and schematic diagram sections.

However, for some details about DIY dot-matrix displays, the subsequent Animated LED Matrix Sign project utilises five Max7221's daisy-chained, with a large 8 x 36 inch DIY dot-matrix LED display. That project describes construction details for the DIY dot matrix display from individual LED's.

A potential 'gotcha' when first starting using a MAX7221 is that on initial power-up, all control registers are reset, the display is blanked, and the MAX7221 is in shutdown mode. This means that the microcontroller will need to send some initial setup information (e.g. 'shutdown' register x0C , and set bit D0 to '1' to enable normal operation) to enable operation of the MAX7221. Similarily, on power-up the MAX7221 will only scan a single digit, does not decode BCD data and the intensity register is set to minimum value.

A final thing to note, decoupling capacitors as close to the MAX7221 as possible are likely to be needed (see Circuit Details section) and both GND pins (4 and 9) of the MAX7221 must be connected to ground (as per recommendation in the datasheet).

Note: Image loading can be slow depending on server load.


Note: Video loading can be slow depending on server load.

The video's below show demonstrations of animations/scrolling messages on daisy-chained 8x8 dot matrices interfaced via MAX7221 with PIC 16F876A. The demonstration code is discussed in the "Background Section" above.

Comments/Questions

No comments yet.

Add Comment/Question

Only Logged-In Members can add comments

"If we could sell our experiences for what they cost us, we'd all be millionaires".

Please donate any amount to help with hosting this web site.

If you subscribe (only $2/annum) you can view the site without advertisements and get emails abouts updates etc.

X

Sorry!

Only logged-in users with correct Membership Level can download.


Membership starts at only $2, so join now!