• Increase font size
  • Default font size
  • Decrease font size
  • default color
  • cyan color
  • red color

Arduino.TW樂園

Member Area
Controlling a Led matrix or 7-segment displays with the MAX7219 or the MAX7221
站長Blog文章單元 - Arduino擴充IO (PWM IC, LED Driver IC, Digital/Analo)
作者是 Administrator   
週五, 28 五月 2010 17:25

光使用單晶片的IO沒有辦法驅動需要大量IO環境的LED顯示,解決的方式是利用掃描的方式來達成,所謂的掃描指利用快速的ON/OFF方式來驅動LED。例如: 共陰極七段顯示器,一顆七段顯示器有八組。利用一顆MAX7219 MAX7221可以以三條線來控制8科七段顯示器,即64個IO。首先,你需要先下載晶片的使用手冊你可以從google搜尋打maxim 7219 datasheet或是點選下方連結下載。Reference: Controlling a Led matrix with the MAX7219 and MAX7221. An extensive collection of articles, schematics and software libraries.

電路圖

  • Pin 12 連接到MAX72xx晶片的 DATA IN-pin 1
  • Pin 11 連接到MAX72xx片的 CLK-pin 13
  • Pin 10 連接到MAX72xx片的 LOAD(/CS)-pin 12

基本線路與Arduino搭配
完整電路圖 (另 開視窗)


電路中需要兩個電容10uF和100nF(104),電阻的部分是控制MAXIM晶片輸出的電流和電壓,所以你必須參考所要驅動的LED來更改電阻的大小。下方列出電阻對應的表格:
挑選電容
104=10*10exp4=100000pf=100nF=0.1uf
電容單位換算
1: 10-15 或 f (Femto 毫微微)
2: 10-12 或 p (Pico 微微)
3: 10-9 或 n (Nano 毫微)
4: 10-6 或 μ (Micro 微)
5: 10-3 或 m (milli 毫)
6: 103 或 k (Kilo 千)
7: 106 或 M (Mega 百萬)
8: 109 或 G (Giga 十億)

 9: 1012 或 T (Tera 兆)

挑選RSet電阻(依據MAX7219 SPEC中的表格)
  Forward voltage
ISeg 1.5V 2.0V 2.5V 3.0V 3.5V
40mA 12.2kΩ 11.8kΩ 11.0kΩ 10.6kΩ 9.69kΩ
30mA 17.8kΩ 17.1kΩ 15.8kΩ 15.0kΩ 14.0kΩ
20mA 29.8kΩ 28.0kΩ 25.9kΩ 24.5kΩ 22.6kΩ
10mA 66.7kΩ 63.7kΩ 59.3kΩ 55.4kΩ 51.2kΩ

舉例來說,我有一顆8x8矩陣LED(共64顆),每一顆額定電流是40mA,電壓是3.1V,那麼選10.6K的電阻。但是手邊的電阻沒有相對的話,你可以使用歐姆定律,利用幾顆電阻來組合出你所需要的電阻總值。

R = r1*r2 / r1+r2  ;  10.6K ~= 10K + 0.6K = 10K 串聯 (1K並聯2K) =10.666666....KΩ


MAX7219MAX7221 我應該使用哪一顆?

  • MAX7221支援標準 SPI-protocol,並且針對高頻有特殊的設計不會干擾其他晶片。
  • 所以,以下兩種狀況你必須使用MAX7221
    • 使用SPI通訊控制
    • 裝置需要類比輸入或是附近的裝置必須避免高頻干擾,列如:電台(調頻調幅器)。

其他狀況,就只要使用MAX7219就可以了,相對的也比較便宜。 


 軟體 [下載]

測試電路:(七段顯示器依不同廠牌腳位有所差異)

 

測試程式碼:

#include "LedControl.h"
/*
 pin 12 is connected to the DataIn
 pin 11 is connected to the CLK
 pin 10 is connected to LOAD
 */
 LedControl lc=LedControl(12,11,10,1);
 //LedControl lc=LedControl(12,11,10,2); //如果有個位與十位數,兩顆七段顯示
 unsigned long delaytime=200;
 void setup() {
   lc.shutdown(0,false);
   lc.setIntensity(0,8);
   lc.clearDisplay(0);
 }
 void setDisplay(int which7219,int which7segments,char value){
	lc.setChar(which7219,which7segments,value,true);
	delay(delaytime);
}
void printNumber(int v) {
    int ones;
    int tens;
    int hundreds;
    boolean negative;	

    if(v < -999 || v > 999) 
       return;
    if(v<0) {
        negative=true;
        v=v*-1;
    }
    ones=v%10;
    v=v/10;
    tens=v%10;
    v=v/10;
    hundreds=v;			
    if(negative) {
       //print character '-' in the leftmost column	
       lc.setChar(0,3,'-',false);
    }
    else {
       //print a blank in the sign column
       lc.setChar(0,3,' ',false);
    }
    //Now print the number digit by digit
    lc.setDigit(0,2,(byte)hundreds,false);
    lc.setDigit(0,1,(byte)tens,false);
    lc.setDigit(0,0,(byte)ones,false);
}

void loop() {
	for(int x=0;x<99;x++){   
		printNumber(x);
	}
}
setDigit 參數說明
/* 
 * Display a (hexadecimal) digit on a 7-Segment Display
 * Params:
 * addr  address of the display
 * digit the position of the digit on the display (0..7)
 * value the value to be displayed. (0x00..0x0F)
 * dp    sets the decimal point.
 */
void setDigit(int addr, int digit, byte value, boolean dp);

效果:

控制矩陣LED

控制七段顯示器

 Reference [link][link][example]

 

 

 

==============

#include "LedControl.h"
/*
 pin 12 is connected to the DataIn
 pin 11 is connected to the CLK
 pin 10 is connected to LOAD
 */
 LedControl lc=LedControl(12,11,10,1);
 //LedControl lc=LedControl(12,11,10,2); //如果有個位與十位數,兩顆七段顯示
 unsigned long delaytime=200;
 void setup() {
   lc.shutdown(0,false);
   lc.setIntensity(0,8);
   lc.clearDisplay(0);
 }
 void setDisplay(int which7219,int which7segments,char value){
    lc.setChar(which7219,which7segments,value,true);
    delay(delaytime);
}
void printNumber(int v) {
    int ones;
    int tens;
    int hundreds;
    boolean negative;   

    if(v < -999 || v > 999)
       return;
    if(v<0) {
        negative=true;
        v=v*-1;
    }
    ones=v%10;
    v=v/10;
    tens=v%10;
    v=v/10;
    hundreds=v;           
    if(negative) {
       //print character '-' in the leftmost column   
       lc.setChar(0,3,'-',false);
    }
    else {
       //print a blank in the sign column
       lc.setChar(0,3,' ',false);
    }
    //Now print the number digit by digit
    lc.setDigit(0,2,(byte)hundreds,false);
    lc.setDigit(0,1,(byte)tens,false);
    lc.setDigit(0,0,(byte)ones,false);
}

void loop() {
    for(int x=0;x<99;x++){  
        printNumber(x);
    }
}


blog comments powered by Disqus
最近更新在 週日, 04 七月 2010 17:00
 

幫助我們推廣