极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 75591|回复: 30

MAX7219芯片驱动8*8点阵

[复制链接]
发表于 2013-3-14 19:08:20 | 显示全部楼层 |阅读模式
在论坛混了一段时间了,总是看别人的帖子,感觉也应该分享点东西,人人为我,我为人人嘛,所以写下最近学习使用MAX7219芯片驱动8*8点阵的一点心得,希望能有帮助。
一、MAX7219芯片的引脚


二、8*8点阵引脚


三、ARDUINO与7129芯片的连接


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


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

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

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

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

  23. void setup() {
  24.   /*
  25.    The MAX72XX is in power-saving mode on startup,
  26.    we have to do a wakeup call
  27.    */
  28.   lc.shutdown(0,false);
  29.   /* Set the brightness to a medium values */
  30.   lc.setIntensity(0,8);
  31.   /* and clear the display */
  32.   lc.clearDisplay(0);
  33. }

  34. /*
  35. This method will display the characters for the
  36. word "Arduino" one after the other on the matrix.
  37. (you need at least 5x7 leds to see the whole chars)
  38. */
  39. void writeArduinoOnMatrix() {
  40.   /* here is the data for the characters */
  41.   byte a[5]={B01111110,
  42.                     B10001000,
  43.                     B10001000,
  44.                     B10001000,
  45.                     B01111110};
  46.   byte r[5]={B00111110,
  47.                     B00010000,
  48.                     B00100000,
  49.                     B00100000,
  50.                     B00010000};
  51.   byte d[5]={B00011100,
  52.                     B00100010,
  53.                     B00100010,
  54.                     B00010010,
  55.                     B11111110};
  56.   byte u[5]={B00111100,
  57.                     B00000010,
  58.                     B00000010,
  59.                     B00000100,
  60.                     B00111110};
  61.   byte i[5]={B00000000,
  62.                     B00100010,
  63.                     B10111110,
  64.                     B00000010,
  65.                     B00000000};
  66.   byte n[5]={B00111110,
  67.                     B00010000,
  68.                     B00100000,
  69.                     B00100000,
  70.                     B00011110};
  71.   byte o[5]={B00011100,B00100010,B00100010,B00100010,B00011100};

  72.   /* now display them one by one with a small delay */
  73.   lc.setRow(0,0,a[0]);
  74.   lc.setRow(0,1,a[1]);
  75.   lc.setRow(0,2,a[2]);
  76.   lc.setRow(0,3,a[3]);
  77.   lc.setRow(0,4,a[4]);
  78.   delay(delaytime1);
  79.   lc.setRow(0,0,r[0]);
  80.   lc.setRow(0,1,r[1]);
  81.   lc.setRow(0,2,r[2]);
  82.   lc.setRow(0,3,r[3]);
  83.   lc.setRow(0,4,r[4]);
  84.   delay(delaytime1);
  85.   lc.setRow(0,0,d[0]);
  86.   lc.setRow(0,1,d[1]);
  87.   lc.setRow(0,2,d[2]);
  88.   lc.setRow(0,3,d[3]);
  89.   lc.setRow(0,4,d[4]);
  90.   delay(delaytime1);
  91.   lc.setRow(0,0,u[0]);
  92.   lc.setRow(0,1,u[1]);
  93.   lc.setRow(0,2,u[2]);
  94.   lc.setRow(0,3,u[3]);
  95.   lc.setRow(0,4,u[4]);
  96.   delay(delaytime1);
  97.   lc.setRow(0,0,i[0]);
  98.   lc.setRow(0,1,i[1]);
  99.   lc.setRow(0,2,i[2]);
  100.   lc.setRow(0,3,i[3]);
  101.   lc.setRow(0,4,i[4]);
  102.   delay(delaytime1);
  103.   lc.setRow(0,0,n[0]);
  104.   lc.setRow(0,1,n[1]);
  105.   lc.setRow(0,2,n[2]);
  106.   lc.setRow(0,3,n[3]);
  107.   lc.setRow(0,4,n[4]);
  108.   delay(delaytime1);
  109.   lc.setRow(0,0,o[0]);
  110.   lc.setRow(0,1,o[1]);
  111.   lc.setRow(0,2,o[2]);
  112.   lc.setRow(0,3,o[3]);
  113.   lc.setRow(0,4,o[4]);
  114.   delay(delaytime1);
  115.   lc.setRow(0,0,0);
  116.   lc.setRow(0,1,0);
  117.   lc.setRow(0,2,0);
  118.   lc.setRow(0,3,0);
  119.   lc.setRow(0,4,0);
  120.   delay(delaytime1);
  121. }

  122. /*
  123.   This function lights up a some Leds in a row.
  124. The pattern will be repeated on every row.
  125. The pattern will blink along with the row-number.
  126. row number 4 (index==3) will blink 4 times etc.
  127. */
  128. void rows() {
  129.   for(int row=0;row<8;row++)
  130.   {
  131.     delay(delaytime);
  132.     lc.setRow(0,row,B10100000);
  133.     delay(delaytime);
  134.     lc.setRow(0,row,(byte)0);
  135.     for(int i=0;i<row;i++) {
  136.       delay(delaytime);
  137.       lc.setRow(0,row,B10100000);
  138.       delay(delaytime);
  139.       lc.setRow(0,row,(byte)0);
  140.     }
  141.   }
  142. }

  143. /*
  144.   This function lights up a some Leds in a column.
  145. The pattern will be repeated on every column.
  146. The pattern will blink along with the column-number.
  147. column number 4 (index==3) will blink 4 times etc.
  148. */
  149. void columns() {
  150.   for(int col=0;col<8;col++) {
  151.     delay(delaytime);
  152.     lc.setColumn(0,col,B10100000);
  153.     delay(delaytime);
  154.     lc.setColumn(0,col,(byte)0);
  155.     for(int i=0;i<col;i++) {
  156.       delay(delaytime);
  157.       lc.setColumn(0,col,B10100000);
  158.       delay(delaytime);
  159.       lc.setColumn(0,col,(byte)0);
  160.     }
  161.   }
  162. }

  163. /*
  164. This function will light up every Led on the matrix.
  165. The led will blink along with the row-number.
  166. row number 4 (index==3) will blink 4 times etc.
  167. 此函数点亮点阵上的所有LED,
  168. 每个LED会根据所在的行数闪烁相应的次数
  169. 例如:第四行的LED会闪四次
  170. */
  171. void single() {
  172.   for(int row=0;row<8;row++)
  173.   {
  174.     for(int col=0;col<8;col++)
  175.     {
  176.       delay(delaytime);
  177.       lc.setLed(0,row,col,true);
  178.       delay(delaytime);
  179.       for(int i=0;i<col;i++)
  180.       {
  181.         lc.setLed(0,row,col,false);
  182.         delay(delaytime);
  183.         lc.setLed(0,row,col,true);
  184.         delay(delaytime);
  185.       }
  186.     }
  187.   }
  188. }

  189. void loop() {
  190.   writeArduinoOnMatrix();
  191.   rows();
  192.   columns();
  193.   single();
  194.   lc.clearDisplay(0);
  195. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1 +5 收起 理由
幻生幻灭 + 5 赞一个!

查看全部评分

回复

使用道具 举报

发表于 2013-3-14 19:32:10 | 显示全部楼层
写的很不错。
{:soso_e179:}
加油~
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-3-14 20:09:17 | 显示全部楼层
Damn_intuition 发表于 2013-3-14 19:32
写的很不错。

加油~

谢谢,希望对大家有帮助。
回复 支持 反对

使用道具 举报

发表于 2013-3-15 00:22:18 | 显示全部楼层
{:soso_e142:} 终于看到7219的文章咯
回复 支持 反对

使用道具 举报

发表于 2013-3-15 09:52:24 | 显示全部楼层
这个可以有!
回复 支持 反对

使用道具 举报

发表于 2013-3-15 11:41:25 | 显示全部楼层
MAX7219驱动 很专业!

回复 支持 反对

使用道具 举报

发表于 2013-9-20 11:00:44 | 显示全部楼层
LZ有没有好一些的点阵取模软件推荐一下的呢?
回复 支持 反对

使用道具 举报

发表于 2013-11-7 23:58:00 | 显示全部楼层
库文件在哪找啊 为
回复 支持 反对

使用道具 举报

发表于 2013-11-26 15:31:28 | 显示全部楼层
你这没测试过吧! 根本没这库文件!
回复 支持 反对

使用道具 举报

发表于 2013-12-8 17:55:15 | 显示全部楼层
想问下如果两个8*8点阵max7219, 一个是比如’A‘字向走左和重复,另一个只是显示’B‘。有可能实现吗?一样信号咯。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-12-30 11:45:33 | 显示全部楼层
guangliang825 发表于 2013-11-26 15:31
你这没测试过吧! 根本没这库文件!

这个我已经测试过,库文件你可以去官网搜一下。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-12-30 11:47:31 | 显示全部楼层
wilson16 发表于 2013-12-8 17:55
想问下如果两个8*8点阵max7219, 一个是比如’A‘字向走左和重复,另一个只是显示’B‘。有可能实现吗?一样 ...

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

使用道具 举报

发表于 2014-1-9 22:40:25 | 显示全部楼层
为何我照着图片接线,然后直接把代码原封不动拷贝结果上传了什么反应也没有。。。。
回复 支持 反对

使用道具 举报

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

求指点
回复 支持 反对

使用道具 举报

发表于 2014-1-24 21:28:15 | 显示全部楼层
好帖子,我刚买了一个,按照这篇文章的办法很快点亮了。需要特别注意的是线的顺序。

感谢楼主
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-28 17:19 , Processed in 0.053838 second(s), 30 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表