硬件设计
(末尾附文件)
该方案支持左右滚动,两个按键,其中之一支持暂停/启动,另外一个支持换方向。
原理图:
仿真图:
程序设计
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define data1 P0
#define data2 P2
sbit s1=P3^6;
sbit s2=P3^7;
bit fangxiang;
uint alt=0,net=0,sl=128;
bit mode;
uchar code tab[]={
//
0x20,0x08,0x24,0x10,0x22,0x60,0x21,0x80,0x26,0x41,0x39,0x32,0x02,0x04,0x0C,0x18,
0xF0,0x60,0x13,0x80,0x10,0x60,0x10,0x18,0x14,0x04,0x18,0x02,0x00,0x01,0x00,0x00,/*"欢",2*/
0x02,0x00,0x02,0x02,0x42,0x04,0x33,0xF8,0x00,0x04,0x00,0x02,0x3F,0xF2,0x20,0x22,
0x40,0x42,0x00,0x02,0x3F,0xFE,0x20,0x42,0x20,0x22,0x3F,0xC2,0x00,0x02,0x00,0x00,/*"迎",3*/
0x00,0x80,0x01,0x00,0x06,0x00,0x1F,0xFF,0xE0,0x00,0x02,0x08,0x04,0x30,0x18,0xC0,
0xF0,0x02,0x10,0x01,0x13,0xFE,0x10,0x00,0x10,0x80,0x14,0x60,0x18,0x18,0x00,0x00,/*"你",4*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",5*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",6*/
};
void delay(uint z) //延时子函数
{
uchar x;
for(;z>0;z--)
for(x=110;x>0;x--);
}
void xianshi() //显示
{
uchar aa,i;
for(i=0;i<16;i++)
{
P1=i; //列扫描
data1=tab[net+aa]; //取出上8行数据输出
aa++;
data2=tab[net+aa]; //取出下8行数据输出
aa++;
delay(5); //延时
data1=0; //清屏
data2=0; //清屏
P1=0x00; //消除余辉
if(aa>30) aa=0; //字模地址
}
}
void main() //主函数
{
ET1=1; //使能定时器0
EA=1; //开启总中断
TR1=1; //开始计数
while(1) //无限循环
{
xianshi(); //显示
if(s1==0) //检测按键
{
delay(30); //延时消抖
TR1=~TR1; //按下暂停 ,暂按继续
while(!s1)xianshi();
delay(30);
}
if(s2==0) //检测按键
{
delay(30); //延时消抖
fangxiang=~fangxiang; //方向取反
while(!s2)xianshi();
delay(30);
}
}
}
void timer1() interrupt 3
{
alt++;
if(alt==10) //到一定的时间加以实现左移
{
alt=0;
if(fangxiang==0) //如果是正向 正向移动
{
net=net+2;
if(net>sl) //字移动数量
net=0;
.
文件仅供参考:
链接:https://pan.baidu.com/s/1oWzSEVmQzs9xctBMqX0f9Q
提取码:xm55
.