新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > CH451驅(qū)動(dòng)LED數(shù)碼管單片機(jī)C語言實(shí)例程序

CH451驅(qū)動(dòng)LED數(shù)碼管單片機(jī)C語言實(shí)例程序

作者: 時(shí)間:2016-11-13 來源:網(wǎng)絡(luò) 收藏
CH451能夠一次性驅(qū)動(dòng)8位數(shù)碼管,與單片機(jī)串行通信。支持?jǐn)?shù)碼管的左移,右移,左循環(huán),右循環(huán),獨(dú)立閃爍,16級(jí)亮度控制等功能。是單片機(jī)控制多個(gè)數(shù)碼管的得力助手,現(xiàn)將MEGA16單片機(jī)(MEGA16是AVR單片機(jī),改程序稍加修改可以應(yīng)用到8051單片機(jī),PIC單片機(jī),MSP430單片機(jī)上)驅(qū)動(dòng)CH451的程序發(fā)布,希望能有所用。CH451的詳細(xì)資料可去官方網(wǎng)站下載。

本文引用地址:http://m.butianyuan.cn/article/201611/316267.htm

//包含CH451所需頭文件

#i nclude

#i nclude

/*------宏定義------*/

#define uchar unsigned char

#define uint unsigned int

#define ch451din PORTB

#define ch451dclk0 PORTB&=~BIT(PB1)

#define ch451dclk1 PORTB|=BIT(PB1)

#define ch451load0 PORTB&=~BIT(PB2)

#define ch451load1 PORTB|=BIT(PB2)

#define ch451dout0 PORTB&=~BIT(PB3)

#define ch451dout1 PORTB|=BIT(PB3)

//CH451復(fù)位

#define CH451_RESET 0x0201

//設(shè)置移動(dòng)方式-作移、左循、右移、右循

#define CH451_LEFTMOV 0x0300

#define CH451_LEFTCYC 0x0301

#define CH451_RIGHTMOV 0x0302

#define CH451_RIGHTCYC 0x0303

//設(shè)置BCD譯碼方式

#define CH451_BCD 0x0580

//設(shè)置數(shù)碼管閃爍控制

#define CH451_TWINKLE 0x0600

//數(shù)碼管各位顯示

#define CH451_DIG0 0x0800

#define CH451_DIG1 0x0900

#define CH451_DIG2 0x0a00

#define CH451_DIG3 0x0b00

#define CH451_DIG4 0x0c00

#define CH451_DIG5 0x0d00

#define CH451_DIG6 0x0e00

#define CH451_DIG7 0x0f00

//CH451初始化

void ch451_init()

{

ch451din=0;

ch451din=1;

}

//輸出命令子程序

//定義一個(gè)無符號(hào)整型變量存儲(chǔ)12字節(jié)的命令字

void ch451_write(uint command)

{

uchar i;

ch451load0;

for(i=0;i<12;i++)

{

ch451din=command&1;

ch451dclk0;

ch451dclk1;

command>>=1;

}

ch451load1;

}

//CH451端口初始化

void port_init(void)

{

PORTA = 0x00;

DDRA = 0x00;

PORTB = 0x07;

DDRB = 0x07;

PORTC = 0x00;

DDRC = 0x00;

PORTD = 0x00;

DDRD = 0x00;

}

//單片機(jī)C語言主函數(shù)

void main(void)

{

port_init();

ch451_init();

ch451_write(CH451_RESET);

ch451_write(0x401);

ch451_write(0x580);

ch451_write(0x600);

ch451_write(CH451_DIG0|0x08);

while(1)

{}

}



關(guān)鍵詞: CH451LED數(shù)碼管單片

評(píng)論


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

關(guān)閉