yangqiang29 发表于 2013-3-14 19:08:20

MAX7219芯片驱动8*8点阵

在论坛混了一段时间了,总是看别人的帖子,感觉也应该分享点东西,人人为我,我为人人嘛,所以写下最近学习使用MAX7219芯片驱动8*8点阵的一点心得,希望能有帮助。
一、MAX7219芯片的引脚


二、8*8点阵引脚


三、ARDUINO与7129芯片的连接


四、7219芯片与点阵的连接
(1)共阴极点阵的连接图


(2)共阳极点阵的连接
芯片引脚行、列对换。
关键:芯片引脚Seg应始终与阳极相连,引脚Dig应始终与阴极相连。
五、代码
/*
日期:2013-2-18
功能:MAX7219驱动8*8点阵
作者:YQ
IDE:1.0.2
硬件:最小系统UNO
说明:本代码主要参考了官方的示例程序
*/

//官方的库
#include "LedControl.h"

/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
第一个参数:pin 12 is connected to the DataIn
第二个参数:pin 11 is connected to the CLK
第三个参数:pin 10 is connected to LOAD
第四个参数:We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);

/* we always wait a bit between updates of the display */
unsigned long delaytime=100;
unsigned long delaytime1=2000;

void setup() {
/*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}

/*
This method will display the characters for the
word "Arduino" one after the other on the matrix.
(you need at least 5x7 leds to see the whole chars)
*/
void writeArduinoOnMatrix() {
/* here is the data for the characters */
byte a={B01111110,
                B10001000,
                B10001000,
                B10001000,
                B01111110};
byte r={B00111110,
                B00010000,
                B00100000,
                B00100000,
                B00010000};
byte d={B00011100,
                B00100010,
                B00100010,
                B00010010,
                B11111110};
byte u={B00111100,
                B00000010,
                B00000010,
                B00000100,
                B00111110};
byte i={B00000000,
                B00100010,
                B10111110,
                B00000010,
                B00000000};
byte n={B00111110,
                B00010000,
                B00100000,
                B00100000,
                B00011110};
byte o={B00011100,B00100010,B00100010,B00100010,B00011100};

/* now display them one by one with a small delay */
lc.setRow(0,0,a);
lc.setRow(0,1,a);
lc.setRow(0,2,a);
lc.setRow(0,3,a);
lc.setRow(0,4,a);
delay(delaytime1);
lc.setRow(0,0,r);
lc.setRow(0,1,r);
lc.setRow(0,2,r);
lc.setRow(0,3,r);
lc.setRow(0,4,r);
delay(delaytime1);
lc.setRow(0,0,d);
lc.setRow(0,1,d);
lc.setRow(0,2,d);
lc.setRow(0,3,d);
lc.setRow(0,4,d);
delay(delaytime1);
lc.setRow(0,0,u);
lc.setRow(0,1,u);
lc.setRow(0,2,u);
lc.setRow(0,3,u);
lc.setRow(0,4,u);
delay(delaytime1);
lc.setRow(0,0,i);
lc.setRow(0,1,i);
lc.setRow(0,2,i);
lc.setRow(0,3,i);
lc.setRow(0,4,i);
delay(delaytime1);
lc.setRow(0,0,n);
lc.setRow(0,1,n);
lc.setRow(0,2,n);
lc.setRow(0,3,n);
lc.setRow(0,4,n);
delay(delaytime1);
lc.setRow(0,0,o);
lc.setRow(0,1,o);
lc.setRow(0,2,o);
lc.setRow(0,3,o);
lc.setRow(0,4,o);
delay(delaytime1);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
delay(delaytime1);
}

/*
This function lights up a some Leds in a row.
The pattern will be repeated on every row.
The pattern will blink along with the row-number.
row number 4 (index==3) will blink 4 times etc.
*/
void rows() {
for(int row=0;row<8;row++)
{
    delay(delaytime);
    lc.setRow(0,row,B10100000);
    delay(delaytime);
    lc.setRow(0,row,(byte)0);
    for(int i=0;i<row;i++) {
      delay(delaytime);
      lc.setRow(0,row,B10100000);
      delay(delaytime);
      lc.setRow(0,row,(byte)0);
    }
}
}

/*
This function lights up a some Leds in a column.
The pattern will be repeated on every column.
The pattern will blink along with the column-number.
column number 4 (index==3) will blink 4 times etc.
*/
void columns() {
for(int col=0;col<8;col++) {
    delay(delaytime);
    lc.setColumn(0,col,B10100000);
    delay(delaytime);
    lc.setColumn(0,col,(byte)0);
    for(int i=0;i<col;i++) {
      delay(delaytime);
      lc.setColumn(0,col,B10100000);
      delay(delaytime);
      lc.setColumn(0,col,(byte)0);
    }
}
}

/*
This function will light up every Led on the matrix.
The led will blink along with the row-number.
row number 4 (index==3) will blink 4 times etc.
此函数点亮点阵上的所有LED,
每个LED会根据所在的行数闪烁相应的次数
例如:第四行的LED会闪四次
*/
void single() {
for(int row=0;row<8;row++)
{
    for(int col=0;col<8;col++)
    {
      delay(delaytime);
      lc.setLed(0,row,col,true);
      delay(delaytime);
      for(int i=0;i<col;i++)
      {
      lc.setLed(0,row,col,false);
      delay(delaytime);
      lc.setLed(0,row,col,true);
      delay(delaytime);
      }
    }
}
}

void loop() {
writeArduinoOnMatrix();
rows();
columns();
single();
lc.clearDisplay(0);
}

Damn_intuition 发表于 2013-3-14 19:32:10

写的很不错。
{:soso_e179:}
加油~

yangqiang29 发表于 2013-3-14 20:09:17

Damn_intuition 发表于 2013-3-14 19:32 static/image/common/back.gif
写的很不错。

加油~

谢谢,希望对大家有帮助。

Micky 发表于 2013-3-15 00:22:18

{:soso_e142:} 终于看到7219的文章咯

Randy 发表于 2013-3-15 09:52:24

这个可以有!

幻生幻灭 发表于 2013-3-15 11:41:25

MAX7219驱动 很专业!

guqi 发表于 2013-9-20 11:00:44

LZ有没有好一些的点阵取模软件推荐一下的呢?

~风雨四年~/kel 发表于 2013-11-7 23:58:00

库文件在哪找啊 为

guangliang825 发表于 2013-11-26 15:31:28

你这没测试过吧! 根本没这库文件!

wilson16 发表于 2013-12-8 17:55:15

想问下如果两个8*8点阵max7219, 一个是比如’A‘字向走左和重复,另一个只是显示’B‘。有可能实现吗?一样信号咯。

yangqiang29 发表于 2013-12-30 11:45:33

guangliang825 发表于 2013-11-26 15:31 static/image/common/back.gif
你这没测试过吧! 根本没这库文件!

这个我已经测试过,库文件你可以去官网搜一下。

yangqiang29 发表于 2013-12-30 11:47:31

wilson16 发表于 2013-12-8 17:55 static/image/common/back.gif
想问下如果两个8*8点阵max7219, 一个是比如’A‘字向走左和重复,另一个只是显示’B‘。有可能实现吗?一样 ...

个人觉得应该是可以的,只不过需要合理的算法去确定怎么取模。

zxyy15717 发表于 2014-1-9 22:40:25

为何我照着图片接线,然后直接把代码原封不动拷贝结果上传了什么反应也没有。。。。

zxyy15717 发表于 2014-1-9 22:52:02

另外硬件上我始终有两点没想通,求指点:1.共阴极的点阵各行是阴极连在一起的,如果送给高电平进去那阴极不久成高电平了吗??所以感觉送高电平的恰恰不应该亮才对啊。。。2.共阴极点阵的各行是连在一起的,那应该是只需送一个电平进去整行就应该同时反映吧,没法控制同一行里有些亮有些不亮吧,感觉只能是全亮全灭。。。。

求指点

zoologist 发表于 2014-1-24 21:28:15

好帖子,我刚买了一个,按照这篇文章的办法很快点亮了。需要特别注意的是线的顺序。

感谢楼主
页: [1] 2 3
查看完整版本: MAX7219芯片驱动8*8点阵