在pcDuino上面使用LED Matrix Kit-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5027|回复: 1

在pcDuino上面使用LED Matrix Kit

[复制链接]
发表于 2014-1-10 13:10 | 显示全部楼层 |阅读模式
本帖最后由 Lily 于 2014-1-10 13:14 编辑

     LED matrix kit是一个 8×8的 LED 矩阵。  它的驱动芯片是MAX7219。 MAX7219通过SPI接口和主机通讯。 pcDuino已经实现了SPI接口API。 在这里,我们看看怎么来吧LED matrix kit集成到pcDuino。
1、实验清单:一块pcDuino V2,一套A/ V KIT,一块 8×8的 LED matrix kit、杜邦线
2、实验要求:pcDuino里自带arduino IDE的程序
3、试验过程:
    (1)将 LED matrix kit上的接口与pcDuino上接口一一对应,分别为:
         VCC of LED Matrix kit is connected to VCCof pcDuino.
       GND of LED Matrix kit is connected to GNDof pcDuino.
      CLK of LED Matrix kit is connected to D8 ofpcDuino.
      CS of LED Matrix kit is connected to D9 ofpcDuino.
      DIN of LED Matrix kit is connected to D10of pcDuino.
(2)在arduino IDE中输入代码:
#include "core.h"
unsigned char i;
unsigned char j;
/*端口定义*/
intMax7219_pinCLK = 8;
intMax7219_pinCS = 9;
intMax7219_pinDIN = 10;

unsigned char disp1[38][8] =
{
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//0
{0x10,0x30,0x50,0x10,0x10,0x10,0x10,0x10},//1
{0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E},//2
{0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0},//3
{0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8},//4
{0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0},//5
{0x3C,0x20,0x20,0x3C,0x24,0x24,0x3C,0x0},//6
{0x3E,0x22,0x4,0x8,0x8,0x8,0x8,0x8},//7
{0x0,0x3E,0x22,0x22,0x3E,0x22,0x22,0x3E},//8
{0x3E,0x22,0x22,0x3E,0x2,0x2,0x2,0x3E},//9
{0x8,0x14,0x22,0x3E,0x22,0x22,0x22,0x22},//A
{0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C,0x0},//B
{0x3C,0x40,0x40,0x40,0x40,0x40,0x3C,0x0},//C
{0x7C,0x42,0x42,0x42,0x42,0x42,0x7C,0x0},//D
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C},//E
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40},//F
{0x3C,0x40,0x40,0x40,0x40,0x44,0x44,0x3C},//G
{0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44},//H
{0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C},//I
{0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30},//J
{0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24},//K
{0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C},//L
{0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81},//M
{0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0},//N
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//O
{0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20},//P
{0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D},//Q
{0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21},//R
{0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C},//S
{0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8},//T
{0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C},//U
{0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18},//V
{0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0},//W
{0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41},//X
{0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8},//Y
{0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F},//Z
{0x8,0x7F,0x49,0x49,0x7F,0x8,0x8,0x8},//
{0xFE,0xBA,0x92,0xBA,0x92,0x9A,0xBA,0xFE},//
};

void Write_Max7219_byte(unsigned char DATA)
{
unsigned char i;
digitalWrite(Max7219_pinCS,LOW);
for(i=8;i>=1;i--)
{
digitalWrite(Max7219_pinCLK,LOW);
if((DATA&0x80)==0x80)  digitalWrite(Max7219_pinDIN,HIGH);//提取Data的高一位数据
else                                            digitalWrite(Max7219_pinDIN,LOW);
DATA= DATA<<1;
digitalWrite(Max7219_pinCLK,HIGH);
}
}

void Write_Max7219(unsigned charaddress,unsigned char dat)
{
digitalWrite(Max7219_pinCS,LOW);
Write_Max7219_byte(address);           //写入地址,即数码管编号
Write_Max7219_byte(dat);               //写入数据,即数码管显示数字
digitalWrite(Max7219_pinCS,HIGH);
}

void Init_MAX7219(void)
{
Write_Max7219(0x09, 0x00);       //译码方式:BCD
Write_Max7219(0x0a, 0x03);       //亮度
Write_Max7219(0x0b, 0x07);       //扫描界限;8个数码管显示
Write_Max7219(0x0c, 0x01);       //掉电模式:0,普通模式:1
Write_Max7219(0x0f, 0x00);       //显示测试:1;测试结束,正常显示:0
}

void setup()
{
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
digitalWrite(11,LOW);
digitalWrite(12,HIGH);
pinMode(Max7219_pinCLK,OUTPUT);
pinMode(Max7219_pinCS,OUTPUT);
pinMode(Max7219_pinDIN,OUTPUT);
delay(50);
Init_MAX7219();
}

void loop()
{
for(j=0;j<38;j++)
{
for(i=1;i<9;i++)
Write_Max7219(i,disp1[j][i-1]);
delay(500);
}
}
4、试验结果:




24D4C5049C2969035DD1B2A10EC2169E.jpg
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-29 19:26 , Processed in 0.078381 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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