51單片機驅動點陣16*16間斷顯示C程序
#include
#define uchar unsigned char
#define uint unsigned int
#define LINE P0//定義行線IO口,即74HC154控制端
#define shudu 20//字移動的速度
sbit DATA=P1^4;//74HC595數據端
sbit CLK=P1^5;//74HC595移位脈沖端
sbit CLKR=P1^6;//74HC595數據鎖存端
uchar move;//移動幾位變量
uchar line;//行變量
uchar word;//字節(jié)變量
uchar ji;//字節(jié)變量
ucharcode 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
};
void delay(uchar z)
{
uchar x,y;
for(x=8;x>0;x--)
for(y=z;y>0;y--);
}
void song(uchar z)//帶參數函數
{
uchar num,hang;//定義變量
hang=z;//將形參給變量
for(num=0;num<8;num++)//移動8次將數據發(fā)送完畢
{
if(hang&0x01==1)//將高7位屏蔽掉,保留最低位判斷
DATA=1;//為1就將74HC595數據端置1
else
DATA=0;//否則給0
CLK=0;//上升沿送走數據
CLK=1;//高電平形成上升沿
hang>>=1;//將數移走一位
}
}
void jian()
{
for(move=30;move>0;move--)
{
ji=word;
for(line=0;line<16;line++)
{
song(~table[ji*2+1]);
song(~table[ji*2]);
ji++;
CLKR=1;//在74HC595處鎖存起來
CLKR=0;
CLKR=1;
LINE=line;
delay(17);
}
}
word=ji;
if(word>=128)//7個字
{
ji=0;
word=0;
}
}
void main()
{
while(1)
{
jian();
}
}
視頻祥見:http://www.tudou.com/programs/view/D0SCJyO4RBQ/
評論