这个点阵左移,曾经让我......如今在朋友指导下.........主要部分在红色部分,请大家理解那里就行了!会了也没有什么!硬件:行采用74HC154+S8550,列采用74HC595!
#include<reg52.h>
#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;//行变量
uint word;//字节变量
uchar BUF[4];//4组缓存数组以便动态更改数据
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
};//字模数组
/********************************/
/**74HC595移位寄存器送数子函数***/
/********************************/
void song(uchar z)//带参数函数
{
uchar num,hang;//定义变量
hang=z;//将形参给变量
for(num=0;num<8;num++)//移动8次将数据发送完毕
{
if(hang&0x01==1)//将高7位屏蔽掉,保留最低位判断
DATA=1;//为1就将74HC595数据端置1
else
DATA=0;//否则给0
CLK=0;//上升沿送走数据
CLK=1;//高电平形成上升沿
hang>>=1;//将数移走一位
}
}
/********************************/
/*装一线数据子函数(即一行数据)*/
/********************************/
void yixian()
{
uchar s;
for(s=0;s<2;s++)/*循环2次,得到第1个字(代码存在数组1与2中)
与第2个字(代码存在数组2与3中)的某一行数值*/
{
BUF[s*2]=table[word+(32*s)+(line*2)];//左半屏代码,line表示行数,word表示字数
BUF[s*2+1]=table[word+(32*s+1)+(line*2)];//右半屏代码
}
}
/********************************/
/*将一行数据转换出来,然后显示*/
/********************************/
void yipai()
{
uchar temp,yi;
if(move<8)//处理移动次数小于8次的部分
{
yi=move;
temp=(BUF[1]<<yi)|(BUF[2]>>(8-yi));/*将第1个字的右半屏数左移yi次,
然后或上第2个字左半屏的8-yi次数,注此句是处理右半屏的数*/
song(~temp);//发送给74HC595
temp=(BUF[0]<<yi)|(BUF[1]>>(8-yi));/*将第1个字的左半屏数左移yi次,
然后或上第1个字右半屏的8-yi次数,注此句是处理左半屏的数*/
song(~temp);//发送给74HC595
}
else//处理移动次数小于8次以外的部分
{
yi=move-8;
temp=(BUF[2]<<yi)|(BUF[3]>>(8-yi));//原理同上
song(~temp);//发送给74HC595
temp=(BUF[1]<<yi)|(BUF[2]>>(8-yi));//原理同上
song(~temp);//发送给74HC595
}
}
void zou()
{
uchar i;
while(word<256)
{
for(move=0;move<16;move++)//要移多少位?
{
for(i=0;i<shudu;i++)//一字移动的速度
{
for(line=0;line<16;line++)//扫描16次,即完成一个字的移动
{
yixian();//调用一线子程序
yipai();//调用数据转换子程序
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/