此程序可以实现如下功能:间断.上移.下移.上拉.下拉等! 硬件说明:行部分采用驿码器74LS154+PNP三极管驱动,74LS154L输入部分接P0口的低四位,即P0.0——3 4个端口,列部分采用74HC595移位锁存器驱动+30R限流电阻,列输出口接P1.4脚,移位时钟接P1.5脚,锁存时钟接P1.5脚! #include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar hang,lei,cen,num,shu1,shu2,shu3,shu4,shu5,shu6,shu7,shu8;
sbit sdata=P1^4; //输出定义
sbit clk=P1^5;//移位时钟定义
sbit sclk=P1^6;//锁存定义
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,0x08,0x01,0xFC,0x7D,0x08,0x05,0x08,0x45,0xF8,0x29,0x08,0x29,0x08,0x11,0xF8,
0x11,0x44,0x29,0x4C,0x29,0x30,0x45,0x20,0x85,0x10,0x01,0x4E,0x01,0x84,0x01,0x00,
0x08,0x20,0x08,0x28,0x7F,0xFC,0x08,0x20,0x09,0x20,0x01,0x04,0xFF,0xFE,0x01,0x00,
0x01,0x10,0x1F,0xF8,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,
0x04,0x00,0x25,0xF8,0x25,0x08,0x24,0x90,0x24,0x90,0x24,0x60,0x24,0x20,0x24,0xD0,
0x27,0x0E,0x05,0x04,0x01,0x10,0x3F,0xF8,0x01,0x00,0x01,0x04,0xFF,0xFE,0x00,0x00,
0x08,0x04,0xFD,0xFE,0x09,0x04,0x09,0x04,0x09,0xFC,0x79,0x24,0x48,0x20,0x43,0xFE,
0x42,0x22,0x7A,0x22,0x0B,0xFE,0x0A,0x22,0x08,0x20,0x88,0x24,0x53,0xFE,0x20,0x02,
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
}; //数组一
uchar code table1[]={
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,
0x08,0x04,0xFD,0xFE,0x09,0x04,0x09,0x04,0x09,0xFC,0x79,0x24,0x48,0x20,0x43,0xFE,
0x42,0x22,0x7A,0x22,0x0B,0xFE,0x0A,0x22,0x08,0x20,0x88,0x24,0x53,0xFE,0x20,0x02,
0x04,0x00,0x25,0xF8,0x25,0x08,0x24,0x90,0x24,0x90,0x24,0x60,0x24,0x20,0x24,0xD0,
0x27,0x0E,0x05,0x04,0x01,0x10,0x3F,0xF8,0x01,0x00,0x01,0x04,0xFF,0xFE,0x00,0x00,
0x08,0x20,0x08,0x28,0x7F,0xFC,0x08,0x20,0x09,0x20,0x01,0x04,0xFF,0xFE,0x01,0x00,
0x01,0x10,0x1F,0xF8,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,
0x00,0x08,0x01,0xFC,0x7D,0x08,0x05,0x08,0x45,0xF8,0x29,0x08,0x29,0x08,0x11,0xF8,
0x11,0x44,0x29,0x4C,0x29,0x30,0x45,0x20,0x85,0x10,0x01,0x4E,0x01,0x84,0x01,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 yi()
{
uchar shu;//局部变量定义
for(shu=8;shu>0;shu--)//循环8次,将数移出
{
if(hang&0x01==1)//与01与一下,以判断移出的结果
sdata=1; //输出为1
else//如果hang与完后不为1,就执行下一句
sdata=0;//输出为0
clk=1;//上升沿
clk=0; //下降
clk=1;//上升
hang>>=1;//将hang这个右移一位
}
} /**********显示子函数*********/
void xian()
{
lei=0; //将列清0
num=cen;//将暂存数给num
for(shu2=16;shu2>0;shu2--) //循环16次,以得到一个整体的字
{
hang=~table[num];//扫左半屏
yi();//送数
num++; //计数器加1
hang=~table[num];//扫右半屏
yi(); //送数
num++;//计数器加1
sclk=1; //锁存起来
sclk=0;//下降沿
sclk=1; //上升沿
P0=lei; //将列数给P0口
lei++; //加1后可以紧接着扫下一行
delay(15);//延时一下
}
}
/**********显示子函数1*********/
//以下子程序和上面完全一样,不同的是表不同而已
void xian1()
{
lei=0;
num=cen;
for(shu2=16;shu2>0;shu2--)
{
hang=~table1[num];
yi();
num++;
hang=~table1[num];//使用得是TABLE1表
yi();
num++;
sclk=1;
sclk=0;
sclk=1;
P0=lei;
lei++;
delay(15);
}
}
/**********间断显示子函数*********/
void jian()
{
num=0;//计数器清0
cen=0;//暂存器清0
for(shu3=6;shu3>0;shu3--)//循环6次,即要显示6个字
{
for(shu1=40;shu1>0;shu1--)//一个字间隔的时间
xian(); //调用显示子程序
cen=num;//将数给暂存器存起来,以便记住num的数是多少
}
num=0;//计数器清0
cen=0;//暂存器清0
}
/**********上移子函数*********/
void shangyi()
{
num=0;//计数器清0
cen=0;//暂存器清0
for(shu3=60;shu3>0;shu3--)// //循环60次
{
for(shu1=5;shu1>0;shu1--)// 一个字间隔的时间
xian();//调用显示子程序
cen=cen+2;//将暂存器数加2,形成上移
}
num=0;
cen=0;
}
/**********下移子函数*********/
void xiayi()
{
num=0;
cen=160;//先给数暂存
for(shu3=80;shu3>0;shu3--) //循环次数
{
for(shu1=5;shu1>0;shu1--)// 一个字间隔的时间
xian1(); //调用显示子程序
cen=cen-2;//将暂存器数减2,形成下移
}
num=0;//清0
cen=160; //重新赋值
}
/**********上拉幕子函数*********/
void shangla()
{
num=0;//清0
cen=0;//清0
for(shu3=6;shu3>0;shu3--)//6个字循环6次
{
for(shu7=16;shu7>0;shu7--)//一个字扫描需要16次
{
for(shu1=1;shu1>0;shu1--)//一个字间隔时间
xian(); //调用显示
cen=cen+2;//加2,形成上移
}
for(shu7=80;shu7>0;shu7--) //一个字显示完了,停下来,即形成拉幕,此句是重点
xian();//调用显示子程序
}
num=0;//清0
cen=0;//清0
}
/**********下拉幕子函数*********/
void xiala()
{
num=0;
cen=160;
for(shu3=5;shu3>0;shu3--)
{
for(shu6=16;shu6>0;shu6--)
{
for(shu1=1;shu1>0;shu1--)
xian1();
cen=cen-2;
}
for(shu7=80;shu7>0;shu7--)
xian1();
}
num=0;
cen=160;
}
/**********主函数*********/
void main()
{
while(1)
{
for(shu8=2;shu8>0;shu8--)//两次
jian(); //调用间断显示子程序
for(shu8=2;shu8>0;shu8--)
shangyi(); //调用上移显示子程序
for(shu8=2;shu8>0;shu8--)
xiayi(); //调用下移显示子程序
for(shu8=2;shu8>0;shu8--)
shangla(); //调用上拉显示子程序
for(shu8=2;shu8>0;shu8--)
xiala(); //调用下拉显示子程序
}
}
|