#include<reg51.h>
#include<math.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=8*7;
bit mode;
uchar code tab[]={
// 天(0) 大(1) 仁(2) 爱(3) 电(4) 1(5) 电(6) 2(7)
0x10,0x52,0x54,0x78,0x58,0x54,0x12,0x10,/*"0",天*/
0x01,0x12,0x14,0x18,0xF8,0x14,0x12,0x01,/*"1",大*/
0x10,0x20,0x7F,0x84,0x14,0x14,0x14,0x04,/*"2",仁*/
0x10,0x28,0x44,0x22,0x22,0x44,0x28,0x10,/*"3"爱(心形)*/
0x00,0x7C,0x54,0xFF,0x55,0x7D,0x03,0x00,/*"4",电*/
0x00,0x00,0x21,0x41,0xFF,0x01,0x00,0x00,/*"5",1*/
0x00,0x7C,0x54,0xFF,0x55,0x7D,0x03,0x00,/*"6",电*/
0x00,0x22,0x46,0x4A,0x52,0x22,0x00,0x00,/*"7",2*/
};
void delay(uint z) //延时子函数
{
uchar x;
for(;z>0;z--)
for(x=110;x>0;x--);
}
void xianshi() //显示
{
uchar aa,i,num=2;
for(i=0;i<16;i++)
{
switch(i){
case 0:
num=1;
break;
case 1:
num=2;
break;
case 2:
num=4;
break;
case 3:
num=8;
break;
case 4:
num=16;
break;
case 5:
num=32;
break;
case 6:
num=64;
break;
case 7:
num=128;
break;
default :
num=0;
break;
}
P2=0xff-num; //列扫描
data1=tab[net+aa]; //取出上8行数据输出
aa++;
delay(5); //延时
data1=0; //清屏
P1=0x00; //消除余辉
if(aa>15) 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==30) //到一定的时间加以实现左移
{
alt=0;
if(fangxiang==0) //如果是正向 正向移动
{
net=net+2;
if(net>sl) //字移动数量
net=0;
}
else //否则反向移动
{
net=net-2;
if(net<2)
net=sl; //字移动数量
}
}
}
|