常见的流水灯形式组合在一起,12个LED,满足你多种需求,提供一个大家对于大于8个LED灯进行流水灯控制的思路。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg51.h>
- #define uchar unsigned char
- uchar code ledtab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
- uchar fun=0,time=0,num=0,ss;
- uchar code led1[6]={0xfe,0xfd,0xfb,0xf7,0x6f,0x9f};
- uchar led2=0xfe;
- sbit key=P3^2;
- void delay(uchar a)
- {
- uchar i;
- while(a--)for(i=0;i<120;i++);
- }
- void t0isr() interrupt 1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- time++;
- if(time>=2)
- {
- time=0;
- switch(fun)
- {
- case 0: num%=6;
- P1=led1[num];
- if(num<4)P0=led1[num];
- else P0=0xff;
- break;
- case 1: P1=ss;P0=ss;ss=~ss;break;
- case 2: num%=12;
- if(num<4)
- {
- if(num==0)led2=0xfe;
- P0=led2;
- P1=0xff;
- led2<<=1;
- led2|=0x01;
- }
- else
- {
- if(num==4)led2=0x7f;
- P0=0xff;
- P1=led2;
- led2>>=1;
- led2|=0x80;
- }
- break;
- case 3: num%=12;
- if(num<8)
- {
- if(num==0)led2=0xfe;
- P0=0xff;
- P1=led2;
- led2<<=1;
- led2|=0x01;
- }
- else
- {
- if(num==8)led2=0xf7;
- P1=0xff;
- P0=led2;
- led2>>=1;
- led2|=0x08;
- }
- break;
- case 4: num%=2;
- if(num==0){P1=0xc0;P0=0xff;}
- else{P1=0x3f;P0=0x00;}
- break;
- case 5: num%=7;
- if(num==0){P0=0x00;P1=0x00;led2=0x01;}
- else
- {
- if(num<5){P0=led2;P1=led2;led2<<=1;led2|=0x01;}
- else
- {
- if(num==5){P1=0x9f;P0=0xff;}
- if(num==6)P1=0xff;
- }
- }
- break;
- case 6: num%=13;
- if(num<9){
- if(num==0){P0=0x00;P1=0x00;led2=0x01;}
- else{P1=led2;
- led2<<=1;
- led2|=0x01;
- }
- }
- else
- {
- if(num==9)led2=0xf8;
- P0=led2;
- led2>>=1;
- led2|=0x08;
- }
- break;
- case 7: num%=13;
- if(num<5)
- {
- if(num==0){P0=0x00;P1=0x00;led2=0x01;}
- else{P0=led2;led2<<=1;led2|=0x01;}
- }
- else
- {
- if(num==5)led2=0x80;
- P1=led2;
- led2>>=1;
- led2|=0x80;
- }
- break;
- case 8: num%=7;
- if(num==0){P0=0xff;P1=0xff;led2=0x07;}
- if(num==1)P1=0x9f;
- if(num==2)P1=0x0f;
- if(num>2){P0=led2;P1=led2;led2>>=1;led2&=0xf7;}
- break;
- case 9: num%=7;
- if(num<5)
- {
- if(num==0){P0=0xff;P1=0xff;led2=0xfe;}
- else
- {
- P1=led2;P0=led2;led2<<=1;
- }
- }
- else
- {
- if(num==5){P0=0x00;P1=0x60;}
- if(num==6)P1=0x00;
- }
- break;
- case 10: num%=2;
- if(num==0){P0=0xf5;P1=0xaa;}
- else {P0=0xfa;P1=0x55;}
- default:break;
- }
- num++;
- }
- }
- main()
- {
- TMOD=0x01;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- TR0=1;
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
花样流水灯.rar
(34.29 KB, 下载次数: 65)
|