您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > 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#includereg52.h#defineuintunsignedintsbitled1=P1^0;voiddelay();voidmain(){while(1){led1=0;delay();led1=1;delay();}}voiddelay(){uintx,y;for(x=200;x0;x--)for(y=100;y0;y--);}2#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharsbitp1=P1^0;uchara;voiddelay();voidmain(){a=0xfe;P1=a;while(1){a=_crol_(a,1);delay();P1=a;delay();}}voiddelay(){uintb;for(b=55000;b0;b--);}3#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharvoiddelay(){uintx,y;for(x=100;x0;x--)for(y=110;y0;y--);}voidmain(){uchara,i;while(1){a=0xfe;for(i=0;i8;i++){P1=a;delay(100);a=_crol_(a,1);}a=0x7f;for(i=0;i8;i++){P1=a;delay(100);a=_cror_(a,1);}}}4#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharvoiddelay(uinta){uintx,y;for(x=a;x0;x--)for(y=110;y0;y--);}voidmain(){ucharb;while(1){b++;P1=~b;delay(200);}}5#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharvoidmain(){uchara,i,j;while(1){for(j=0;j2;j++){a=0xfe;for(i=0;i8;i++){P1=a;delay(200);a=_crol_(a,1);}a=0x7f;for(i=0;i8;i++){P1=a;delay(200);a=_cror_(a,1);}}P1=0xff;for(j=0;j10;j++){delay(300);P1=~P1;}}}voiddelay(){uintx,y;for(x=200;x0;x--)for(y=110;y0;y--);}6#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharvoiddelay(){uintx,y;for(x=300;x0;x--)for(y=110;y0;y--);}voidmain(){uchara,i,j;while(1){a=0xfe;for(j=0;j8;j++){for(i=0;i8-j;i++){P1=a;delay(200);a=_crol_(a,1);}a=_crol_(a,j);P1=0xff;a=a1;}}}7#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharvoiddelay(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voidmain(){uchara,i,j;for(j=0;j3;j++){P1=0x55;delay(300);P1=0xaa;delay(300);}for(j=0;j3;j++){a=0xfe;for(i=0;i8;i++){P1=a;delay(300);a=_crol_(a,1);}}P1=0xff;for(j=0;j3;j++){P1=0x7e;delay(300);P1=0xbd;delay(300);P1=0xdb;delay(300);P1=0xe7;delay(300);}P1=0xff;for(j=0;j3;j++){P1=0xe7;delay(300);P1=0xdb;delay(300);P1=0xbd;delay(300);P1=0x7e;delay(300);}P1=0xff;for(j=0;j6;j++){P1=~P1;delay(300);}P1=0xff;while(1);}
本文标题:51单片机流水灯--程序
链接地址:https://www.777doc.com/doc-1540444 .html