#include<reg51.h>//头文件
sbit shcp=P1^2;//数据输入时钟线 595的11脚
sbit stcp=P1^1;//输出存储器锁存时钟线 595的12脚
sbit ds=P1^0;//数据线 595的14脚
sbit s1=P3^1;//按下暂停再暂按继续
sbit s2=P3^2;//按下方向取反
bit fx;//方向切换
unsigned char alt;//数据移动定时时间
unsigned int net;//控制显示的字符
unsigned char zi=8;
unsigned int zong;//总字符 (所有的字数+1)*32 字数指的是汉字,字母、数字两个算一个数字
unsigned char code tab[]={
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,/*先送两个空字节用于缓冲*/
//老(0) 师(1) ,(2) 您(3) 辛(4) 苦(5) 了(6) !(7)
0x04,0x08,0x04,0x10,0x24,0x20,0x24,0x40,0x24,0xFC,0x24,0xA2,0xFD,0x22,0x26,0x22,
0x24,0x42,0x2C,0x42,0x14,0x42,0x24,0x82,0x44,0x1E,0x04,0x00,0x04,0x00,0x00,0x00,/*"老",0*/
0x00,0x00,0x3F,0xE1,0x00,0x02,0x00,0x0C,0xFF,0xF0,0x00,0x00,0x40,0x00,0x47,0xF8,
0x44,0x00,0x44,0x00,0x7F,0xFF,0x44,0x10,0x44,0x08,0x47,0xF0,0x40,0x00,0x00,0x00,/*"师",1*/
0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*",",2*/
0x04,0x02,0x08,0x0C,0x10,0x00,0x3F,0xEE,0xC4,0x01,0x08,0x81,0x11,0x11,0xE6,0x4D,
0x20,0x21,0x2F,0xC1,0x20,0x01,0x24,0x07,0x2A,0x00,0x31,0x88,0x00,0x06,0x00,0x00,/*"您",3*/
0x02,0x00,0x02,0x20,0x22,0x20,0x22,0x20,0x2A,0x20,0x26,0x20,0xA2,0x20,0x63,0xFF,
0x22,0x20,0x26,0x20,0x2A,0x20,0x22,0x20,0x22,0x20,0x02,0x20,0x02,0x00,0x00,0x00,/*"辛",4*/
0x21,0x00,0x21,0x00,0x21,0x00,0x21,0x3F,0xF9,0x22,0x21,0x22,0x21,0x22,0x2F,0xE2,
0x21,0x22,0x21,0x22,0xF9,0x22,0x21,0x3F,0x21,0x00,0x21,0x00,0x21,0x00,0x00,0x00,/*"苦",5*/
0x00,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x02,0x40,0x01,0x47,0xFE,
0x44,0x00,0x48,0x00,0x50,0x00,0x60,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"了",6*/
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xCC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"!",7*/
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,
};
unsigned char code tab1[]={
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,
//老(0) 师(1) ,(2) 您(3) 辛(4) 苦(5) 了(6) !(7)
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xCC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"!",7*/
0x00,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x02,0x40,0x01,0x47,0xFE,
0x44,0x00,0x48,0x00,0x50,0x00,0x60,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"了",6*/
0x21,0x00,0x21,0x00,0x21,0x00,0x21,0x3F,0xF9,0x22,0x21,0x22,0x21,0x22,0x2F,0xE2,
0x21,0x22,0x21,0x22,0xF9,0x22,0x21,0x3F,0x21,0x00,0x21,0x00,0x21,0x00,0x00,0x00,/*"苦",5*/
0x02,0x00,0x02,0x20,0x22,0x20,0x22,0x20,0x2A,0x20,0x26,0x20,0xA2,0x20,0x63,0xFF,
0x22,0x20,0x26,0x20,0x2A,0x20,0x22,0x20,0x22,0x20,0x02,0x20,0x02,0x00,0x00,0x00,/*"辛",4*/
0x04,0x02,0x08,0x0C,0x10,0x00,0x3F,0xEE,0xC4,0x01,0x08,0x81,0x11,0x11,0xE6,0x4D,
0x20,0x21,0x2F,0xC1,0x20,0x01,0x24,0x07,0x2A,0x00,0x31,0x88,0x00,0x06,0x00,0x00,/*"您",3*/
0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*",",2*/
0x00,0x00,0x3F,0xE1,0x00,0x02,0x00,0x0C,0xFF,0xF0,0x00,0x00,0x40,0x00,0x47,0xF8,
0x44,0x00,0x44,0x00,0x7F,0xFF,0x44,0x10,0x44,0x08,0x47,0xF0,0x40,0x00,0x00,0x00,/*"师",1*/
0x04,0x08,0x04,0x10,0x24,0x20,0x24,0x40,0x24,0xFC,0x24,0xA2,0xFD,0x22,0x26,0x22,
0x24,0x42,0x2C,0x42,0x14,0x42,0x24,0x82,0x44,0x1E,0x04,0x00,0x04,0x00,0x00,0x00,/*"老",0*/
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(unsigned int z)//延时子函数
{
unsigned char x;
for(;z>0;z--)
for(x=110;x>0;x--);
}
void writedata(unsigned char dat1,unsigned char dat2) //595显示子函数
{
unsigned char i;
//CY存储移位之后的数据 CY进位标志位,单片机内部的寄存器 移位之后的数据就存在CY里面
for(i=0;i<8;i++)//循环八次
{
dat1=dat1<<1;//数据左移11110001
ds=CY;//数据发送
shcp=1;//上升沿发生移位 上升沿时数据寄存器的数据锁存。
shcp=0;
}
for(i=0;i<8;i++)//循环八次
{
dat2=dat2<<1;//数据左移
ds=CY;//数据发送
shcp=1;//上升沿发生移位 上升沿时数据寄存器的数据锁存 。
shcp=0;
}
stcp=0;
stcp=1;//上升沿将数据送到输出锁存器
stcp=0;
}
void main() //主函数
{
char i,aa;
TMOD=0x01;//定时器0 模式1 16位定时模式
TH0=(65536-10000)/256;//定时10.000ms
TL0=(65536-10000)%256;
ET0=1;//使能定时器0
EA=1;//开启总中断
TR0=1;//开始计数
zong=(zi+1)*32;
while(1) //无限循环
{
if(s1==0)//检测按键
{
delay(30);//延时消除按键抖动
if(s1==0)
{
TR0=~TR0;//按下暂停 暂按继续
while(s1==0);//等待按键松手
}
}
if(s2==0)//检测按键
{
delay(30);//延时消除按键抖动
if(s2==0)
{
fx=~fx;//方向取反
aa=0;
if(fx==0)net=0;//正向移动
if(fx==1)net=zong;//反向移动
while(s2==0);//等待按键松手
}
}
for(i=0;i<16;i++)//循环移位
{
//两片138组成的4-16线译码器
P2=i;//列数据驱动,138的驱动端口
if(fx==0)writedata(tab[net+aa],tab[net+aa+1]);//写入需要显示的数据
if(fx==1)writedata(tab1[net+aa],tab1[net+aa+1]);//写入需要显示的数据
delay(3);//延时
writedata(0,0);//清屏
aa+=2;//数据加 实现扫描
if(aa>30)aa=0;//循环16次 清零
}
}
}
void timer0() interrupt 1
{
TH0=(65536-10000)/256;//10.000ms 进入一次中断
TL0=(65536-10000)%256;
alt++;
if(alt==10)//到100.000ms时间加以实现移动 用于控制移动速度
{
alt=0;
if(fx==0)//正向移动
{
net=net+2; //每次送两个编码数据
if(net>zong)//达到总字符
net=0;//数据清零
}
else//否则反向移动
{
net=net-2;//每次送两个编码数据
if(net<2)//数据完毕
net=zong;//回到总字符
}
}
}
|