新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > [C51代碼]MAX7219驅(qū)動(dòng)

[C51代碼]MAX7219驅(qū)動(dòng)

作者: 時(shí)間:2016-11-10 來(lái)源:網(wǎng)絡(luò) 收藏
/***************max7219.h****************/
#ifndef _max7219_h_
#define _max7219_h_
#include
#include "link.h"
/***************控制引腳定義****************/
sbit _7219_DIN = P2^0;
sbit _7219_CS = P2^1;
sbit _7219_CLK = P2^2;
/***************控制字定義****************/
#define _7219_NO_OP0x00 //Digit0~Digit7位于RAM的地址
#define _7219_DIG00x01
#define _7219_DIG10x02
#define _7219_DIG20x03
#define _7219_DIG30x04
#define _7219_DIG40x05
#define _7219_DIG50x06
#define _7219_DIG60x07
#define _7219_DIG70x08
#define _7219_DECODE0x09 //譯碼方式地址
#define _7219_INTENSITY0x0A //亮度寄存器地址
#define _7219_SCANLIMIT0x0B //掃描界限寄存器地址,用于設(shè)置外接數(shù)碼管個(gè)數(shù)
#define _7219_SHUTDOWN0x0C //停機(jī)寄存器地址,使其處于低功耗
#define _7219_DISPTEST0x0F //顯示測(cè)試寄存器地址,用于測(cè)試數(shù)碼管和MAX2719是否工作
//Decode Mode
#define _7219_DECODE_ALL0xff
#define _7219_DECODE_NONE0x00
// Intensity
#define _7219_INTENSITY_MIN0x01
#define _7219_INTENSITY_MAX0x0f
// Scanlimit
#define _7219_SCANLIMIT_70x07
#define _7219_SCANLIMIT_60x06
#define _7219_SCANLIMIT_50x05
#define _7219_SCANLIMIT_40x04
#define _7219_SCANLIMIT_30x03
#define _7219_SCANLIMIT_20x02
#define _7219_SCANLIMIT_10x01
#define _7219_SCANLIMIT_00x00
//Shutdown mode
#define _7219_SHUTDOWN_ON 0x01
#define _7219_SHUTDOWN_OFF 0x00
//Display test
#define _7219_DISPTEST_ON0x01
#define _7219_DISPTEST_OFF 0x00
//7219 CODE B
//BCD譯碼對(duì)應(yīng)的字符段位
#define _7219_00x00
#define _7219_10x01
#define _7219_20x02
#define _7219_30x03
#define _7219_40x04
#define _7219_50x05
#define _7219_60x06
#define _7219_70x07
#define _7219_80x08
#define _7219_90x09
#define _7219_E0x0B
#define _7219_H0x0C
#define _7219_L0x0D
#define _7219_P0x0E
#define _7219_BLANK0x0F
//7219 NO Code
#define _7219_SEG_DP7
#define _7219_SEG_A6
#define _7219_SEG_B5
#define _7219_SEG_C4
#define _7219_SEG_D3
#define _7219_SEG_E2
#define _7219_SEG_F1
#define _7219_SEG_G0
/***************函數(shù)聲明****************/
extern void Write_Max7219(uchar Addr, uchar Content);
extern void Init_Max7219();
#endif
/**************************max7219.c*******************************/
#include "max7219.h"
#include "link.h"
#include
/****************************************************************
*函數(shù)功能:寫入一個(gè)字節(jié)到max7219
*入口參數(shù):數(shù)據(jù)Content
*出口參數(shù):無(wú)
*****************************************************************/
void Write_Max7219_byte(unsigned char temp)
{
unsigned char i;
for (i=0;i<8;i++)
{
_7219_CLK=0;
_7219_DIN=(bit)(temp&0x80);
temp<<=1;
_7219_CLK=1;
}
}
/****************************************************************
*函數(shù)功能:在max7219指定的地址寫入一個(gè)字節(jié)的內(nèi)容
*入口參數(shù):要寫入數(shù)據(jù)的地址:Address
寫入數(shù)據(jù)的具體值:Content
*出口參數(shù):無(wú)
****************************************************************/
void Write_Max7219(unsigned char address,unsigned char dat)
{
_7219_CS=0;
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
_7219_CS=1;
}
/****************************************************************
*函數(shù)功能:配置max7219的基本參數(shù)
*入口參數(shù):無(wú)
*出口參數(shù):無(wú)
****************************************************************/
void Init_Max7219()
{
Write_Max7219(_7219_SHUTDOWN , _7219_SHUTDOWN_OFF);
Write_Max7219(_7219_INTENSITY, 0x05);
Write_Max7219(_7219_DECODE , _7219_DECODE_ALL);
Write_Max7219(_7219_DISPTEST , _7219_DISPTEST_OFF);
Write_Max7219(_7219_SHUTDOWN , _7219_SHUTDOWN_ON);
Write_Max7219(_7219_SCANLIMIT , _7219_SCANLIMIT_7);
}


關(guān)鍵詞: C51代碼MAX7219驅(qū)

評(píng)論


技術(shù)專區(qū)

關(guān)閉