简单的51单片机花样流水灯C语言源代码
51单片机流水灯程序
1.第一个发光管以间隔200ms闪烁。
2.8个发光管由上至下间隔1s流动,其中每个管亮500ms,灭500ms。
3.8个发光管来回流动,第个管亮100ms。
4。
用8个发光管演示出8位二进制数累加过程。
5。
8个发光管间隔200ms由上至下,再由下至上,再重复一次,然后全部熄灭再以300ms间隔全部闪烁5次。
重复此过程。
6.间隔300ms第一次一个管亮流动一次,第二次两个管亮流动,依次到8个管亮,然后重复整个过程。
7。
间隔300ms先奇数亮再偶数亮,循环三次;一个灯上下循环三次;两个分别从两边往中间流动三次;再从中间往两边流动三次;8个全部闪烁3次;关闭发光管,程序停止。
1#include<reg52。
h〉#define uint unsigned intsbit led1=P1^0;void delay();void main(){while(1){led1=0;delay();led1=1;delay();}}void delay(){uint x,y;for(x=200;x>0;x—-)for(y=100;y〉0;y-—);}2#include<reg52。
h>#include〈intrins。
h〉#define uint unsigned intuchar a;void delay();void main(){a=0xfe;P1=a;while(1){a=_crol_(a,1);delay();P1=a;delay();}}void delay(){uint b;for(b=55000;b>0;b—-);}3#include<reg52。
h〉#include <intrins。
h>#define uint unsigned int #define uchar unsigned char void delay(){uint x,y;for(x=100;x〉0;x--)for(y=110;y>0;y—-);}void main(){uchar a,i;while(1){a=0xfe;for(i=0;i〈8;i++){P1=a;delay(100);a=_crol_(a,1);for(i=0;i〈8;i++){P1=a;delay(100);a=_cror_(a,1);}}}4#include<reg52.h>#include 〈intrins。
多种方法写出的51单片机流水灯C语言程序
目录流水灯最原始 (1)流水灯位左移 (3)流水灯移位函数 (4)流水灯数组 (5)流水灯精确定时器 (6)流水灯最原始#include "reg51.h"sbit p0=P1^0;sbit p1=P1^1;sbit p2=P1^2;sbit p3=P1^3;sbit p4=P1^4;sbit p5=P1^5;sbit p6=P1^6;sbit p7=P1^7;voidmdelay(unsigned int t){unsigned char n;for(;t>0;t--)for(n=0;n<125;n++){;}}void main(){while(1){P1=0;p0=1;mdelay(1000);p0=0;p1=1;mdelay(1000);p1=0;p2=1;mdelay(1000);p2=0;p3=1;mdelay(1000);p3=0;p4=1;mdelay(1000);p4=0;p5=1;mdelay(1000);p5=0;p6=1;mdelay(1000);p6=0;p7=1;mdelay(1000);p7=0;}}流水灯位左移#include "reg51.h"voidmdelay(unsigned int t){unsigned char n;for(;t>0;t--)for(n=0;n<125;n++){;}}void main(){unsigned char i;unsignedint led;while(1){led=0xfe;for(i=0;i<8;i++){P1=led;mdelay(1000);led=led<<1;led=led|0x01;}}}流水灯移位函数#include "reg51.h"#include "intrins.h"voidmdelay(unsigned int t){unsigned char n;for(;t>0;t--)for(n=0;n<125;n++){;}}void main(){unsigned char led;led=0x01;while(1){P1=led;led=_crol_(led,1);mdelay(1000);}}流水灯数组#include "reg51.h"unsigned char table[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; voidmdelay(unsigned int t){unsigned char n;for(;t>0;t--)for(n=0;n<125;n++){;}}void main(){unsigned char i;while(1){for(i=0;i<8;i++){P1=table[i];mdelay(1000);}}}流水灯精确定时器#include "reg51.h"#include "intrins.h"unsignedint count=0,led;void main(){P1=0x00;led=0x01;EA=1;ET0=1;TMOD=0x01;TH0=0x3c;TL0=0xb0;TR0=1;for(;;){;}}voidbiao() interrupt 1{count++;if(count==20){count=0;P1=led;led=_crol_(led,1);}TH0=0x3c;TL0=0xb0;}。
51芯片超炫爱心流水程序灯代码
#include<reg52.h>sbit P00=P0^0;sbit P01=P0^1;sbit P02=P0^2;sbit P03=P0^3;sbit P04=P0^4;sbit P05=P0^5;sbit P06=P0^6;sbit P07=P0^7;sbit P10=P1^0;sbit P11=P1^1;sbit P12=P1^2;sbit P13=P1^3;sbit P14=P1^4;sbit P15=P1^5;sbit P16=P1^6;sbit P17=P1^7;sbit P20=P2^0;sbit P21=P2^1;sbit P22=P2^2;sbit P23=P2^3;sbit P24=P2^4;sbit P25=P2^5;sbit P26=P2^6;sbit P27=P2^7;sbit P30=P3^0;sbit P31=P3^1;sbit P32=P3^2;sbit P33=P3^3;sbit P34=P3^4;sbit P35=P3^5;sbit P36=P3^6;sbit P37=P3^7;unsigned int x,y;void rzmzy(); //红色走马左移声明void rzmyy(); //红色走马右移声明void rzmnwyd(); //红色走马内外移动声明void rtbyd(); //红色跳变移动声明void rjl(); //红色渐亮声明void rja(); //红色渐暗声明void rP0ja();//P0渐暗void zkb(unsigned char d);void delayms(int z)//延时声明,修改s的数值,就可以改变时间{int i,j;for(i=z;i>0;i--)for(j=110;j>0;j--);}void Onall() //开启所有灯{P0=0x00;P1=0x00;P2=0x00;P3=0x00;}void Offall()//关闭所有灯{P0=0xff;P1=0xff;P2=0xff;P3=0xff;}//void fxls()//逆时针逐个等时流水灯//{// P0=0xfe;delayms(50);// P0=0xfd;delayms(50);// P0=0xfb;delayms(50);// P0=0xf7;delayms(50);// P0=0xef;delayms(50);// P0=0xdf;delayms(50);// P0=0xbf;delayms(50);// P0=0x7f;delayms(50);// P0=0xff;//// P2=0x7f;delayms(50);// P2=0xbf;delayms(50);// P2=0xdf;delayms(50);// P2=0xef;delayms(50);// P2=0xf7;delayms(50);// P2=0xfb;delayms(50);// P2=0xfd;delayms(50);// P2=0xfe;delayms(50);// P2=0xff;//// P3=0x7f;delayms(50);// P3=0xbf;delayms(50);// P3=0xdf;delayms(50);// P3=0xef;delayms(50);// P3=0xf7;delayms(50);// P3=0xfb;delayms(50);// P3=0xfe;delayms(50);// P3=0xff;//// P1=0x7f;delayms(50);// P1=0xbf;delayms(50);// P1=0xdf;delayms(50);// P1=0xef;delayms(50);// P1=0xf7;delayms(50);// P1=0xfb;delayms(50);// P1=0xfd;delayms(50);// P1=0xfe;delayms(50);// P1=0xff;//}//void ls()//顺时针逐个等时流水灯//{// Offall();// P1=0xfe;delayms(50);// P1=0xfd;delayms(50);// P1=0xfb;delayms(50);// P1=0xf7;delayms(50);// P1=0xef;delayms(50);// P1=0xdf;delayms(50);// P1=0xbf;delayms(50);// P1=0x7f;delayms(50);// P1=0xff;//// P3=0xfe;delayms(50);// P3=0xfd;delayms(50);// P3=0xfb;delayms(50);// P3=0xf7;delayms(50);// P3=0xef;delayms(50);// P3=0xdf;delayms(50);// P3=0xbf;delayms(50);// P3=0x7f;delayms(50);// P3=0xff;;//// P2=0xfe;delayms(50);// P2=0xfd;delayms(50);// P2=0xfb;delayms(50);// P2=0xf7;delayms(50);// P2=0xef;delayms(50);// P2=0xdf;delayms(50);// P2=0xbf;delayms(50);// P2=0xff;;//// P0=0x7f;delayms(50);// P0=0xbf;delayms(50);// P0=0xdf;delayms(50);// P0=0xef;delayms(50);// P0=0xf7;delayms(50);// P0=0xfb;delayms(50);// P0=0xfd;delayms(50);// P0=0xfe;delayms(50);// P0=0xff;//}void bsb()//双边同时流水由上至下{Offall();delayms(50);P0=0xfe;delayms(50);P0=0xfd;P1=0xfe;delayms(50);P0=0xfb;P1=0xfd;delayms(50);P0=0xf7;P1=0xfb;delayms(50);P0=0xef;P1=0xf7;delayms(50);P0=0xdf;P1=0xef;delayms(50);P0=0xbf;P1=0xdf;delayms(50);P0=0x7f;P1=0xbf;delayms(50);P0=0xff;P2=0x7f;P1=0x7f;delayms(50);P1=0xff;P2=0xbf;P3=0xfe;delayms(50);P2=0xdf;P3=0xfd;delayms(50);P2=0xef;P3=0xfb;delayms(50);P2=0xf7;P3=0xf7;delayms(50);P2=0xfb;P3=0xef;delayms(50);P2=0xfd;P3=0xdf;delayms(50);P2=0xfe;P3=0xbf;delayms(50);P2=0xff;P3=0x7f;delayms(50);P3=0xff;}//void fbsb() //半双边流水由下至上//{// Offall();// P3=0x7f;delayms(80);// P2=0xfe;P3=0xbf;delayms(80);// P2=0xfd;P3=0xdf;delayms(80);// P2=0xfb;P3=0xef;delayms(80);// P2=0xf7;P3=0xf7;delayms(80);// P2=0xef;P3=0xfb;delayms(80);// P2=0xdf;P3=0xfd;delayms(80);// P2=0xbf;P3=0xfe;delayms(80);Offall(); // P2=0x7f;P1=0x7f;delayms(80);Offall(); //// P0=0x7f;P1=0xbf;delayms(80);// P0=0xbf;P1=0xdf;delayms(80);// P0=0xdf;P1=0xef;delayms(80);// P0=0xef;P1=0xf7;delayms(80);// P0=0xf7;P1=0xfb;delayms(80);// P0=0xfb;P1=0xfd;delayms(80);// P0=0xfd;P1=0xfe;delayms(80);// P0=0xfe;P1=0xff;delayms(80);//}void ss(y)//闪烁(y为闪烁间隔时间){Onall();delayms(y);Offall();delayms(y);}//void fxsz() //反向生长//{// Offall();// P0=0xfe;delayms(50);// P0=0xfc;delayms(50);// P0=0xf8;delayms(50);// P0=0xf0;delayms(50);// P0=0xe0;delayms(50);// P0=0xc0;delayms(50);// P0=0x80;delayms(50);// P0=0x00;delayms(50);//// P2=0x7f;delayms(50);// P2=0x3f;delayms(50);// P2=0x1f;delayms(50);// P2=0x0f;delayms(50);// P2=0x07;delayms(50);// P2=0x03;delayms(50);// P2=0x01;delayms(50);// P2=0x00;delayms(50);//// P3=0x7f;delayms(50);// P3=0x3f;delayms(50);// P3=0x1f;delayms(50);// P3=0x0f;delayms(50);// P3=0x07;delayms(50); // P3=0x03;delayms(50); // P3=0x01;delayms(50); // P3=0x00;delayms(50); //// P1=0x7f;delayms(50);// P1=0x3f;delayms(50);// P1=0x1f;delayms(50);// P1=0x0f;delayms(50);// P1=0x07;delayms(50); // P1=0x03;delayms(50); // P1=0x01;delayms(50); // P1=0x00;delayms(50); //// Offall();delayms(100);// Onall();delayms(100);// Offall();delayms(100);// Onall();delayms(500);// Offall();delayms(50);//}void zxsz() //正向生长{Offall();P0=0xfe;delayms(50);P1=0xfe;delayms(50);P1=0xfc;delayms(50);P1=0xf8;delayms(50);P1=0xf0;delayms(50);P1=0xe0;delayms(50);P1=0xc0;delayms(50);P1=0x80;delayms(50);P1=0x00;delayms(50);P3=0xfe;delayms(50);P3=0xfc;delayms(50);P3=0xf8;delayms(50);P3=0xf0;delayms(50);P3=0xe0;delayms(50);P3=0xc0;delayms(50);P3=0x80;delayms(50);P3=0x00;delayms(50);P2=0xfe;delayms(50);P2=0xfc;delayms(50);P2=0xf8;delayms(50);P2=0xf0;delayms(50);P2=0xe0;delayms(50);P2=0xc0;delayms(50);P2=0x80;delayms(50);P2=0x00;delayms(50);P0=0x7e;delayms(50);P0=0x3e;delayms(50);P0=0x1e;delayms(50);P0=0x0e;delayms(50);P0=0x06;delayms(50);P0=0x02;delayms(50);P0=0x00;delayms(50);Offall();delayms(100);Onall();delayms(100);Offall();delayms(100);Onall();delayms(500);Offall();delayms(100);}//void fxsw() //反向死亡//{// Onall();// P0=0x01;delayms(50); // P0=0x03;delayms(50); // P0=0x07;delayms(50); // P0=0x0f;delayms(50);// P0=0x1f;delayms(50);// P0=0x3f;delayms(50);// P0=0x7f;delayms(50);// P0=0xff;delayms(50);//// P2=0x80;delayms(50); // P2=0xc0;delayms(50); // P2=0xe0;delayms(50); // P2=0xf0;delayms(50);// P2=0xf8;delayms(50);// P2=0xfc;delayms(50);// P2=0xff;delayms(50);//// P3=0x80;delayms(50);// P3=0xc0;delayms(50);// P3=0xe0;delayms(50);// P3=0xf0;delayms(50);// P3=0xf8;delayms(50);// P3=0xfc;delayms(50);// P3=0xfe;delayms(50);// P3=0xff;delayms(50);//// P1=0x80;delayms(50);// P1=0xc0;delayms(50);// P1=0xe0;delayms(50);// P1=0xf0;delayms(50);// P1=0xf8;delayms(50);// P1=0xfc;delayms(50);// P1=0xfe;delayms(50);// P1=0xff;delayms(50);//}void c(x) //间隔闪烁x为闪烁间隔时间{Offall();P0=0xaa;P2=0x55;P3=0x55;P1=0x55;delayms(x);P0=0x55;P2=0xaa;P3=0xaa;P1=0xaa;delayms(x);}/*----------------------------------------------------------*/void cx() //出现一点点{Offall();delayms(500);P0=0xff;P2=0xff;P1=0xbf;P3=0xff;delayms(500);P0=0xdf;P2=0xbf;P1=0xbf;P3=0xff;delayms(500);P0=0xdb;P2=0xbd;P1=0xbf;P3=0xfb;delayms(500);P0=0x59;P2=0xa5;P1=0x5d;P3=0x9a;delayms(500);P0=0x11;P2=0x20;P1=0x24;P3=0x10;delayms(500);P0=0x00;P2=0x00;P1=0x00;P3=0x00;delayms(500); }//void df() //单飞//{// P0=0xfe;delayms(50);// P0=0xfc;delayms(50);// P0=0xf0;delayms(50);// P0=0xe0;delayms(50);// P0=0xc0;delayms(50);// P0=0x80;delayms(50);// P0=0x00;delayms(50);//先引出单飞//// P0=0x01;delayms(50);// P0=0x03;delayms(50);// P0=0x07;delayms(50);// P0=0x0f;delayms(50);// P0=0x1f;delayms(50);// P0=0x3f;delayms(50);// P0=0x7f;delayms(50);// P0=0xff;delayms(50);//// P2=0x7f;delayms(50);// P2=0x3f;delayms(50);// P2=0x1f;delayms(50);// P2=0x0f;delayms(50);// P2=0xf7;delayms(50);// P2=0xf3;delayms(50);// P2=0xf1;delayms(50);// P2=0xf0;delayms(50);//// P3=0x7f;delayms(50);// P2=0x80;delayms(50);// P2=0xc0;delayms(50);// P2=0xe0;delayms(50);// P2=0xf0;delayms(50);// P2=0xf8;delayms(50);// P2=0xfc;delayms(50);// P2=0xfe;delayms(50);// P2=0xff;delayms(50);//// P3=0x7f;delayms(50);// P3=0x3f;delayms(50);// P3=0x1f;delayms(50);// P3=0x0f;delayms(50);// P3=0x07;delayms(50);// P3=0x03;delayms(50);// P3=0x01;delayms(50);// P3=0x00;delayms(50);//// P3=0xc0;delayms(50);// P3=0xe0;delayms(50);// P3=0xf0;delayms(50);// P3=0xf8;delayms(50);// P3=0xfc;delayms(50);// P3=0xfe;delayms(50);// P3=0xff;delayms(50);//// P1=0x7f;delayms(50);// P1=0x3f;delayms(50);// P1=0x1f;delayms(50);// P1=0x0f;delayms(50);// P1=0x07;delayms(50);// P1=0x03;delayms(50);// P1=0x01;delayms(50);// P1=0x00;delayms(50);//// P0=0x01;delayms(50);// P1=0x80;delayms(50);// P1=0xc0;delayms(50);// P1=0xe0;delayms(50);// P1=0xf0;delayms(50);// P1=0xf8;delayms(50);// P1=0xfc;delayms(50);// P1=0xfe;delayms(50);// P1=0xff;delayms(50);////}/*----------------------------------------------------------*/ void cdP00() //沉淀语句{P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0xff;P0=0x7f;delayms(30);P0=0xbf;delayms(30);P0=0xef;delayms(30);P0=0xf7;delayms(30);P0=0xfb;delayms(30);P0=0xfd;delayms(30);P0=0xfe;delayms(30);}//P00void cdP01(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x7e;delayms(30);P0=0xbe;delayms(30);P0=0xde;delayms(30);P0=0xee;delayms(30);P0=0xf6;delayms(30);P0=0xfa;delayms(30);P0=0xfc;delayms(30);}//P01void cdP02(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x7c;delayms(30);P0=0xbc;delayms(30);P0=0xdc;delayms(30);P0=0xf4;delayms(30);P0=0xf8;delayms(30);}//P02void cdP03(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x78;delayms(30);P0=0xb8;delayms(30);P0=0xd8;delayms(30);P0=0xe8;delayms(30);P0=0xf0;delayms(30);}//P03void cdP04(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x70;delayms(30);P0=0xb0;delayms(30);P0=0xd0;delayms(30);P0=0xe0;delayms(30);}//P04void cdP05(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x60;delayms(30);P0=0xa0;delayms(30);P0=0xc0;delayms(30);}//P05void cdP06(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x40;delayms(30);P0=0x80;delayms(30);}//P06void cdP07(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);P2=0xff;P0=0x00;delayms(30);}//P07void cdP27(){P3=0x7f;delayms(30);P3=0xff;P2=0xfe;delayms(30);P2=0xfd;delayms(30);P2=0xfb;delayms(30);P2=0xf7;delayms(30);P2=0xef;delayms(30);P2=0xdf;delayms(30);P2=0xbf;delayms(30);P2=0x7f;delayms(30);}//P27void cdP26(){P3=0x7e;delayms(30);//P3=0xff;P2=0x7e;delayms(30);P2=0x7d;delayms(30);P2=0x7b;delayms(30);P2=0x77;delayms(30);P2=0x6f;delayms(30);P2=0x5f;delayms(30);P2=0x3f;delayms(30);}//P26void cdP25(){P3=0x7c;delayms(30);//P3=0xff;P2=0x3e;delayms(30);P2=0x3d;delayms(30);P2=0x3b;delayms(30);P2=0x37;delayms(30);P2=0x2f;delayms(30);P2=0x1f;delayms(30);}//P25void cdP24(){P3=0x78;delayms(30);//P3=0xff;P2=0x1e;delayms(30);P2=0x1d;delayms(30);P2=0x1b;delayms(30);P2=0x17;delayms(30);P2=0x0f;delayms(30);}//P24void cdP23(){P3=0x70;delayms(30);//P3=0xff;P2=0x0e;delayms(30);P2=0x0d;delayms(30);P2=0x0b;delayms(30);P2=0x07;delayms(30);}//P23void cdP22(){P3=0x60;delayms(30);//P3=0xff;P2=0x06;delayms(30);P2=0x05;delayms(30);P2=0x03;delayms(30);}//P22void cdP21(){P3=0x20;delayms(30);//P3=0xff;P2=0x02;delayms(30);P2=0x01;delayms(30);}//P21void cdP20(){P3=0x00;delayms(30);//P3=0xff;P2=0x00;delayms(30);}//P20void cdP10(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30) ;P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0xff;P1=0x7f;delayms(30);P1=0xbf;delayms(30);P1=0xdf;delayms(30);P1=0xef;delayms(30);P1=0xf7;delayms(30);P1=0xfb;delayms(30);P1=0xfd;delayms(30);P1=0xfe;delayms(30);}//P10void cdP11(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x7e;delayms(30);P1=0xbe;delayms(30);P1=0xde;delayms(30);P1=0xee;delayms(30);P1=0xf6;delayms(30);P1=0xfa;delayms(30);P1=0xfc;delayms(30);}//P11void cdP12(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x7c;delayms(30);P1=0xbc;delayms(30);P1=0xdc;delayms(30);P1=0xec;delayms(30);P1=0xf4;delayms(30);P1=0xf8;delayms(30);}//P12void cdP13(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x78;delayms(30);P1=0xb8;delayms(30);P1=0xd8;delayms(30);P1=0xe8;delayms(30);P1=0xf0;delayms(30);}//P13void cdP14(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x70;delayms(30);P1=0xb0;delayms(30);P1=0xd0;delayms(30);P1=0xe0;delayms(30);}//P14void cdP15(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x60;delayms(30);P1=0xa0;delayms(30);P1=0xc0;delayms(30);}//P15void cdP16(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x40;delayms(30);P1=0x80;delayms(30);}//P16void cdP17(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);P3=0xff;P1=0x00;delayms(30);}//P17void cdP30(){P3=0x7f;delayms(30);P3=0xbf;delayms(30);P3=0xdf;delayms(30);P3=0xef;delayms(30);P3=0xf7;delayms(30);P3=0xfb;delayms(30);P3=0xfd;delayms(30);P3=0xfe;delayms(30);}//P30void cdP31(){P3=0x7e;delayms(30);P3=0xbe;delayms(30);P3=0xde;delayms(30);P3=0xee;delayms(30);P3=0xf6;delayms(30);P3=0xfa;delayms(30);P3=0xfc;delayms(30); }//P31void cdP32(){P3=0x7c;delayms(30);P3=0xbc;delayms(30);P3=0xdc;delayms(30);P3=0xec;delayms(30);P3=0xf4;delayms(30);P3=0xfb;delayms(30); }//P32void cdP33(){P3=0x78;delayms(30);P3=0xb8;delayms(30);P3=0xd8;delayms(30);P3=0xe8;delayms(30);P3=0xf0;delayms(30); }//P33void cdP34(){P3=0x70;delayms(30);P3=0xb0;delayms(30);P3=0xd0;delayms(30);P3=0xe0;delayms(30); }//P34void cdP35(){P3=0x60;delayms(30);P3=0xa0;delayms(30);P3=0xc0;delayms(30);}//P35void cdP36(){P3=0x40;delayms(30);P3=0x80;delayms(30);}//P36void cdP37(){P3=0x00;delayms(30);}//P37/*----------------------------------------------------------*/ void cd() //由下至上沉淀{cdP00();cdP10();cdP01();cdP11();cdP02();cdP12();cdP03();cdP13();cdP04();cdP14();cdP05();cdP15();cdP06();cdP16();cdP07();cdP17();cdP27();cdP30();cdP26();cdP31();cdP25();cdP32();cdP24();cdP33();cdP23();cdP34();cdP22();cdP35();cdP21();cdP36();cdP20();cdP37();delayms(500);Offall();delayms(300);Onall();delayms(300);Offall();delayms(300);Onall();delayms(300);}/*----------------------------------------------------------*/ void szsx() //左右同时生长(由上至下){Offall();P0=0xfe;delayms(50);P0=0xfc;delayms(50);P1=0xfe;delayms(50);P0=0xf8;delayms(50);P1=0xfc;delayms(50);P0=0xf0;delayms(50);P1=0xf8;delayms(50);P0=0xe0;delayms(50);P1=0xf0;delayms(50);P0=0xc0;delayms(50);P1=0xe0;delayms(50);P0=0x80;delayms(50);P1=0xc0;delayms(50);P0=0x00;delayms(50);P1=0x80;delayms(50);P2=0x7f;delayms(50);P1=0x00;delayms(50);P2=0x3f;delayms(50);P3=0xfe;delayms(50);P2=0x1f;delayms(50);P3=0xfc;delayms(50);P2=0x0f;delayms(50);P3=0xf8;delayms(50);P2=0x07;delayms(50);P3=0xf0;delayms(50);P2=0x03;delayms(50);P3=0xe0;delayms(50);P2=0x01;delayms(50);P3=0xc0;delayms(50);P2=0x00;delayms(50);P3=0x80;delayms(50);P3=0x00;delayms(50);}/*----------------------------------------------------------*/void szxs() //左右同时生长(由下至上){Offall();P3=0x7f;delayms(50);P2=0xfe;delayms(50);P3=0x3f;delayms(50);P2=0xfc;delayms(50);P3=0x1f;delayms(50);P2=0xf8;delayms(50);P3=0x0f;delayms(50);P2=0xf0;delayms(50);P3=0x07;delayms(50);P2=0xe0;delayms(50);P3=0x03;delayms(50);P2=0xc0;delayms(50);P3=0x01;delayms(50);P2=0x80;delayms(50);P3=0x00;delayms(50);P2=0x00;delayms(50);P1=0x7f;delayms(50);P0=0x7f;delayms(50);P1=0x3f;delayms(50);P0=0x3f;delayms(50);P1=0x1f;delayms(50);P0=0x1f;delayms(50);P1=0x0f;delayms(50);P0=0x0f;delayms(50);P1=0x07;delayms(50);P0=0x07;delayms(50);P1=0x03;delayms(50);P0=0x03;delayms(50);P1=0x01;delayms(50);P0=0x01;delayms(50);P1=0x00;delayms(50);P0=0x00;delayms(50);}/*----------------------------------------------------------*/void l1d() //1个灯转{P0=0xfe,P2=0x7f,P3=0x7f,P1=0x7f;delayms(50);P0=0xfd,P2=0xbf,P3=0xbf,P1=0xbf;delayms(50);P0=0xfb,P2=0xdf,P3=0xdf,P1=0xdf;delayms(50);P0=0xf7,P2=0xef,P3=0xef,P1=0xef;delayms(50);P0=0xef,P2=0xf7,P3=0xf7,P1=0xf7;delayms(50);P0=0xdf,P2=0xfb,P3=0xfb,P1=0xfb;delayms(50);P0=0xbf,P2=0xfd,P3=0xfd,P1=0xfd;delayms(50);P0=0x7f,P2=0xfe,P3=0xfe,P1=0xfe;delayms(50); }/*----------------------------------------------------------*/ void l2d() //2个灯转{P0=0xfc,P2=0x3f,P3=0x3f,P1=0x3f;delayms(50);P0=0xf9,P2=0x9f,P3=0x9f,P1=0x9f;delayms(50);P0=0xf3,P2=0xcf,P3=0xcf,P1=0xcf;delayms(50);P0=0xe7,P2=0xe7,P3=0xe7,P1=0xe7;delayms(50);P0=0xcf,P2=0xf3,P3=0xf3,P1=0xf3;delayms(50);P0=0x9f,P2=0xf9,P3=0xf9,P1=0xf9;delayms(50);P0=0x3f,P2=0xfc,P3=0xfc,P1=0xfc;delayms(50);P0=0x7e,P2=0x7e,P3=0x7e,P1=0x7e;delayms(50); }/*----------------------------------------------------------*/ void l3d() //3个灯转{P0=0xf8,P2=0x1f,P3=0x1f,P1=0x1f;delayms(50);P0=0xf1,P2=0x8f,P3=0x8f,P1=0x8f;delayms(50);P0=0xe3,P2=0xc7,P3=0xc7,P1=0xc7;delayms(50);P0=0xc7,P2=0xe3,P3=0xe3,P1=0xe3;delayms(50);P0=0x8f,P2=0xf1,P3=0xf1,P1=0xf1;delayms(50);P0=0x1f,P2=0xf8,P3=0xf8,P1=0xf8;delayms(50);P0=0x3e,P2=0x7c,P3=0x7c,P1=0x7c;delayms(50);P0=0x7c,P2=0x3e,P3=0x3e,P1=0x3e;delayms(50);}/*----------------------------------------------------------*/ void l4d() //4个灯转{P0=0xf0,P2=0x0f,P3=0x0f,P1=0x0f;delayms(50);P0=0xe1,P2=0x87,P3=0x87,P1=0x87;delayms(50);P0=0xc3,P2=0xc3,P3=0xc3,P1=0xc3;delayms(50);P0=0x87,P2=0xe1,P3=0xe1,P1=0xe1;delayms(50);P0=0xaf,P2=0xf0,P3=0xf0,P1=0xf0;delayms(50);P0=0x1e,P2=0x78,P3=0x78,P1=0x78;delayms(50);P0=0x3c,P2=0x3c,P3=0x3c,P1=0x3c;delayms(50);P0=0x78,P2=0x1e,P3=0x1e,P1=0x1e;delayms(50);}/*----------------------------------------------------------*/void l5d() //5个灯转{P0=0xe0,P2=0x07,P3=0x07,P1=0x07;delayms(50);P0=0xc1,P2=0x83,P3=0x83,P1=0x83;delayms(50);P0=0x83,P2=0xc1,P3=0xc1,P1=0xc1;delayms(50);P0=0x87,P2=0xe0,P3=0xe0,P1=0xe0;delayms(50);P0=0x0e,P2=0x70,P3=0x70,P1=0x70;delayms(50);P0=0x1c,P2=0x38,P3=0x38,P1=0x38;delayms(50);P0=0x38,P2=0x1c,P3=0x1c,P1=0x1c;delayms(50);P0=0x70,P2=0x0e,P3=0x0e,P1=0x0e;delayms(50);}/*----------------------------------------------------------*/void l6d() //6个灯转{P0=0xc0,P2=0x03,P3=0x03,P1=0x03;delayms(50);P0=0x81,P2=0x81,P3=0x81,P1=0x81;delayms(50);P0=0x03,P2=0xc0,P3=0xc0,P1=0xc0;delayms(50);P0=0x06,P2=0x60,P3=0x60,P1=0x60;delayms(50);P0=0x0c,P2=0x30,P3=0x30,P1=0x30;delayms(50);P0=0x18,P2=0x18,P3=0x18,P1=0x18;delayms(50);P0=0x30,P2=0x0c,P3=0x0c,P1=0x0c;delayms(50);P0=0x60,P2=0x06,P3=0x06,P1=0x06;delayms(50);}void main() //主函数,由于模块化设计,只要修改下面各模块的排列顺序和时间,就可以实现各种变化模式{while(1) //无限循环{cx();//一点点出现rja(); //渐暗Onall();delayms(100);Offall();delayms(100);Onall();delayms(180);Offall();delayms(180);Onall();delayms(180);Offall();delayms(300);Onall();delayms(300);rja(); //渐暗delayms(300);// for(x=10;x>0;x--)// ss(100);/* 闪烁20次,50ms */// //ls(); /* 正向流水*/rjl();Offall();delayms(100);zxsz(); /* 正向生长*/delayms(500);rja();//渐暗rzmzy(); //拖尾从上到下rzmyy(); //拖尾从下到上for(x=6;x>0;x--) /*P00闪烁6次50ms*/{P0=0xfe,delayms(50);P0=0xff,delayms(50);}szsx(); /* 半双边生长,由上至下*/rja();//渐暗for(x=10;x>0;x--)ss(100);/* 闪烁20次,50ms */Offall();rzmnwyd();delayms(100);//走马内外移动函数//l1d(),l2d(),l3d(),l4d(),l5d(),l6d(),Onall(),delayms(50);//1至6个灯转rja();//渐暗for(x=6;x>0;x--) /*P00闪烁6次50ms*/{P0=0xfe,delayms(50);P0=0xff,delayms(50);}bsb();//双边同时流水由上至下szxs(); /* 半双边生长,由下至上*/rja();//渐暗ss(100); /* 闪烁10次*/l1d(),l2d(),l3d(),l4d(),l5d(),l6d(),Onall(),delayms(50);//1至6个灯转l1d(),l2d(),l3d(),l4d(),l5d(),l6d(),Onall(),delayms(50);//1至6个灯转Onall();delayms(200);c(700),c(600),c(500);//间隔闪烁c(400),c(300),c(200);c(100),c(100),c(100),c(100);c(50),c(50),c(50),c(50);Offall();for(x=10;x>0;x--){ss(100);}/* 闪烁*/rzmzy(); //拖尾从上到下szxs();/* 半双边生长,由下至上*/szsx(); /* 半双边生长,由上至下*/rja(); //渐暗delayms(100);rzmzy(); //拖尾从上到下//fbsb();/* 半双边流水由下至上*/for(x=10;x>0;x--){P3=0x7f;delayms(50);Offall();delayms(50); /* P37闪烁6次,50ms */ }cd(); /* 由下至上沉淀*///fxsw(); /* 反向死亡*/rja(); //渐暗rzmyy(); //拖尾从下到上bsb();//双边同时流水由上至下// fxsz();Offall(); /* 反向生长*/szsx();/* 左右同时生长由上至下*/rja();delayms(200);for(x=20;x>0;x--){ss(100);} /* 闪烁20次*/rjl(); //渐亮delayms(500);rja(); //渐暗rzmyy(); //拖尾从下到上szsx(); /* 半双边生长,由上至下*/Offall();delayms(100);rjl(); //渐亮Offall();delayms(500); //开启所有灯2sfor(x=20;x>0;x--){c(100);} /* 闪烁20次*/l1d(),l2d(),l3d(),l4d(),l5d(),l6d(),Onall(),delayms(50);//1至6个灯转l1d(),l2d(),l3d(),l4d(),l5d(),l6d(),Onall(),delayms(50);//1至6个灯转for(x=3;x>0;x--){Onall();delayms(200);Offall();delayms(200);}Onall();delayms(500);rja(); //渐暗delayms(100);rzmzy(); //拖尾从上到下rzmyy(); //拖尾从下到上szsx();/* 左右同时生长由上至下*/delayms(300);rja(); //渐暗rjl(); //渐亮delayms(300);rzmnwyd(); //走马内外移动delayms(300);rja(); //渐暗delayms(300);rtbyd(); //眨眼rtbyd(); //眨眼Onall();delayms(180);Offall();delayms(180);Onall();delayms(180);Offall();delayms(180);Onall();delayms(500);Offall();delayms(300);szsx();/* 左右同时生长由上至下*/delayms(300);szsx();/* 左右同时生长由上至下*/rja();delayms(1000);Onall();delayms(2000);}}void rzmyy() //走马拖尾右移函数{Offall();delayms(200);P3=0x7f;delayms(60);P3=0xbf;P2=0xfe;if(P37==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P37 = 0;for(i = 0; i < 15; i++); //调节亮度高低P37 = 1;for(i = 0; i < 50; i++);}}P3=0xdf;P2=0xfd;if(P36==1 && P20==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P36 = 0;P20 = 0;for(i = 0; i < 15; i++); //调节亮度高低P37 = 0;for(i = 0; i < 1; i++); //调节亮度高低P36 = 1;P20 = 1;P37 = 1;for(i = 0; i < 50; i++);}}P3=0xef;P2=0xfb;if(P35==1 && P21 ==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P35 = 0;P21 = 0;for(i = 0; i < 15; i++); //调节亮度高低{P36 = 0;P20 = 0;}for(i = 0; i < 1; i++); //调节亮度高低P35 = 1;P21 = 1;P36 = 1;P20 = 1;for(i = 0; i < 50; i++);}}P3=0xf7;P2=0xf7;if(P34==1 && P22 == 1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P34 = 0;P22 = 0;for(i = 0; i < 15; i++); //调节亮度高低{P35 = 0;P21 = 0;}for(i = 0; i < 1; i++); //调节亮度高低P34 = 1;P22 = 1;P35 = 1;P21 = 1;for(i = 0; i < 50; i++);}}P3=0xfb;P2=0xef;if(P33==1 && P23==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P33 = 0;P23 = 0;for(i = 0; i < 15; i++); //调节亮度高低{P34 = 0;P22 = 0;for(i = 0; i < 1; i++); //调节亮度高低P33 = 1;P23 = 1;P34 = 1;P22 = 1;for(i = 0; i < 50; i++);}}P3=0xfd;P2=0xdf;if(P32==1 && P24==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P32 = 0;P24 = 0;for(i = 0; i < 15; i++); //调节亮度高低{P33 = 0;P24 = 0;}for(i = 0; i < 1; i++); //调节亮度高低P32 = 1;P24 = 1;P33 = 1;P23 = 1;for(i = 0; i < 50; i++);}}P3=0xfe;//P3^0P2=0xbf;//P2^6if(P31==1 && P25==1){unsigned int a;for(a=0;a<350;a++) //调节点亮时间{unsigned char i;P31 = 0;P25 = 0;for(i = 0; i < 15; i++); //调节亮度高低P32 = 0;。
单片机流水灯c语言实现
//------------------------------------------------
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code DSY_CODE []=
red_a=1;yellow_a=1;green_a=0;
red_b=0;yellow_b=1;green_b=1;
delayMs(2000);
Operation_Type=2;
break;
case 2://东西向黄灯开始闪烁,绿灯关闭
delayMs(300);
yellow_a=!yellow_a; green_a=1;
while(x--)
{
for(i=0;i<120;i++);
}
}
//---------------------------------------------
//交通灯切换子程序
void Traffic_Light()
{
switch (Operation_Type)
{
case 1://东西向绿灯亮与南北向红灯亮
{
uchar i;
P2=0x01;//P2端口初始化
while(1)//死循环
{
for(i=0;i<7;i++)//i自加1,当i=7时执行第二个for语句
{
P2=_crol_(P2,1);//P2端口循环左移1位
delayMs(150);
}
for(i=0;i<7;i++)
51心形流水灯代码
51心形流水灯代码#include //调用reg52头文件void delay(unsigned int t);//定义延时函数void one();//定义流水一函数void two();//定义流水二函数void three();//定义流水三函数void four();//定义流水四函数void five();//定义流水五函数void six();//定义流水六函数void seven();//定义流水七函数void eight();//定义流水八函数void night();//定义流水九函数void ten();//定义流水十函数void eleven();//定义流水十一函数void twelve();//定义流水十二函数void thirteen();//定义流水十三函数void fouteen();//定义流水十四函数sbit led00=P0^0;sbit led01=P0^1;sbit led02=P0^2;sbit led03=P0^3;sbit led04=P0^4;sbit led05=P0^5;sbit led10=P1^0;sbit led11=P1^1;sbit led12=P1^2;sbit led13=P1^3;sbit led14=P1^4;sbit led15=P1^5;sbit led20=P2^0;sbit led21=P2^1;sbit led22=P2^2;sbit led23=P2^3;sbit led24=P2^4;sbit led25=P2^5;sbit led30=P3^0;sbit led31=P3^1;sbit led32=P3^2;sbit led33=P3^3;sbit led34=P3^4;sbit led35=P3^5;void main()//主函数开启{unsigned int i;one();//执行流水一two();//执行流水二three();//执行流水三four();//执行流水四five();//执行流水五six();//执行流水六seven();//执行流水七eight();//执行流水八night();//执行流水九ten();//执行流水十eleven();//执行流水十一twelve();//执行流水十二thirteen();//执行流水十三fouteen();//执行流水十四for(i=0;i<3;i++){P0=0xF0;P1=0xE1;P2=0xE0;P3=0x03;delay(65000);P0=P1=P2=P3=0xFF;delay(65000);}while(1){led00=led01=led02=led03=led11=led12=led13=led14=led 32=led33=led34=led35=led20=led21=led22=led23=led24=0;led10=led15=led30=led31=led04=led05=led25=0;delay(30000);led10=led15=led30=led31=led04=led05=led25=1;delay(30000);}}////////////////////////////////////////////////////////我是分割线1(全灯闪亮三次)////////////////////////////////////////////////// void one()//编写流水一函数{unsigned int i;for(i=0;i<3;i++){P0=P1=P2=P3=0x00;//P0口全熄delay(30000);//延时P0=P1=P2=P3=0xFF;//P0口全熄delay(40000);//延时}}/////////////////////////////////////////////////////////我是分割线2(逆时针转一圈)//////////////////////////////////////////////////////void two()//编写流水二{unsigned char code table[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF};//定义数组unsigned char code table1[]={0xDF,0xEF,0xF7,0xFB,0xFD,0xFE};//定义数组unsigned int i;for(i=0;i<6;i++){P1=table[i];delay(20000);//延时}P1=0xFF;for(i=0;i<6;i++){P3=table[i];delay(20000);//延时}P3=0xFF;for(i=0;i<6;i++){P2=table[i];delay(20000);//延时}P2=0xFF;for(i=0;i<6;i++){P0=table1[i];delay(20000);//延时}P0=0xFF;}////////////////////////////////////////////////////////我是分割线3(顺时针转一圈)//////////////////////////////////////////////////////////// void three()//编写流水三{unsigned char code table[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF};//定义数组unsigned char code table1[]={0xDF,0xEF,0xF7,0xFB,0xFD,0xFE};//定义数组unsigned int i;P1=0xFE;delay(20000);P1=0xFF;for(i=0;i<6;i++){P0=table[i];delay(20000);//延时}P0=0xFF;for(i=0;i<6;i++){P2=table1[i];delay(20000);//延时}P2=0xFF;for(i=0;i<6;i++){P3=table1[i];delay(20000);//延时}P3=0xFF;for(i=0;i<6;i++){P1=table1[i];delay(20000);//延时}P0=0xFF;}////////////////////////////////////////////////////////我是分割线4(左半圈依次全亮)//////////////////////////////////////////////////////////// void four()//编写流水四{unsigned char code table[]={0xFE,0xFC,0xF8,0xF0,0xE0,0xC0};//定义数组unsigned int i;for(i=0;i<6;i++){P1=table[i];delay(30000);//延时}for(i=0;i<6;i++){P3=table[i];delay(30000);//延时}P2=0xFE;delay(30000);P1=P3=0xFF;//P0口全熄P0=P2=0x00;delay(30000);P0=P2=0xFF;}////////////////////////////////////////////////////////我是分割线5(右半圈依次点亮)//////////////////////////////////////////////////////////// void five()//编写流水五{unsigned char code table[]={0xFE,0xFC,0xF8,0xF0,0xE0,0xC0};//定义数组unsigned char codetable1[]={0xdf,0xcf,0xc7,0xc3,0xc1,0xc0};//定义数组unsigned int i;P1=0xFE;delay(30000);for(i=0;i<6;i++){P0=table[i];delay(30000);//延时}for(i=0;i<6;i++){P2=table1[i];delay(30000);//延时}P0=P2=0xFF;//P0口全熄P1=P3=0x00;//P0口全熄delay(30000);//延时P1=P3=0xFF;}////////////////////////////////////////////////////////我是分割线6//////////////////////////////////////////////////////////// void six()//编写流水六{unsigned char code table[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xFF};//定义数组unsigned char code table1[]={0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF};//定义数组unsigned int i;for(i=0;i<7;i++){P1=table[i];delay(20000);//延时P3=table[i];delay(20000);//延时P2=table[i];delay(20000);//延时P0=table1[i];delay(20000);//延时}}////////////////////////////////////////////////////////我是分割线7//////////////////////////////////////////////////////////// void seven()//编写流水七{unsigned char code table[]={0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0xFF};//定义数组unsigned char code table1[]={0xFF,0xFE,0xFC,0xF8,0xF0,0xE0,0xFF};//定义数组unsigned int i;for(i=0;i<7;i++){P1=table[i];P0=table1[i];delay(30000);}P0=0xE0;P1=0xC0;delay(60000);P2=P3=0xC0;P1=0xFF;P0=0xDF;delay(60000);}////////////////////////////////////////////////////////我是分割线8//////////////////////////////////////////////////////////// void eight()//编写流水8{unsigned char code table[]={0xF8,0xC7};//定义数组unsigned char code table1[]={0xC7,0xF8};//定义数组unsigned int i,j;for(j=0;j<2;j++){for(i=0;i<2;i++){P1=P2=P3=table[i];P0=table1[i];delay(30000);}}}////////////////////////////////////////////////////////我是分割线9//////////////////////////////////////////////////////////// void night()//编写流水9{unsigned char code table[]={0xFC,0xF3,0xCF};//定义数组unsigned char code table1[]={0xCF,0xF3,0xFC};//定义数组unsigned int i;for(i=0;i<3;i++){P1=P2=P3=table[i];P0=table1[i];delay(30000);}}////////////////////////////////////////////////////////我是分割线10//////////////////////////////////////////////////////////// void ten()//编写流水10{unsigned char code table[]={0xFE,0xFC,0xF8,0xF0,0xE0,0xC0};//定义数组unsigned char code table1[]={0xDF,0xCF,0xC7,0xC3,0xC1,0xC0};//定义数组unsigned int i;for(i=0;i<6;i++){P1=table[i];delay(10000);//延时}for(i=0;i<6;i++){P3=table[i];delay(10000);//延时}for(i=0;i<6;i++){P2=table[i];delay(10000);//延时}for(i=0;i<6;i++){P0=table1[i];delay(10000);//延时}}////////////////////////////////////////////////////////我是分割线11//////////////////////////////////////////////////////////// void eleven()//编写流水11{unsigned char code table[]={0xFE,0xFC,0xF8,0xF0,0xE0,0xC0};//定义数组unsigned char code table1[]={0xDF,0xCF,0xC7,0xC3,0xC1,0xC0};//定义数组unsigned int i;P1=0xFE;delay(10000);for(i=0;i<6;i++){P0=table[i];delay(10000);//延时}for(i=0;i<6;i++){P2=table1[i];delay(10000);//延时}for(i=0;i<6;i++){P3=table1[i];delay(10000);//延时}for(i=0;i<6;i++){P1=table1[i];delay(10000);//延时}}////////////////////////////////////////////////////////我是分割线12蝴蝶闪////////////////////////////////////////////////////////////void twelve()//编写流水12{unsigned int i;for(i=0;i<12;i++){P1=P3=0x00;P2=0xFE;delay(15000);P1=P2=P3=0xFF;P1=0xFE;P0=P2=0x00;delay(15000);P0=P1=P2=0xFF;}}////////////////////////////////////////////////////////我是分割线13////////////////////////////////////////////////////////////void thirteen()//编写流水十三{unsigned char code table[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF};//定义数组unsigned char code table1[]={0xDF,0xEF,0xF7,0xFB,0xFD,0xFE};//定义数组unsigned int i,j;for(j=0;j<3;j++) {for(i=0;i<6;i++) {P3=0x00;P1=table[i]; delay(20000);//延时}P1=P3=0xFF;for(i=0;i<6;i++) {P2=0x00;P3=table[i]; delay(25000);//延时}P2=P3=0xFF;for(i=0;i<6;i++) {P0=0x00;P2=table[i]; delay(30000);//延时}P0=P2=0xFF;for(i=0;i<6;i++) {P1=0x00;P0=table1[i]; delay(35000);//延时}P0=P1=0xFF;}}/////////////////////////////////////////////////////////我是分割线14////////////////////////////////////////////////////// void fouteen()//编写流水十四{unsigned char code table[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF};//定义数组unsigned char code table1[]={0xDF,0xEF,0xF7,0xFB,0xFD,0xFE};//定义数组unsigned int i,j;for(j=0;j<3;j++){P1=0xFE;delay(20000);P1=0xFF;for(i=0;i<6;i++){P2=0x00;P0=table[i];delay(20000);//延时}P0=P2=0xFF;for(i=0;i<6;i++){P3=0x00;P2=table1[i];delay(25000);//延时}P2=P3=0xFF;for(i=0;i<6;i++){P1=0x00;P3=table1[i];delay(30000);//延时}P1=P3=0xFF;for(i=0;i<6;i++){P0=0x00;P1=table1[i];delay(35000);//延时}P0=P1=0xFF;}}/////////////////////////////////////////////////////////我是分割线15////////////////////////////////////////////////////// void delay(unsigned int t)//编写延时函数{while(--t);}。
基于51单片机的C语言程序设计
基于51单片机的C语言程序设计实训100例第 01 篇基础程序设计01 闪烁的LED/* 名称:闪烁的LED说明:LED按设定的时间间隔闪烁*/#include<reg51.h>#define uchar unsigned char#define uint unsigned intsbit LED=P1^0;//延时void DelayMS(uint x){uchar i;while(x--){for(i=0;i<120;i++);}}//主程序void main(){while(1){LED=~LED;DelayMS(150);}}02 从左到右的流水灯/* 名称:从左到右的流水灯说明:接在P0口的8个LED从左到右循环依次点亮,产生走马灯效果*/#include<reg51.h>#include<intrins.h>#define uchar unsigned char#define uint unsigned intvoid DelayMS(uint x){uchar i;while(x--){for(i=0;i<120;i++);}}//主程序void main(){P0=0xfe;while(1){P0=_crol_(P0,1); //P0的值向左循环移动DelayMS(150);}}03 8只LED左右来回点亮/* 名称:8只LED左右来回点亮说明:程序利用循环移位函数_crol_和_cror_形成来回滚动的效果*/#include<reg51.h>#include<intrins.h>#define uchar unsigned char#define uint unsigned int//延时void DelayMS(uint x){uchar i;while(x--){for(i=0;i<120;i++);}}//主程序void main(){uchar i;P2=0x01;while(1){{P2=_crol_(P2,1); //P2的值向左循环移动DelayMS(150);}for(i=0;i<7;i++){P2=_cror_(P2,1); //P2的值向右循环移动DelayMS(150);}}}04 花样流水灯/* 名称:花样流水灯说明:16只LED分两组按预设的多种花样变换显示*/#include<reg51.h>#define uchar unsignedchar#define uint unsigned intuchar code Pattern_P0[]={0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xe7,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7,0xff, 0xaa,0x55,0x18,0xff,0xf0,0x0f,0x00,0xff,0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x3f,0x7f, 0x7f,0x3f,0x1f,0x8f,0xc7,0xe3,0xf1,0xf8,0xff,0x00,0x00,0xff,0xff,0x0f,0xf0,0xff, 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe, 0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe, 0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff};uchar code Pattern_P2[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0xff, 0xe7,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7,0xff, 0xaa,0x55,0x18,0xff,0xf0,0x0f,0x00,0xff,0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x3f,0x7f, 0x7f,0x3f,0x1f,0x8f,0xc7,0xe3,0xf1,0xf8,0xff,0x00,0x00,0xff,0xff,0x0f,0xf0,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, 0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00, 0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff//延时void DelayMS(uint x){uchar i;while(x--){for(i=0;i<120;i++);}}//主程序void main(){uchar i;while(1){ //从数组中读取数据送至P0和P2口显示for(i=0;i<136;i++){P0=Pattern_P0[i];P2=Pattern_P2[i];DelayMS(100);}}}05 LED模拟交通灯/* 名称:LED模拟交通灯说明:东西向绿灯亮若干秒,黄灯闪烁5次后红灯亮,红灯亮后,南北向由红灯变为绿灯,若干秒后南北向黄灯闪烁5此后变红灯,东西向变绿灯,如此重复。
简单的51单片机花样流水灯C语言源代码
简单的51单片机花样流水灯C语言源代码#include //51系列单片机定义文件#define uchar unsigned char //定义无符号字符#define uint unsigned int //定义无符号整数void Delayms(uint x){ //定义延时函数uint i,j;for(i=x;i>0;i--)for(j=110;j>0;j--);}void main(){uint i;uchar temp;while(1){temp=0x01; //8个流水灯逐个闪动for(i=0;i<8;i++){P0=~temp;Delayms(50);temp<<=1;}temp=0x80; //8个流水灯反向逐个闪动for(i=0;i<8;i++){P0=~temp;Delayms(50);temp>>=1;}temp=0xfe; //8个流水灯依次全部点亮for(i=0;i<8;i++){P0=temp;Delayms(50);temp<<=1;}temp=0x7f; //8个流水灯依次反向全部点亮for(i=0;i<8;i++){P1=temp;Delayms(50);temp>>=1;}}}//此程序的作者向往未来#include#include#define uint unsigned int #define uchar unsigned char uchar z=50,e=0x00,f=0xff; uchar code table1[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};uchar code table2[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00}; uchar code table3[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};uchar code table4[]={0xe7,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,0xff}; uchar code table5[]={0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7,0xff};uchar code table6[]={0x7e,0x3c,0x18,0x00, 0x18,0x3c,0x7e,0xff}; void delay(uchar); void lsd1();void lsd2();void lsd3();void lsd4();void lsd5();void lsd6();void lsd7();void lsd8();void lsd9();void lsd10();void lsd11();void lsd12();main(){while(1){lsd1();lsd2();lsd3();lsd4();lsd5();lsd6();lsd7();lsd8();lsd9();lsd10();lsd11();lsd12();}}void delay(uchar x) //延时函数{uint i,j;for(i=x;i>0;i--)for(j=250;j>0;j--);}void lsd1() //lsd1 单个流水灯双程模式1 {uchar a,i,j,k,l,l1,k1,j1,i1;a=0xfe;P0=a;delay(z);for(i=0;i<7;i++) //仅单个灯亮从上往下流{a=_crol_(a,1);P0=a;delay(z);}P0=0xff;a=0xfe;P2=a;delay(z);for(j=0;j<7;j++){a=_crol_(a,1);P2=a;delay(z);}P2=0xff;a=0xfe;P3=a;delay(z);for(k=0;k<7;k++){a=_crol_(a,1);P3=a;delay(z);}P3=0xff;a=0xfe;P1=a;delay(z);for(l=0;l<7;l++){a=_crol_(a,1);P1=a;delay(z);}a=0xbf;P1=a;delay(z);for(l1=0;l1<6;l1++) //l1==6 仅单个灯亮从下往上流{a=_cror_(a,1);P1=a;delay(z);}a=0x7f;P3=a;delay(z);for(k1=0;k1<7;k1++) {a=_cror_(a,1);P3=a;delay(z);}P3=0xff;a=0x7f;P2=a;delay(z);for(j1=0;j1<7;j1++) {a=_cror_(a,1);P2=a;delay(z);}P2=0xff;a=0x7f;P0=a;delay(z);for(i1=0;i1<7;i1++) {a=_cror_(a,1);P0=a;}P0=0xff;}void lsd2() //lsd2 两个灯流水双程模式1 {uchar a,i,j,k,l,l1,k1,j1,i1;a=0xfe;P0=a;delay(z);a=a<<1;P0=a;delay(z);for(i=0;i<6;i++){a=_crol_(a,1);P0=a;delay(z);}P0=0x7f;P2=0xfe;delay(z);P0=0xff;a=0xfc;P2=a;delay(z);for(j=0;j<6;j++){a=_crol_(a,1);P2=a;}P2=0x7f;P3=0xfe;delay(z);P2=0xff;a=0xfc;P3=a;delay(z);for(k=0;k<6;k++) {a=_crol_(a,1);P3=a;delay(z);}P3=0x7f;P1=0xfe;delay(z);P3=0xff;a=0xfc;P1=a;delay(z);for(l=0;l<6;l++) {a=_crol_(a,1);P1=a;delay(z);}P1=0x7f;delay(z);delay(z);a=0x7f;P1=a;delay(z);a=a>>1;P1=a;delay(z);for(l1=0;l1<6;l1++) {a=_cror_(a,1);P1=a;delay(z);}P1=0xfe;P3=0x7f;delay(z);P1=0xff;a=0x3f;P3=a;delay(z);for(k1=0;k1<6;k1++) {a=_cror_(a,1);P3=a;delay(z);}P3=0xfe;P2=0x7f;delay(z);P3=0xff;a=0x3f;P2=a;delay(z);for(j1=0;j1<6;j1++){a=_cror_(a,1);P2=a;delay(z);}P2=0xfe;P0=0x7f;delay(z);P2=0xff;a=0x3f;P0=a;delay(z);for(i1=0;i1<6;i1++){a=_cror_(a,1);P0=a;delay(z);}P0=0xfe;delay(z);P0=0xff;delay(z);}void lsd3() //lsd3 两个灯流水双程模式2 {uchar a,i,j,k,l,l1,k1,j1,i1;a=0xfe;P0=a;delay(z);a=a<<1;P0=a;delay(z);for(i=0;i<6;i++) //_crol_与_cror_混合使用{a=_crol_(a,1);P0=a;delay(z);}P0=0x7f;a=0x7f;P2=a;delay(z);P0=f;a=a>>1;P2=a;delay(z);for(j=0;j<6;j++){a=_cror_(a,1);P2=a;delay(z);}P2=0xfe;a=0xfe;P3=a;delay(z);P2=f;a=a<<1;P3=a;delay(z);for(k=0;k<6;k++) {a=_crol_(a,1);P3=a;delay(z);}P3=0x7f;a=0x7f;P1=a;delay(z);P3=f;a=a>>1;P1=a;delay(z);for(l=0;l<6;l++) {a=_cror_(a,1);P1=a;delay(z);}P1=0xfe;delay(z);P1=f;delay(z);a=0xfe;delay(z);a=a<<1;P1=a;delay(z);for(l1=0;l1<6;l1++) //l1==6 {a=_crol_(a,1);P1=a;delay(z);}P1=0x7f;a=0x7f;P3=a;delay(z);P1=f;a=a>>1;P3=a;for(k1=0;k1<6;k1++){a=_cror_(a,1);P3=a;delay(z);}P3=0xfe;a=0xfe;P2=a;delay(z);P3=f;a=a<<1;delay(z);for(j1=0;j1<6;j1++) {a=_crol_(a,1);P2=a;delay(z);}P2=0x7f;a=0x7f;P0=a;delay(z);P2=f;a=a>>1;P0=a;delay(z);for(i1=0;i1<6;i1++) {a=_cror_(a,1);P0=a;delay(z);}P0=0xfe;delay(z);P0=f;delay(z);}void lsd4() //lsd4{uchar a,i,j,k,l,l1,k1,j1,i1;P0=a;delay(z);for(i=0;i<7;i++){a=a<<1; //单个灯依次点亮所有灯,从上往下P0=a;delay(z);}a=0xfe;P2=a;delay(z);for(j=0;j<7;j++){a=a<<1;P2=a;delay(z);}a=0xfe;P3=a;delay(z);for(k=0;k<7;k++){a=a<<1;P3=a;delay(z);}a=0xfe;P1=a;for(l=0;l<7;l++){a=a<<1;P1=a;delay(z);}for(l1=0;l1<8;l1++) //l1==8{P1=table1[l1]; //单个灯依次熄灭所有灯,从下往上delay(z);}for(k1=0;k1<8;k1++){P3=table1[k1];delay(z);}for(j1=0;j1<8;j1++){P2=table1[j1];delay(z);}for(i1=0;i1<8;i1++){P0=table1[i1];delay(z);}}void lsd5() //lsd5{uchar a,i,j,k,l,l1,k1,j1,i1;a=0xfe;P0=a;delay(z);for(i=0;i<7;i++){a=a<<1;P0=a;delay(z);}for(j=0;j<8;j++) //单个灯依次点亮所有灯,从下往上{P2=table2[j];delay(z);}a=0xfe;P3=a;delay(z);for(k=0;k<7;k++){a=a<<1;P3=a;delay(z);}for(l=0;l<8;l++){P1=table2[l];delay(z);}for(l1=0;l1<8;l1++) //单个灯依次熄灭所有灯,从上往下{P1=table3[l1];delay(z);}for(k1=0;k1<8;k1++){P3=table1[k1];delay(z);}for(j1=0;j1<8;j1++) //单个灯依次熄灭所有灯,从上往下{P2=table3[j1];delay(z);}for(i1=0;i1<8;i1++){P0=table1[i1];delay(z);}}void lsd6() //每组为单位同亮同灭从左向右再向左{P0=0x00;delay(z);P0=0xff;P2=0x00;delay(z);P2=0xff;P3=0x00;delay(z);P3=0xff;P1=0x00;delay(z);P3=0x00;P1=0xff;delay(z);P2=0x00;P3=0xff;delay(z);P0=0x00;P2=0xff;delay(z);P0=0xff;delay(z);}void lsd7() //lsd7 全亮全灭{uchar i;for(i=0;i<2;i++){P0=0x00;P1=0x00;P2=0x00;P3=0x00;delay(z);P0=0xff;P1=0xff;P2=0xff;P3=0xff;delay(z);}}void lsd8() //每组仅两个灯,从中间往两边再往中间{uchar i;for(i=0;i<8;i++){P0=table4[i];P1=table4[i];P2=table4[i];P3=table4[i];delay(z);}}void lsd9() //每组两个灯引亮所有灯再引灭,从中间带两边再到中间{uchar i;for(i=0;i<8;i++){P0=table5[i];P1=table5[i];P2=table5[i];P3=table5[i];delay(z);}}void lsd10(){uchar a,i,j;a=0xfe;P0=a;P1=a;P2=a;P3=a;delay(z);for(i=0;i<7;i++) //仅单个灯亮从上往下流{a=_crol_(a,1);P0=a;P1=a;P2=a;P3=a;delay(z);}for(j=0;j<7;j++) //仅单个灯亮从上往下流{a=_cror_(a,1);P0=a;P1=a;P2=a;P3=a;delay(z);}P0=f;P1=f;P2=f;P3=f;delay(z);void lsd11() {uchar a,i,j;a=0xfe;P0=a;P1=a;P2=a;P3=a;delay(z);for(i=0;i<7;i++) {a=a<<1;P0=a;P1=a;P2=a;P3=a;delay(z);}for(j=0;j<8;j++) {P0=table1[j];P1=table1[j];P2=table1[j];P3=table1[j]; delay(z);}}void lsd12()uchar a,i,j,k,l;a=0xfe;P0=a;P1=a;delay(z);for(i=0;i<7;i++) {a=a<<1;P0=a;P1=a;delay(z);}a=0x7f;P2=a;P3=a;delay(z);for(j=0;j<7;j++) {a=a>>1;P2=a;P3=a;delay(z);}for(k=0;k<8;k++) {P2=table3[k];P3=table3[k]; delay(z);}for(l=0;l<8;l++) {P0=table1[l];P1=table1[l]; delay(z);}while(1);}。
51单片机流水灯程序
char code table4[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,};//P0123 一个灯走动
char code table5[]={0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,};//P0123 两个灯走动
char code table6[]={0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,};//P0123 三个灯走动
for(j=0;j<8;j++)//P0123 一条龙一个灯走动
{ P0=table4[j];
delay(5);
} P0=0xff;
for(j=0;j<8;j++)//P0123 一条龙一个灯走动
{ P2=table4[j];
delay(5);
}
P0=0xff;P1=0xff;P2=0xff;P3=0xff;
for(j=0;j<7;j++)//P0123 两个灯走动
{ P0=table5[j];
P1=table5[j];
P2=table5[j];
P3=table5[j];
for(j=1;j<7;j++)//P0123 一条龙两个灯走动
{ P2=table5[j];
delay(5);
{ P0=table10[j];
P1=table10[j];
P2=table10[j];
P3=table10[j];
delay(5);
} P0=0x00;P1=0x00;P2=0x00;P3=0x00;delay(5);
51单片机流水灯程序
51单片机流水灯程序// 51 单片机的心形流水灯 #include unsigned int x,y; void delayms(unsigned int z) //延时程序 { unsigned int i,j; for(i=z;i>0;i--) for(j=110;j>0;j--); } /*----------------------------------------------------------*/ void Offall() //开启所有灯 { P0=0x00; P1=0x00; P2=0x00; P3=0x00; P4=0X00; P5=0X00; } /*----------------------------------------------------------*/ void Onall()//关闭所有灯 { P0=0xff; P1=0xff; P2=0xff; P3=0xff; P4=0XFF; P5=0XFF; } /*----------------------------------------------------------*/ void ls()//等时流水灯 { P0=0x00; P0=0x01; delayms(50); P0=0x02; delayms(50); P0=0x04; delayms(50) ; P0=0x08; delayms(50) ; P0=0x10;delayms(50) ; P0=0x20; delayms(50); P0=0x40; delayms(50) ; P0=0x80; delayms(50); P0=0x00; P2=0x00; P2=0x80; delayms(50) ; P2=0x40; delayms(50);P2=0x20; delayms(50) ; P2=0x10; delayms(50) ; P2=0x08; delayms(50) ; P2=0x04; delayms(50); P2=0x02; delayms(50) ; P2=0x01; delayms(50); P2=0x00; P3=0x00;P3=0x80; delayms(50) ; P3=0x40; delayms(50); P3=0x20; delayms(50) ; P3=0x10; delayms(50) ; P3=0x08; delayms(50) ; P3=0x04; delayms(50); P3=0x02;delayms(50) ; P3=0x01; delayms(50); P3=0x00;P1=0x00; P1=0x80; delayms(50) ; P1=0x40; delayms(50); P1=0x20;delayms(50) ; P1=0x10; delayms(50) ; P1=0x08; delayms(50) ; P1=0x04;delayms(50); P1=0x02; delayms(50) ; P1=0x01; delayms(50); P1=0x00; P0=0x01; delayms(50); P0=0x00; } /*----------------------------------------------------------*/ void fxls()//反向等时流水灯 { P0=0x00; P0=0x01; delayms(50); P0=0x00; P1=0x00; P1=0x01;delayms(50); P1=0x02;delayms(50); P1=0x04;delayms(50);P1=0x08;delayms(50); P1=0x10;delayms(50); P1=0x20;delayms(50);P1=0x40;delayms(50); P1=0x80;delayms(50); P1=0x00; P3=0x00;P3=0x01;delayms(50); P3=0x02;delayms(50); P3=0x04;delayms(50);P3=0x08;delayms(50);P3=0x10;delayms(50); P3=0x20;delayms(50); P3=0x40;delayms(50);P3=0x80;delayms(50); P3=0x00; P2=0x00; P2=0x01;delayms(50);P2=0x02;delayms(50); P2=0x04;delayms(50); P2=0x08;delayms(50);P2=0x10;delayms(50); P2=0x20;delayms(50); P2=0x40;delayms(50);P2=0x80;delayms(50); P4=0X00; P4=0x01;delayms(50); P4=0x02;delayms(50);P4=0x04;delayms(50); P4=0x08;delayms(50); P4=0x10;delayms(50);P4=0x20;delayms(50); P4=0x40;delayms(50); P4=0x80;delayms(50); P4=0X00;P2=0x00; P0=0x00; P0=0x80;delayms(50); P0=0x40;delayms(50);P0=0x20;delayms(50); P0=0x10;delayms(50); P0=0x08;delayms(50);P0=0x04;delayms(50); P0=0x02;delayms(50); P0=0x01;delayms(50); P0=0x00; } /*----------------------------------------------------------*/ void bsb()//半双边流水由上至下 { Offall(); P0=0x01;delayms(50); P0=0x02;P1=0x01;delayms(50);P0=0x04;P1=0x02;delayms(50);P0=0x08;P1=0x04;delayms(50); P0=0x10;P1=0x08;delayms(50);P0=0x20;P1=0x10;delayms(50); P0=0x40;P1=0x20;delayms(50);P0=0x80;P1=0x40;delayms(50);P0=0x00; P2=0x80;P1=0x80;delayms(50);P1=0x00;P2=0x40;P3=0x01;delayms(50); P2=0x20;P3=0x02;delayms(50);P2=0x10;P3=0x04;delayms(50); P2=0x08;P3=0x08;delayms(50);P2=0x04;P3=0x10;delayms(50); P2=0x02;P3=0x20;delayms(50); P2=0x01;P3=0x40;delayms(50);Offall(); P3=0x80;delayms(50);Offall(); } /*----------------------------------------------------------*/ void fbsb() //半双边流水由下至上 { Offall();P3=0x80;delayms(50); P2=0x01;P3=0x40;delayms(50); P2=0x02;P3=0x20;delayms(50); P2=0x04;P3=0x10;delayms(50); P2=0x08;P3=0x08;delayms(50);P2=0x10;P3=0x04;delayms(50); P2=0x20;P3=0x02;delayms(50);P2=0x40;P3=0x01;delayms(50);Offall(); P2=0x80;P1=80;delayms(50);Offall();P0=0x80;P1=0x40;delayms(50); P0=0x40;P1=0x20;delayms(50);P0=0x20;P1=0x10;delayms(50); P0=0x10;P1=0x08;delayms(50);P0=0x08;P1=0x04;delayms(50); P0=0x04;P1=0x02;delayms(50);P0=0x02;P1=0x01;delayms(50);Offall(); P0=0x01;Offall(); } void zxsz() //正向生长 { Offall(); P0=0x01;delayms(50); P0=0x03;delayms(50); P0=0x07;delayms(50);P0=0x0f;delayms(50); P0=0x1f;delayms(50); P0=0x3f;delayms(50);P0=0x7f;delayms(50); P0=0xff;delayms(50); P2=0x80;delayms(50);P2=0xc0;delayms(50); P2=0xe0;delayms(50); P2=0xf0;delayms(50);P2=0xf8;delayms(50); P2=0xfc;delayms(50); P2=0xfe;delayms(50);P2=0xff;delayms(50); P3=0x80;delayms(50); P3=0xc0;delayms(50);P3=0xe0;delayms(50); P3=0xf0;delayms(50); P3=0xf8;delayms(50);P3=0xfc;delayms(50); P3=0xfe;delayms(50); P3=0xff;delayms(50);P1=0x80;delayms(50); P1=0xc0;delayms(50); P1=0xe0;delayms(50);P1=0xf0;delayms(50); P1=0xf8;delayms(50); P1=0xfc;delayms(50);P1=0xfe;delayms(50); P1=0xff;delayms(50); } /*----------------------------------------------------------*/ void fxsz() //反向生长 { Offall();P0=0x01;delayms(50); P1=0x01;delayms(50); P1=0x03;delayms(50);P1=0x07;delayms(50); P1=0x0f;delayms(50); P1=0x1f;delayms(50);P1=0x3f;delayms(50); P1=0x7f;delayms(50);P1=0xff;delayms(50); P3=0x01;delayms(50); P3=0x03;delayms(50);P3=0x07;delayms(50); P3=0x0f;delayms(50); P3=0x1f;delayms(50);P3=0x3f;delayms(50); P3=0x7f;delayms(50); P3=0xff;delayms(50);P2=0x01;delayms(50); P2=0x03;delayms(50); P2=0x07;delayms(50);P2=0x0f;delayms(50); P2=0x1f;delayms(50); P2=0x3f;delayms(50);P2=0x7f;delayms(50); P2=0xff;delayms(50); P0=0x81;delayms(50);P0=0xc1;delayms(50); P0=0xe1;delayms(50); P0=0xf1;delayms(50);P0=0xf9;delayms(50); P0=0xfd;delayms(50); P0=0xff;delayms(50); } /*----------------------------------------------------------*/ void zxsw() //正向死亡{ Onall(); P0=0xfd;delayms(50); P0=0xf9;delayms(50); P0=0xf1;delayms(50);P0=0xf0;delayms(50); P0=0xe1;delayms(50); P0=0xc1;delayms(50);P0=0x81;delayms(50); P0=0x01;delayms(50); P2=0x7f;delayms(50);P2=0x3f;delayms(50); P2=0x1f;delayms(50); P2=0x0f;delayms(50);P2=0x07;delayms(50); P2=0x03;delayms(50); P2=0x01;delayms(50);P2=0x00;delayms(50); P3=0x7f;delayms(50); P3=0x3f;delayms(50);P3=0x1f;delayms(50); P3=0x0f;delayms(50); P3=0x07;delayms(50);P3=0x03;delayms(50); P3=0x01;delayms(50); P3=0x00;delayms(50);P1=0x7f;delayms(50); P1=0x3f;delayms(50); P1=0x1f;delayms(50);P1=0x0f;delayms(50); P1=0x07;delayms(50); P1=0x03;delayms(50);P1=0x01;delayms(50); P1=0x00;delayms(50); P0=0x00;delayms(50);}/*----------------------------------------------------------*/ void fxsw() //反向死亡 { Onall(); P1=0xfe;delayms(50); P1=0xfc;delayms(50);P1=0xf8;delayms(50); P1=0xf0;delayms(50); P1=0xe0;delayms(50);P1=0xc0;delayms(50); P1=0x80;delayms(50); P1=0x00;delayms(50);P3=0xfe;delayms(50); P3=0xfc;delayms(50); P3=0xf8;delayms(50);P3=0xf0;delayms(50); P3=0xe0;delayms(50);P3=0xc0;delayms(50); P3=0x80;delayms(50); P3=0x00;delayms(50);P2=0xfe;delayms(50); P2=0xfc;delayms(50); P2=0xf8;delayms(50);P2=0xf0;delayms(50); P2=0xe0;delayms(50); P2=0xc0;delayms(50);P2=0x80;delayms(50); P2=0x00;delayms(50); P0=0x7f;delayms(50);P0=0x3f;delayms(50); P0=0x1f;delayms(50); P0=0x0f;delayms(50);P0=0x07;delayms(50); P0=0x03;delayms(50); P0=0x01;delayms(50);P0=0x00;delayms(50); } /*----------------------------------------------------------*/ void bbs()//半边交替闪{ Offall();P0=0x00;P2=0xff;P3=0x80;delayms(200);Offall();P0=0xfe;P1=0xff;P3=0x ff;delaym s(200); } /*----------------------------------------------------------*/ void sxs()//上下交替闪{ Offall();P1=0xff;P0=0x00;P2=0x80;delayms(200);Offall();P2=0x7f;P3=0xff;delay ms(200); } void cx() //出现一点点 {Offall();delayms(1000); P0=0x00;P2=0x00;P1=0x40;P3=0x00;delayms(1000);P0=0x20;P2=0x40;P1=0x40;P3=0x00;delayms(1000);P0=0x24;P2=0x42;P1=0x40;P3=0x04;delayms(1000);P0=0xa6;P2=0x5a;P1=0x52;P3=0x65;delayms(1000); P0=0xee;P2=0xdf;P1=0xdb;P3=0xef; delayms(1000); P0=0xff;P2=0xff;P1=0xff;P3=0xff;delayms(1000); } void xs(){ Onall();delayms(1000); P0=0xee;P2=0xdf;P1=0xdb;P3=0xef; delayms(1000);P0=0xa6;P2=0x5a;P1=0x52;P3=0x65;delayms(1000);P0=0x24;P2=0x42;P1=0x40;P3=0x04;delayms(1000);P0=0x20;P2=0x40;P1=0x40;P3=0x00;delayms(1000);P0=0x00;P2=0x00;P1=0x40;P3=0x00;delayms(1000);Offall();delayms(1000); } void main() { Onall(); delayms(1000); Offall(); delayms(1000); cx();//一点点出现xs(); zxsw();/* 正向死亡*/ ls(); /* 正向流水 */ zxsz();/* 正向生长 */ zxsw();/* 正向死亡 */ //一点点消失fxsz();/* 反向生长 */ fxsw(); /* 反向死亡 */ fxls(); /* 反向流水*/ bsb();/* 半双边流水由上至下 */ fbsb();/* 半双边流水由下至上 */ sxs(); bbs(); }。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Delayms(50);
temp>>=1;
}
}
}
//此程序的作者 向往未来
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
}
P3=0xfe;
a=0xfe;
P2=a;
delay(z);
P3=f;
a=a<<1;
P2=a;
delay(z);
for(j1=0;j1<6;j1++)
{
a=_crol_(a,1);
P2=a;
delay(z);
}
P2=0x7f;
a=0x7f;
P0=a;
void Delayms(uint x)
{ //定义延时函数
uint i,j;
for(i=x;i>0;i--)
for(j=11ቤተ መጻሕፍቲ ባይዱ;j>0;j--);
}
void main(){
uint i;
uchar temp;
while(1){
uchar a,i,j,k,l,l1,k1,j1,i1;
a=0xfe;
P0=a;
delay(z);
for(i=0;i<7;i++) //仅单个灯亮从上往下流
{
a=_crol_(a,1);
P0=a;
delay(z);
}
P0=0xff;
a=0xfe;
P2=a;
a=a<<1;
P0=a;
delay(z);
for(i=0;i<6;i++)
{
a=_crol_(a,1);
P0=a;
delay(z);
}
P0=0x7f;
P2=0xfe;
delay(z);
P0=0xff;
a=0xfc;
P2=a;
delay(z);
temp>>=1;
}
temp=0xfe; //8个流水灯依次全部点亮
for(i=0;i<8;i++){
P0=temp;
Delayms(50);
temp<<=1;
}
temp=0x7f; //8个流水灯依次反向全部点亮
for(i=0;i<8;i++){
void lsd12();
main()
{
while(1)
{
lsd1();
lsd2();
lsd3();
lsd4();
lsd5();
lsd6();
lsd7();
lsd8();
lsd9();
lsd10();
lsd11();
lsd12();
{
a=_cror_(a,1);
P0=a;
delay(z);
}
P0=0xfe;
delay(z);
P0=0xff;
delay(z);
}
void lsd3() //lsd3 两个灯流水双程模式2
{
uchar a,i,j,k,l,l1,k1,j1,i1;
delay(z);
for(j1=0;j1<6;j1++)
{
a=_cror_(a,1);
P2=a;
delay(z);
}
P2=0xfe;
P0=0x7f;
delay(z);
P2=0xff;
a=0x3f;
P0=a;
delay(z);
for(i1=0;i1<6;i1++)
delay(z);
P1=0xff;
a=0x3f;
P3=a;
delay(z);
for(k1=0;k1<6;k1++)
{
a=_cror_(a,1);
P3=a;
delay(z);
}
P3=0xfe;
P2=0x7f;
delay(z);
P3=0xff;
a=0x3f;
P2=a;
0x07,0x03,0x01,0x00};
uchar code table3[]={
0x01,0x03,0x07,0x0f,
0x1f,0x3f,0x7f,0xff};
uchar code table4[]={
0xe7,0xdb,0xbd,0x7e,
0xbd,0xdb,0xe7,0xff};
P2=a;
delay(z);
P0=f;
a=a>>1;
P2=a;
delay(z);
for(j=0;j<6;j++)
{
a=_cror_(a,1);
P2=a;
delay(z);
}
P2=0xfe;
a=0xfe;
P3=a;
delay(z);
P2=f;
a=a<<1;
for(j=0;j<6;j++)
{
a=_crol_(a,1);
P2=a;
delay(z);
}
P2=0x7f;
P3=0xfe;
delay(z);
P2=0xff;
a=0xfc;
P3=a;
delay(z);
for(k=0;k<6;k++)
{
a=_crol_(a,1);
}
}
void delay(uchar x) //延时函数
{
uint i,j;
for(i=x;i>0;i--)
for(j=250;j>0;j--);
}
void lsd1() //lsd1 单个流水灯双程模式1
{
=a;
delay(z);
}
P0=0xff;
}
void lsd2() //lsd2 两个灯流水双程模式1
{
uchar a,i,j,k,l,l1,k1,j1,i1;
a=0xfe;
P0=a;
delay(z);
P1=0xff;
delay(z);
a=0x7f;
P1=a;
delay(z);
a=a>>1;
P1=a;
delay(z);
for(l1=0;l1<6;l1++)
{
a=_cror_(a,1);
P1=a;
delay(z);
}
P1=0xfe;
P3=0x7f;
uchar code table5[]={
0xe7,0xc3,0x81,0x00,
0x81,0xc3,0xe7,0xff};
uchar code table6[]={
0x7e,0x3c,0x18,0x00,
0x18,0x3c,0x7e,0xff};
void delay(uchar);
{
a=_cror_(a,1);
P1=a;
delay(z);
}
P1=0xff;
a=0x7f;
P3=a;
delay(z);
for(k1=0;k1<7;k1++)
{
a=_cror_(a,1);
P3=a;
delay(z);
}
P3=0xff;
a=0x7f;
P2=a;
delay(z);
{
uchar a,i,j,k,l,l1,k1,j1,i1;
a=0xfe;
P0=a;
delay(z);
for(i=0;i<7;i++)
{
a=a<<1; //单个灯依次点亮所有灯,从上往下
P0=a;
delay(z);
}
a=0xfe;
P2=a;
{
a=_cror_(a,1);
P1=a;
delay(z);
}
P1=0xfe;
delay(z);
P1=f;
delay(z);
a=0xfe;
P1=a;
delay(z);
a=a<<1;
P1=a;
delay(z);
for(l1=0;l1<6;l1++) //l1==6
{
a=_crol_(a,1);
P1=a;
delay(z);
}
P1=0x7f;
a=0x7f;
P3=a;
delay(z);