完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
本帖最后由 骆页 于 2015-5-5 10:23 编辑
求助帖-16x16点阵显示每一行有重影,怎么消除,请大神帮忙,怎么消影。。。谢谢 #include #include #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 displaytime(char time); void init154(); ***it ADATA= P2^0; ***it ASCK= P2^1; ***it LATCH= P2^2; ***it A0= P2^3; ***it A1= P2^4; ***it A2= P2^5; ***it A3= P2^6; ***it E= P0^0; ***it p10 = P1^0; //上移 ***it p11 = P1^1; //左移 ***it p12 = P1^2; //下移 ***it p13 = P1^3; //暂停 ***it 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; } }
|
|
相关推荐
2个回答
|
|
|
|
|
|
时间设置的问题吧? 我猜测
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
205 浏览 0 评论
求助一下关于51系列单片机的Timer0的计时问题,TH0、TL0+1的时间是怎么算的?
1253 浏览 1 评论
【RA-Eco-RA4E2-64PIN-V1.0开发板试用】开箱+Keil环境搭建+点灯+点亮OLED
848 浏览 0 评论
【敏矽微ME32G070开发板免费体验】使用coremark测试敏矽微ME32G070 跑分
853 浏览 0 评论
【敏矽微ME32G070开发板免费体验】开箱+点灯+点亮OLED
1073 浏览 2 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12010 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 18:15 , Processed in 0.641807 second(s), Total 75, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号