您好,欢迎访问三七文档
888光立方仿真代码/*lidameng制作光立方源程序*/#includereg51.h//包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义#defineDataPortP0//定义数据端口程序中遇到DataPort则用P0替换sbitline_LATCH=P1^0;//定义锁存使能端口行扫描的锁存端口sbitLATCH1=P2^0;//定义锁存使能端口第一灯板的字节锁存sbitLATCH2=P2^1;//sbitLATCH3=P2^2;//sbitLATCH4=P2^3;sbitLATCH5=P2^4;sbitLATCH6=P2^5;sbitLATCH7=P2^6;sbitLATCH8=P2^7;voidDelay(unsignedintt){while(--t);}unsignedcharline[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//显示行值01234567voiddisplay(unsignedchar*Data)//显示子程序,指针数组作为形参,直接指向传过来的实参数组的地址,这样就可直接操纵数组传过来的数组了{unsignedchari;for(i=0;i8;i++){DataPort=line[i];//先给行(灯板的公共端)输入数据line_LATCH=1;//打开锁存,把数据line[i]放进去line_LATCH=0;//关闭锁存,阻止外部数据进来DataPort=Data[i];//把数组Data[0~7]里的值依次传给第一灯板的573锁存器中LATCH1=1;LATCH1=0;DataPort=Data[8+i];//把数组Data[8~15]里的值依次传给第二灯板的573锁存器中LATCH2=1;LATCH2=0;DataPort=Data[16+i];//把数组Data[16~23]里的值依次传给第三灯板的573锁存器中LATCH3=1;LATCH3=0;DataPort=Data[24+i];LATCH4=1;LATCH4=0;DataPort=Data[32+i];LATCH5=1;LATCH5=0;DataPort=Data[40+i];LATCH6=1;LATCH6=0;DataPort=Data[48+i];LATCH7=1;LATCH7=0;DataPort=Data[56+i];LATCH8=1;LATCH8=0;Delay(200);//扫描间隙延时,时间太长会闪烁,太短会造成重影DataPort=0xff;//清空行锁存器里数据,防止出现乱码line_LATCH=1;//line_LATCH=0;}/*如此一趟循环下来,每次都是8块灯板的同一行一起点亮,如此组成一个灯板,8次循环下来,就全部灯都点亮了*/}voidliang()//点亮所有的灯{unsignedinti;for(i=0;i5000;i++){DataPort=0x00;//先给行(灯板的公共端)输入数据line_LATCH=1;//打开锁存,把数据0x00放进去line_LATCH=0;//关闭锁存,阻止外部数据进来DataPort=0xff;//把0xff送进锁存器1~8中,使它们的输出引脚都输出高电平,与行锁存器的0x00相对,点亮所有的灯LATCH1=1;LATCH1=0;LATCH2=1;LATCH2=0;LATCH3=1;LATCH3=0;LATCH4=1;LATCH4=0;LATCH5=1;LATCH5=0;LATCH6=1;LATCH6=0;LATCH7=1;LATCH7=0;LATCH8=1;LATCH8=0;}}voidmie()//熄灭所有的灯{unsignedinti;for(i=0;i5000;i++){DataPort=0x00;//先给行(灯板的公共端)输入数据line_LATCH=1;//打开锁存,把数据0x00放进去line_LATCH=0;//关闭锁存,阻止外部数据进来DataPort=0x00;//把0x00送进锁存器1~8中,使它们的输出引脚都输出高电平,与行锁存器的0x00相对,熄灭所有的灯LATCH1=1;LATCH1=0;LATCH2=1;LATCH2=0;LATCH3=1;LATCH3=0;LATCH4=1;LATCH4=0;LATCH5=1;LATCH5=0;LATCH6=1;LATCH6=0;LATCH7=1;LATCH7=0;LATCH8=1;LATCH8=0;}}voidLaihui()//来回灯板显示效果{unsignedchari;unsignedcharcodelaihui0[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//定义空间为64的数组并赋值,用以传递给显示子程序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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};unsignedcharcodelaihui1[]={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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};unsignedcharcodelaihui2[]={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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};unsignedcharcodelaihui3[]={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,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};unsignedcharcodelaihui4[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,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};unsignedcharcodelaihui5[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};unsignedcharcodelaihui6[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};unsignedcharcodelaihui7[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};for(i=0;i10;i++)display(laihui0);//调用显示子程序display,并把数组laihui0的数组名作为实参传给指针式形参for(i=0;i10;i++)display(laihui1);for(i=0;i10;i++)display(laihui2);for(i=0;i10;i++)display(laihui3);for(i=0;i10;i++)display(laihui4);for(i=0;i10;i++)display(laihui5);for(i=0;i10;i++)
本文标题:888光立方仿真
链接地址:https://www.777doc.com/doc-7312553 .html