Monday, July 22, 2013

AVR Atmega MAX7219 7-segment / led matrix display driver library

Updated to version 03

The MAX7219/MAX7221 are compact, serial input/output common-cathode display drivers that interface microprocessors to 7-segment numeric LED displays of up to 8 digits, bar-graph displays, or 64 individual LEDs.

MAX7219 prevents the use of microprocessor resorces, indeed all the logic to drive LED drivers is built inside this small IC.
This library use 3 ports to control MAX7219 ic. It can control more than one ic, without the need of SPI. User can setup scan limit, intensity and other parameter of the ic.

Setup parameters are stored in file max7219.h

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 1MHz.


  • added atomic enabler on shift out function
  • added get status functions
  • first version


  • read risk disclaimer
  • excuse my bad english


  1. Hi! I'm using the same LED modules and ATMega644PA. I've built your example code (unmodified) using Atmel Studio 6. Unfortunately, something is wrong and pixels "run" only by 1st line of each module... Can you help?

    1. Hello, this project is compiled with avrgcc, as far as i know Atmel Studio run avrgcc as default compiler, so it should not be the compiler the source of your problem. So, double check your wiring, and check that you are running the micro at the proper speed, check fuses. If those check passes, check with a logic analizer, what's going on the input pins of the MAX7219. If you do not have a logic analizer, import a uart library, and debug using some uart output to your terminal.

    2. Im having the same problem.

    3. Hello, have you try all the suggestions I've tell on the comment above here?

    4. I have try, use avr-gcc. Its OK, no problem.

  2. Really thanks for the blog and the code :)

    Good luck,

  3. Hello Davide, do you have an example of running text/scrol up text for 8x8 led matrix ? Thanks

    1. Hello, no unlucky I have no example for that, you have it to code by yourself. If you do this, and would like to share that code you can post your gist or pastebin code link here, it would be usefull for other people maybe.

  4. Hello David,
    I just try your code, however I received error below:

    c:/program files/atmel/avr tools/avr toolchain/bin/../lib/gcc/avr/4.4.3/../../../../avr/bin/ld.exe: cannot find -l_max7219_01\david_avr_lib_max7219_01
    make: *** [david_avr_lib_max7219_01.elf] Error 1
    Build failed with 1 errors and 0 warnings...

    I have AVR4.18 Build 716 SP3, Toolchain

    Please help,

    1. Hello, you have to link all the code needed. You can find a few information about avrgcc compiling on avrfreaks forum

  5. Hello i attached 8 seven segment two single Max7219 IC i want to count it from 00 to 99999999 can i get sample code for it??
    m trying my own but its not working.
    please help

    1. Hello, you can use the max7219 library, and a seven segment device. This is much easyer.