新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 51單片機驅(qū)動點陣16*16左移

51單片機驅(qū)動點陣16*16左移

作者: 時間:2016-11-29 來源:網(wǎng)絡(luò) 收藏
這個點陣左移,曾經(jīng)讓我......如今在朋友指導(dǎo)下.........主要部分在紅色部分,請大家理解那里就行了!會了也沒有什么!硬件:行采用74HC154+S8550,列采用74HC595

本文引用地址:http://2s4d.com/article/201611/323402.htm

#include
#define uchar unsigned char
#define uint unsigned int
#define LINE P0//定義行線IO口,即74HC154控制端
#define shudu 20//字移動的速度
sbit DATA=P1^4;//74HC595數(shù)據(jù)端
sbit CLK=P1^5;//74HC595移位脈沖端
sbit CLKR=P1^6;//74HC595數(shù)據(jù)鎖存端
uchar move;//移動幾位變量
uchar line;//行變量
uint word;//字節(jié)變量
uchar BUF[4];//4組緩存數(shù)組以便動態(tài)更改數(shù)據(jù)
uchar code table[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x3F,0xF8,0x04,0x10,0x04,0x14,0xFF,0xFE,0x04,0x10,0x04,0x10,
0x3F,0xF0,0x04,0x10,0x04,0x00,0x08,0x00,0x08,0x00,0x10,0x00,0x20,0x00,0x40,0x00,
0x01,0x00,0x01,0x08,0x7F,0xFC,0x01,0x00,0x3F,0xF8,0x01,0x00,0xFF,0xFE,0x00,0x10,
0x1F,0xF8,0x10,0x10,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0x10,0x50,0x10,0x20,
0x01,0x10,0xFF,0x90,0x14,0x50,0x14,0x7C,0x7F,0x50,0x55,0x90,0x55,0x10,0x57,0xFE,
0x61,0x04,0x41,0x7E,0x41,0x44,0x7F,0x44,0x41,0x44,0x41,0x44,0x7F,0x7C,0x41,0x44,
0x00,0x78,0x3F,0x80,0x11,0x10,0x09,0x20,0x7F,0xFE,0x42,0x02,0x82,0x04,0x7F,0xF8,
0x04,0x00,0x07,0xF0,0x0A,0x20,0x09,0x40,0x10,0x80,0x11,0x60,0x22,0x1C,0x0C,0x08,
0x04,0x40,0x04,0x44,0xFF,0xFE,0x04,0x40,0x08,0x7C,0x09,0x44,0x7F,0xC4,0x08,0x7C,
0x0A,0x44,0x3F,0x44,0x22,0x7C,0x22,0x44,0x22,0x44,0x3E,0x44,0x22,0x94,0x01,0x08,
0x08,0x20,0x08,0x24,0xFF,0xFE,0x08,0x20,0x01,0x08,0x3F,0xFC,0x20,0x08,0x20,0x08,
0x3F,0xF8,0x20,0x08,0x20,0x00,0x20,0x00,0x20,0x00,0x40,0x00,0x40,0x00,0x80,0x00,
0x08,0x10,0x08,0x10,0x08,0x10,0x10,0x20,0x10,0x20,0x22,0x44,0x7E,0xFC,0x04,0x08,
0x08,0x10,0x10,0x20,0x20,0x40,0x7E,0xFC,0x00,0x00,0x00,0x04,0xFF,0xFE,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};//字模數(shù)組
/********************************/
/**74HC595移位寄存器送數(shù)子函數(shù)***/
/********************************/
void song(uchar z)//帶參數(shù)函數(shù)
{
uchar num,hang;//定義變量
hang=z;//將形參給變量
for(num=0;num<8;num++)//移動8次將數(shù)據(jù)發(fā)送完畢
{
if(hang&0x01==1)//將高7位屏蔽掉,保留最低位判斷
DATA=1;//為1就將74HC595數(shù)據(jù)端置1
else
DATA=0;//否則給0
CLK=0;//上升沿送走數(shù)據(jù)
CLK=1;//高電平形成上升沿
hang>>=1;//將數(shù)移走一位
}
}
/********************************/
/*裝一線數(shù)據(jù)子函數(shù)(即一行數(shù)據(jù))*/
/********************************/
void yixian()
{
uchar s;
for(s=0;s<2;s++)/*循環(huán)2次,得到第1個字(代碼存在數(shù)組1與2中)
與第2個字(代碼存在數(shù)組2與3中)的某一行數(shù)值*/
{
BUF[s*2]=table[word+(32*s)+(line*2)];//左半屏代碼,line表示行數(shù),word表示字?jǐn)?shù)
BUF[s*2+1]=table[word+(32*s+1)+(line*2)];//右半屏代碼
}
}
/********************************/
/*將一行數(shù)據(jù)轉(zhuǎn)換出來,然后顯示*/
/********************************/
void yipai()
{
uchar temp,yi;
if(move<8)//處理移動次數(shù)小于8次的部分
{
yi=move;
temp=(BUF[1]<>(8-yi));/*將第1個字的右半屏數(shù)左移yi次,
然后或上第2個字左半屏的8-yi次數(shù),注此句是處理右半屏的數(shù)*/
song(~temp);//發(fā)送給74HC595
temp=(BUF[0]<>(8-yi));/*將第1個字的左半屏數(shù)左移yi次,
然后或上第1個字右半屏的8-yi次數(shù),注此句是處理左半屏的數(shù)*/
song(~temp);//發(fā)送給74HC595
}
else//處理移動次數(shù)小于8次以外的部分
{
yi=move-8;
temp=(BUF[2]<>(8-yi));//原理同上
song(~temp);//發(fā)送給74HC595
temp=(BUF[1]<>(8-yi));//原理同上
song(~temp);//發(fā)送給74HC595
}
}
void zou()
{
uchar i;
while(word<256)
{
for(move=0;move<16;move++)//要移多少位?
{
for(i=0;i{
for(line=0;line<16;line++)//掃描16次,即完成一個字的移動
{
yixian();//調(diào)用一線子程序
yipai();//調(diào)用數(shù)據(jù)轉(zhuǎn)換子程序
LINE=line;//打開行線,即174HC154行線端
CLKR=1;//在74HC595處鎖存起來
CLKR=0;
CLKR=1;
}
}
}
word=word+32;//一個字顯示完了,就顯示下一個字
}
word=0;//清0重新開始
}

/********************************/
/************主程序*************/
/********************************/
void main()
{

while(1)
{
zou();
}
}

視頻祥見:http://www.tudou.com/programs/view/D0SCJyO4RBQ/



關(guān)鍵詞: 51單片機驅(qū)動點

評論


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

關(guān)閉