用一块at89c52单片机,一块74HC154译码器。塔总共16层,每层16盏灯,层共阴,竖共阳,通俗来讲,就是一块16X16的点阵。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序:
- #include <AT89X51.H>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define p0 P0
- #define p1 P1
- #define p2 P2
- #define p3 P3
- uchar taba[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
- 0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
- uchar tabc[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- uchar tabb[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};
- uchar tabd[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};
- uchar a,b,c,d,e,f,g,h,i,j,k,l;
- void delaya();
- void delayb();
- void delayc();
- void delayd();
- void delaye();
- void delayf();
- void delayg();
- void delayh();
- void delayi();
- void delayj();
- void delay(unsigned int z)
- {
- while(z--);
- }
- void main()
- {
- TMOD=0x11;
- TH0=(65536-2000)/256;
- TL0=(65536-2000)%256;
- TH1=(65536-10000)/256;
- TL1=(65536-10000)%256;
- ET0=1;
- TR0=1;
- ET1=1;
- TR1=1;
- EA=1;
- while(1)
- {
- delaya();
- delayb();
- delayc();
- delayd();
- delaye();
- delayf();
- delayg();
- delayh();
- delayi();
- delayj();
- }
- }
- void li1() interrupt 1
- {
- TH0=(65536-2000)/256;
- TL0=(65536-2000)%256;
- i++;
- if(i==5) i=0;j++;
- if(j==16) j=0;
- }
- void li2() interrupt 3
- {
- TH1=(65536-10000)/256;
- TL1=(65536-10000)%256;
- h++;
- if(h==50) h=0;e++;l++;
- if(e==8) e=0;
- if(l==16) l=0;
- }
- void delaya()
- {
- for(c=0;c<3;c++)//下移
- {
- p0=0xff;p1=0xff;
- for(a=0;a<16;a++)
- {
- p2=taba[a];
- delay(6000);
- }
- }
- for(c=0;c<3;c++)//上移
- {
- p0=0xff;p1=0xff;
- for(a=0;a<16;a++)
- {
- p2=taba[15-a];
- delay(6000);
- }
- }
- for(c=0;c<3;c++)//上移和下移一起
- {
- p0=0xff;p1=0xff;
- for(a=0;a<16;a++)
- {
- p2=taba[16-a];
- delay(4000);
- p2=taba[a];
- delay(4000);
- }
- }
- for(a=0;a<200;a++)
- {
- p0=0x01;
- p1=0x01;
- for(b=0;b<=8;b++)
- {
- p2=taba[15-j];
- p0=_crol_(p0,1);
- p1=_crol_(p0,1);
- delay(200);
- }
- }
- }
- void delayb()
- {
- for(a=0;a<8;a++)
- {
- for(g=0;g<16;g++)
- {
- p1=0x00;
- p2=taba[g];
- p0=tabc[a];
- delay(3000);
- }
- for(g=0;g<16;g++)
- {
- p2=taba[g];
- p0=0x00;
- p1=tabc[a];
- delay(3000);
- }
- }
- for(a=0;a<200;a++)
- {
- p0=0x3f;
- p1=0x3f;
- for(b=0;b<=8;b++)
- {
- p2=taba[j];
- p0=_crol_(p0,1);
- p1=_crol_(p0,1);
- delay(200);
- }
- }
- for(a=0;a<20;a++)//右移
- {
- for(c=0;c<=8;c++)
- {
- for(b=0;b<16;b++)
- {
- p2=taba[b];
- delay(125);
- }
- p0=tabc[8-c];
- p1=tabc[8-c];
- delay(1000);
- }
- }
- }
- void delayc()
- {
- for(a=0;a<2;a++)
- {
- for(g=0;g<=16;g++)
- {
- if(g<8)
- {
- p1=0x00;
- p2=taba[g];
- p0=tabb[g];
- delay(4000);
- p2=taba[g];
- p0=0x00;
- p1=tabb[g];
- delay(4000);
- }
- if(g>=8)
- {
- p1=0x00;
- p2=taba[g];
- p0=tabb[g-8];
- delay(4000);
- p2=taba[g];
- p0=0x00;
- p1=tabb[g-8];
- delay(4000);
- }
- }
- }
- for(a=0;a<200;a++)
- {
- p0=0x01;
- p1=0x01;
- for(b=0;b<=8;b++)
- {
- p2=taba[j];
- p0=_cror_(p0,1);
- p1=_cror_(p0,1);
- delay(200);
- }
- }
- for(f=0;f<2;f++)
- {
- for(g=0;g<=16;g++)
- {
- if(g<8)
- {
- p2=taba[g];
- p1=0x00;
- p0=tabb[g];
- delay(8000);
- }
- if(g>=8)
- {
- p2=taba[g];
- p1=tabb[g-8];
- delay(8000);
- }
- }
- }
- for(b=0;b<80;b++)
- {
- for(a=0;a<15;a++)
- {
- p0=tabc[l];
- p1=tabc[l];
- p2=taba[j];
- delay(600);
- }
- }
- }
- void delayd()
- {
- for(a=0;a<=8;a++)
- {
- for(g=0;g<=16;g++)
- {
- p1=0x00;
- p2=taba[g];
- p0=tabb[a];
- delay(2500);
- p2=taba[g];
- p0=0x00;
- p1=tabb[a];
- delay(2500);
- }
- }
- for(a=0;a<=8;a++)
- {
- for(g=0;g<=16;g++)
- {
- p1=0x00;
- p2=taba[16-g];
- p0=tabb[a];
- delay(2500);
- p2=taba[16-g];
- p0=0x00;
- p1=tabb[a];
- delay(2500);
- }
- }
- for(b=0;b<120;b++)
- {
- for(a=0;a<15;a++)
- {
- p0=tabc[l];
- p1=tabc[l];
- p2=taba[j];
- delay(200);
- }
- }
- }
- void delaye()
- {
- for(a=0;a<20;a++)//左移
- {
- for(c=0;c<8;c++)
- {
- for(b=0;b<16;b++)
- {
- p2=taba[b];
- delay(125);
- }
- p0=tabc[c];
- p1=tabc[c];
- delay(1000);
- }
- }
- for(c=0;c<3;c++)//上移和下移一起
- { p0=0xff;p1=0xff;
- for(a=0;a<16;a++)
- {
- p2=taba[16-a];
- delay(4000);
- p2=taba[a];
- delay(4000);
- }
- }
- }
- void delayf()
- {
- for(a=0;a<=8;a++)
- {
- for(g=0;g<=16;g++)
- {
- p1=0x00;
- p2=taba[16-g];
- p0=tabb[8-a];
- delay(2500);
- p2=taba[16-g];
- p0=0x00;
- p1=tabb[8-a];
- delay(2500);
- }
- }
- for(b=0;b<80;b++)
- {
- for(a=0;a<15;a++)
- {
- p0=tabc[l];
- p1=tabc[l];
- p2=taba[j];
- delay(450);
- }
- }
- }
- void delayg()
- {
- for(b=0;b<120;b++)
- {
- for(a=0;a<15;a++)
- {
- p0=tabc[8-e];
- p1=tabc[8-e];
- p2=taba[15-j];
- delay(150);
- }
- }
- for(d=0;d<120;d++)
- {
- p0=0x01;
- p1=0x01;
- for(b=0;b<=8;b++)
- {
- p2=taba[15-j];
- p0=_crol_(p0,1);
- p1=_crol_(p0,1);
- delay(200);
- }
- p0=0x01;
- p1=0x01;
- for(b=0;b<=8;b++)
- {
- p2=taba[j];
- p0=_crol_(p0,1);
- p1=_crol_(p0,1);
- delay(200);
- }
- }
- for(c=0;c<3;c++)//由中间向两边移动
- {
- p0=0xff;
- p1=0xff;
- for(a=8;a<16;a++)
- {
- p2=taba[a];
- delay(4000);
- p2=taba[16-a];
- delay(4000);
- }
- }
- for(a=0;a<200;a++)
- {
- p0=0x3f;
- p1=0x3f;
- for(b=0;b<=8;b++)
- {
- p2=taba[15-j];
- p0=_cror_(p0,1);
- p1=_cror_(p0,1);
- delay(200);
- }
- }
- for(b=0;b<80;b++)
- {
- for(a=0;a<15;a++)
- {
- p0=tabc[e];
- p1=tabc[e];
- p2=taba[j];
- delay(600);
- }
- }
- }
- void delayh()
- {
- for(a=0;a<2;a++)//左移
- {
- delay(65000);
- for(c=0;c<=8;c++)
- {
- for(b=0;b<16;b++)
- {
- p2=taba[b];
- delay(125);
- }
- p0=tabb[c];
- p1=tabb[c];
- delay(2000);
- }
- for(c=0;c<=8;c++)
- {
- for(b=0;b<16;b++)
- {
- p2=taba[b];
- delay(125);
- }
- p0=tabd[c];
- p1=tabd[c];
- delay(800);
- }
- }
- }
- void delayi()
- {
- for(d=0;d<120;d++)
- {
- p0=0x01;
- p1=0x01;
- for(b=0;b<=8;b++)
- {
- p2=taba[15-j];
- p0=_cror_(p0,1);
- p1=_cror_(p0,1);
- delay(200);
- }
- p0=0x01;
- p1=0x01;
- for(b=0;b<=8;b++)
- {
- p2=taba[j];
- p0=_cror_(p0,1);
- p1=_cror_(p0,1);
- delay(200);
- }
- }
- for(a=0;a<200;a++)
- {
- p0=0x01;
- p1=0x01;
- for(b=0;b<=8;b++)
- {
- p2=taba[j];
- p0=_crol_(p0,1);
- p1=_crol_(p0,1);
- delay(200);
- }
- }
- for(a=0;a<200;a++)
- {
- p0=0x3f;
- p1=0x3f;
- for(b=0;b<=8;b++)
- {
- p2=taba[j];
- p0=_cror_(p0,1);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
程序 仿真图.rar
(91.99 KB, 下载次数: 69)
|