Arduino下实现LED Martix级联

前面介绍过在pcDuino上运行LED Matrix Kit,这个套件中有MAX7219芯片,它是串行输入/输出共阴极数码管显示驱动芯片,它的操作很简单,MCU只需通过模拟SPI三线接口就可以将相关的指令写入MAX7219的内部指令和数据寄存器,而且它还支持多片7219串联,即可以通过3根线控制更多的数码管显示

图片1

封装引脚图:

DS1QWFL~{D$IQEGR{YFX3GV

在Arduino下级联三片LED Matrix 点阵屏

CLK   –> arduino D8
CS    –> arduino D9
DIN   –> arduino D10

图片2

图片3

图片5

每片LED显示频率在驱动程序里可以设置,程序代码如下

#define uchar unsigned char

int Max7219_CLK = 8;

int Max7219_CS = 9;

int Max7219_DIN = 10;

uchar num[16][8] = {

{0x1C,0x22,0x22,0x22,0x22,0x22,0x22,0x1C},//0

{0x08,0x18,0x28,0x08,0x08,0x08,0x08,0x3E},//1

{0x3E,0x02,0x02,0x3E,0x20,0x20,0x20,0x3E},//2

{0x3E,0x02,0x02,0x3E,0x02,0x02,0x02,0x3E},//3

{0x0C,0x14,0x24,0x3E,0x04,0x04,0x04,0x04},//4

{0x3E,0x20,0x20,0x3E,0x02,0x02,0x02,0x3E},//5

{0x3E,0x20,0x20,0x3E,0x22,0x22,0x22,0x3E},//6

{0x3E,0x02,0x04,0x08,0x08,0x08,0x08,0x08},//7

{0x1C,0x22,0x22,0x1C,0x22,0x22,0x22,0x1C},//8

{0x3E,0x22,0x22,0x3E,0x02,0x02,0x02,0x3E},//9

{0x08,0x14,0x22,0x22,0x3E,0x22,0x22,0x22},//A

{0x3C,0x22,0x22,0x3C,0x22,0x22,0x22,0x3C},//B

{0x1C,0x22,0x20,0x20,0x20,0x20,0x22,0x1C},//C

{0x38,0x24,0x22,0x22,0x22,0x22,0x24,0x38},//D

{0x3E,0x20,0x20,0x3E,0x20,0x20,0x20,0x3E},//E

{0x3E,0x20,0x20,0x3E,0x20,0x20,0x20,0x20},//F

};

void write_byte(uchar DATA)

{

uchar i;

digitalWrite(Max7219_CS,LOW);

for(i=8;i>=1;i--)

{

digitalWrite(Max7219_CLK,LOW);

digitalWrite(Max7219_DIN,DATA&0x80);//提取Data的高一位数据 DATA = DATA<<1;

digitalWrite(Max7219_CLK,HIGH);

}

}

void write_first(uchar address,uchar dat)

{

digitalWrite(Max7219_CS,LOW);

write_byte(address);           //写入地址,即数码管编号 write_byte(dat);               //写入数据,即数码管显示数字  digitalWrite(Max7219_CS,HIGH);

}

void write_second(char address,char dat)

{

digitalWrite(Max7219_CS,LOW);

write_byte(address);           //写入地址,即数码管编号 write_byte(dat);               //写入数据,即数码管显示数字  write_byte(0);

write_byte(0);

digitalWrite(Max7219_CS,HIGH);

}

void write_third(char address,char dat)

{

digitalWrite(Max7219_CS,LOW);

write_byte(address);           //写入地址,即数码管编号 write_byte(dat);               //写入数据,即数码管显示数字  write_byte(0);

write_byte(0);

write_byte(0);

write_byte(0);

digitalWrite(Max7219_CS,HIGH);

}

void max7219_init(void)

{

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

void setup()

{

pinMode(Max7219_CLK,OUTPUT);

pinMode(Max7219_CS,OUTPUT);

pinMode(Max7219_DIN,OUTPUT);

max7219_init();

}

void loop()

{

uchar i,count;

while(1)

{

for(i=1;i<9;i++)

{

write_first(i,num[count/100][i-1]);

write_second(i,num[count%100/10][i-1]);

write_third(i,num[count%10][i-1]);

}

delay(200);

count++;

}

}

你可能感兴趣的:(liunx,arduino,pcduino,minipc)