Arduino下實現LED Martix級聯

前面介紹過在pcDuino上運行LED Matrix Kit,這個套件中有MAX7219芯片,它是串行輸入/輸出共陰極數碼管顯示驅動芯片,它的操做很簡單,MCU只需經過模擬SPI三線接口就能夠將相關的指令寫入MAX7219的內部指令和數據寄存器,並且它還支持多片7219串聯,便可以經過3根線控制更多的數碼管顯示git

圖片1

封裝引腳圖: oop

DS1QWFL~{D$IQEGR{YFX3GV

在Arduino下級聯三片LED Matrix 點陣屏 測試

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

圖片2

圖片3

圖片5

每片LED顯示頻率在驅動程序裏能夠設置,程序代碼以下 spa

#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++;

}

}
相關文章
相關標籤/搜索