本帖最后由 骆页 于 2015-5-5 10:23 编辑
求助帖-16x16点阵显示每一行有重影,怎么消除,请大神帮忙,怎么消影。。。谢谢
#include <reg51.h>
#include <intrins.h>
#define SPEED 10
#define uchar unsigned char //无符号字符型 宏定义 变量范围0~255
void ymove(char dir,unsigned char *ptr,char speed);
void xmove(char dir,unsigned char *ptr,char n,char speed);
void delay(unsigned int a);
void display();
void display
time(char time);
void init154();
sbit ADATA= P2^0;
sbit ASCK= P2^1;
sbit LATCH= P2^2;
sbit A0= P2^3;
sbit A1= P2^4;
sbit A2= P2^5;
sbit A3= P2^6;
sbit E= P0^0;
sbit p10 = P1^0; //上移
sbit p11 = P1^1; //左移
sbit p12 = P1^2; //下移
sbit p13 = P1^3; //暂停
sbit p14 = P1^4; //右移
uchar led =5; //点阵模式
code unsigned char liang[32]={
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};
code unsigned char mie[32]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, //全灭
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
code unsigned char huan[32]={
0xDF,0xF7,0xDB,0xEF,0xDD,0x9F,0xDE,0x7F,0xD9,0xBE,0xC6,0xCD,0xFD,0xFB,0xF3,0xE7,
0x0F,0x9F,0xEC,0x7F,0xEF,0x9F,0xEF,0xE7,0xEB,0xFB,0xE7,0xFD,0xFF,0xFE,0xFF,0xFF};
code unsigned char ying[32]={
0xFD,0xFF,0xFD,0xFD,0xBD,0xFB,0xCC,0x07,0xFF,0xFB,0xFF,0xFD,0xC0,0x0D,0xDF,0xDD,
0xBF,0xBD,0xFF,0xFD,0xC0,0x01,0xDF,0xBD,0xDF,0xDD,0xC0,0x3D,0xFF,0xFD,0xFF,0xFF};
code unsigned char lai[32]={
0xFF,0x7B,0xEF,0x7B,0xEF,0x77,0xEB,0x77,0xEC,0x6F,0xEF,0x5F,0xEF,0x3F,0x00,0x00,
0xEF,0x3F,0xEF,0x5F,0xEE,0x6F,0xE9,0x77,0xEF,0x77,0xEF,0x7B,0xFF,0x7B,0xFF,0xFF};
code unsigned char dao[32]={
0xBD,0xFD,0xB9,0xDC,0xB5,0xDD,0xAD,0xDD,0x9C,0x01,0xBD,0xDB,0xB5,0xDB,0xB9,0xDB,
0xBC,0xFB,0xFF,0xFF,0xE0,0x0F,0xFF,0xFD,0xFF,0xFE,0x00,0x01,0xFF,0xFF,0xFF,0xFF};
code unsigned char bei[32]={
0xFF,0xFB,0xFB,0xF9,0xFB,0xFB,0xFB,0xF7,0xFB,0xF7,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0x00,0x03,0xFD,0xFD,0xFB,0xFD,0xF7,0xFD,0xEF,0xFD,0xFF,0xE1,0xFF,0xFF};
code unsigned char li[32]={
0xDF,0xFB,0xDE,0xF9,0xDE,0xFB,0xC0,0x07,0xDE,0xF7,0xDE,0xF7,0xFF,0xFD,0x80,0xDD,
0xB6,0xDD,0xB6,0xDD,0x80,0x01,0xB6,0xDD,0xB6,0xDD,0x80,0xDD,0xFF,0xFD,0xFF,0xFF};
code unsigned char gong[32]={
0xFF,0xFB,0xDF,0xFB,0xDF,0xFB,0xDF,0xFB,0xDF,0xFB,0xDF,0xFB,0xDF,0xFB,0xC0,0x03,
0xDF,0xFB,0xDF,0xFB,0xDF,0xFB,0xDF,0xFB,0xDF,0xFB,0xDF,0xFB,0xFF,0xFB,0xFF,0xFF};
code unsigned char zhu[32]={
0xDF,0xF7,0xDD,0xF3,0xDD,0xF7,0xC0,0x0F,0xDD,0xEF,0xDD,0xEF,0xFA,0xFB,0x86,0xE7,
0xEE,0x9F,0xEE,0x7F,0x00,0x00,0xEE,0x7F,0xEE,0x9F,0xEE,0xE7,0xFE,0xFB,0xFF,0xFF};
code unsigned char hai[32]={
0xF7,0xDF,0xF9,0xDF,0xBF,0xC1,0xCF,0x3F,0xFC,0xFF,0xF7,0x7F,0xEF,0x47,0x10,0x37,
0xD7,0x77,0xD5,0x55,0xD6,0x66,0xD7,0x75,0xD0,0x03,0xDF,0x77,0xFF,0x7F,0xFF,0xFF};
code unsigned char xue[32]={
0xFD,0xDF,0xF3,0xDF,0x77,0xDF,0x96,0xDF,0xF6,0xDF,0xF6,0xDD,0x76,0xDE,0x96,0x81,
0xF6,0x9F,0xF6,0x5F,0xE6,0xDF,0xD7,0xDF,0x37,0xDF,0xF5,0xDF,0xF3,0xDF,0xFF,0xFF};
code unsigned char yuan[32]={
0xFF,0xFF,0x80,0x00,0xBB,0xDF,0xA5,0xEF,0x9E,0x1F,0xF7,0xFE,0xCF,0x7D,0xDB,0x73,
0xDB,0x0F,0x5B,0x7F,0x9B,0x7F,0xDB,0x03,0xDB,0x7D,0xD7,0x7D,0xCF,0x71,0xFF,0xFF};
unsigned char idata buffer[32];
void main(void)
{
unsigned char i;
E = 0;
P2= 0x00;
EA = 1; //开总中断
TMOD = 0X01; //定时器0、定时器1工作方式1
ET0 = 1; //关定时器0中断
TR0 = 1; //允许定时器0定时
TH0 = 0xFF;
TL0 = 0x38; //1ms 24M晶振
while(1)
{
if( led == 5)
{
for(i=0;i<32;i++)
buffer
=liang;
displaytime(1);
}
if( led == 1)
ymove(1,mie,SPEED);
if( led == 1)
ymove(1,huan,SPEED);
if( led == 1)
ymove(1,ying,SPEED);
if( led == 1)
ymove(1,lai,SPEED);
if( led == 1)
ymove(1,dao,SPEED);
if( led == 1)
ymove(1,bei,SPEED);
if( led == 1)
ymove(1,li,SPEED);
if( led == 1)
ymove(1,gong,SPEED);
if( led == 1)
ymove(1,zhu,SPEED);
if( led == 1)
ymove(1,hai,SPEED);
if( led == 1)
ymove(1,xue,SPEED);
if( led == 1)
ymove(1,yuan,SPEED); //上行结束
if( led == 2)
xmove(1,mie,1,SPEED);
if( led == 2)
xmove(1,huan,1,SPEED);
if( led == 2)
xmove(1,ying,1,SPEED);
if( led == 2)
xmove(1,lai,1,SPEED);
if( led == 2)
xmove(1,dao,1,SPEED);
if( led == 2)
xmove(1,bei,1,SPEED);
if( led == 2)
xmove(1,li,1,SPEED);
if( led == 2)
xmove(1,gong,1,SPEED);
if( led == 2)
xmove(1,zhu,1,SPEED);
if( led == 2)
xmove(1,hai,1,SPEED);
if( led == 2)
xmove(1,xue,1,SPEED);
if( led == 2)
xmove(1,yuan,1,SPEED); //左行结束(欢迎来到毕设指导)
if( led == 3)
ymove(0,mie,SPEED);
if( led == 3)
ymove(0,huan,SPEED);
if( led == 3)
ymove(0,ying,SPEED);
if( led == 3)
ymove(0,lai,SPEED);
if( led == 3)
ymove(0,dao,SPEED);
if( led == 3)
ymove(0,bei,SPEED);
if( led == 3)
ymove(0,li,SPEED);
if( led == 3)
ymove(0,gong,SPEED);
if( led == 3)
ymove(0,zhu,SPEED);
if( led == 3)
ymove(0,hai,SPEED);
if( led == 3)
ymove(0,xue,SPEED);
if( led == 3)
ymove(0,yuan,SPEED); //下行结束
if( led == 4)
xmove(0,mie,1,SPEED);
if( led == 4)
xmove(0,huan,1,SPEED);
if( led == 4)
xmove(0,ying,1,SPEED);
if( led == 4)
xmove(0,lai,1,SPEED);
if( led == 4)
xmove(0,dao,1,SPEED);
if( led == 4)
xmove(0,bei,1,SPEED);
if( led == 4)
xmove(0,li,1,SPEED);
if( led == 4)
xmove(0,gong,1,SPEED);
if( led == 4)
xmove(0,zhu,1,SPEED);
if( led == 4)
xmove(0,hai,1,SPEED);
if( led == 4)
xmove(0,xue,1,SPEED);
if( led == 4)
xmove(0,yuan,1,SPEED); //右行结束
if( led == 0)
{
displaytime(1);
}
}
}
/************* 子函数 ******************/
void delay(unsigned int a)
{
while(a--);
}
/*显示*/
void display()
{
unsigned char hang,ib,k,tmp,tmp1;
tmp1 = 2;
P2= 0x00;
E=0;
for(hang=0;hang<16;hang++)
{
ASCK =0;
LATCH=0;
for(ib=0;ib<2;ib++)
{
tmp = buffer[hang*2+ib];
for(k=0;k<8;k++)
{
tmp <<=1;
ASCK =0;
ADATA =CY;
ASCK =1;
}
}
LATCH=1;
delay(64);
tmp1 = tmp1 + 8;
P2= tmp1 ;
}
ASCK =0;
ASCK =1;
E = 1;
}
void displaytime(char time)
{
unsigned char i;
while(time--)
{
i=130;
while(i--)
display();
}
}
/*左右移动*/
void xmove(char dir,unsigned char *ptr,char n,char speed)
{ /* 方向 n是要移动的汉字个数 移动速度*/
unsigned char i=0, ib=0;
unsigned int tmp=0, speedm=0;
unsigned char buffer2[16]; //半个汉字的缓存
n*=2; //左半字和右半字,所以要x2
for(i=0;i<16;i++) //清零
buffer2=0;
if(dir == 1)
{
/**** 向左移动 ****/
for(n;n>0;n--)
{
if(ptr != 0)
{
tmp = n%2; //判断是左半字还是右半字
for(i=0;i<16;i++)
buffer2=ptr[i*2+tmp];
if(tmp) //tmp为1时,将地址指向下一个汉字
ptr+=32;
}
for(tmp=8;tmp>0;tmp--) //要移动8列
{
ib=0;
for(i=0;i<16;i++)
{ //要移16行,共16个字节
buffer[ib] <<=1; //移第一个半字
if(buffer[ib+1] & 0x80)
buffer[ib]++;
ib++;
buffer[ib]<<=1; //移后半字
if(buffer2 & 0x80)
buffer[ib]++;
ib++;
buffer2<<=1; //缓冲左半字向左移一位
}
speedm=speed; //更新点阵
while(speedm--)
display();
}
}
}
//--------------------------------------------------//
else
{
/****** 向右移动 ******/
for(n;n>0;n--)
{
if(ptr != 0)
{
tmp = (n+1) % 2 ; //判断左半字还是右半字
for(i=0;i<16;i++)
buffer2=ptr[i*2+tmp];
if(tmp == 0) //tmp为0时,将地址指向下一个汉字
ptr+=32;
}
for(tmp=8;tmp>0;tmp--) //要移动8列
{
ib=0;
for(i=0;i<16;i++)
{ //要移16行,共16个字节
buffer[ib+1] >>= 1; //移右半字
if(buffer[ib] & 0x01)
buffer[ib+1] |=0x80 ;
buffer[ib] >>= 1; //移左半字
if(buffer2 & 0x01)
buffer[ib] |= 0x80;
ib+=2;
buffer2 >>=1; //下个汉字的右半字向右移一位
}
speedm=speed;
while(speedm--) //更新点阵
display();
}
}
}
}
/*上下移动*/
void ymove(char dir,unsigned char *ptr, char speed)
{ //dir=1上移动,dir=0为下移动
char i=0, j=0, ib=0;
unsigned int tmp=0, speedm=0;
if(dir==0)
{
/**** 向下移 ****/
ib=31;
for(i=16;i>0;i--) //下移16行
{
for(j=29;j>-1;j--)
buffer[j+2]=buffer[j]; //将上一行的内容复制到下一行
if(ptr==0)
{ //移空时,buffer的首行用0移入
buffer[0]=0;
buffer[1]=0;
}
else
{ //否则,处理buffer的首行元素
buffer[1]=ptr[ib];
buffer[0]=ptr[ib-1];
ib=ib-2;
}
speedm=speed;
while(speedm--) //更新点阵
display();
}
}
/****** 向上移 *******/
else
{
ib=0; //数组元素序号
for(i=0;i<16;i++) //上移16行
{
for(j=0;j<30;j++) //将下一行的内容复制到上一行
buffer[j]=buffer[j+2];
if(ptr==0) //移入为空,buffer的末行用0移入
{
buffer[30]=0;
buffer[31]=0;
}
else
{ //否则,处理buffer的末行元素
buffer[30]=ptr[ib];
buffer[31]=ptr[ib+1];
ib=ib+2;
}
speedm=speed; //更新点阵
while(speedm--)
display();
}
}
}
void timer0(void) interrupt 1
{
TH0 = 0xFF;
TL0 = 0x38; //1ms
if( p10 ==0 ) // 上
{
led =1;
}
if( p11 ==0 ) // 左
{
led =4;
}
if( p12 ==0 ) // 下
{
led =3;
}
if( p13 ==0 ) // 暂停
{
led =0;
}
if( p14 ==0 ) // 右
{
led =2;
}
}
-
你看看,我上传了照片了,谢谢
一周热门 更多>