51流水灯程序,
2. 8个发光管由上至下间隔1s流动,其中每个管亮500ms,灭500ms,亮时蜂鸣器响,
灭时关闭蜂鸣器,一直重复下去。
3. 8个发光管来回流动,第个管亮100ms,流动时让蜂鸣器发出“滴滴”声。 4. 用8个发光管演示出8位二进制数累加过程。 5. 8个发光管间隔200ms由上至下,再由下至上,再重复一次,然后全部熄灭再以300ms
间隔全部闪烁5次。重复此过程。
6. 间隔300ms第一次一个管亮流动一次,第二次两个管亮流动,依次到8个管亮,然
后重复整个过程。
7. 间隔300ms先奇数亮再偶数亮,循环三次;一个灯上下循环三次;两个分别从两边
往中间流动三次;再从中间往两边流动三次;8个全部闪烁3次;关闭发光管,程序停止。
#include #define uchar unsigned char #define uint unsigned int uchar temp,a; uint i,j; sbit beep=P2^3; void delay(int); void main() { while(1) { for(i=0;i<10;i++) { P1=0xfe; delay(150); P1=0xff; delay(150); } temp=0xfe; for(i=0;i<16;i++) { P1=temp; beep=0; delay(380); P1=0xff; temp=_crol_(temp,1); beep=1; delay(380); } for(j=0;j<2;j++) { temp=0xfe; for(i=0;i<8;i++) { P1=temp; beep=0; delay(80); temp=_crol_(temp,1); P1=0xff; beep=1; delay(80); } temp=0xbf; for(i=0;i<7;i++) { P1=temp; beep=0; delay(80); temp=_cror_(temp,1); P1=0xff; beep=1; delay(80); } } a=0x00; for(i=0;i<256;i++) { P1=~a; a++; delay(500); } for(i=0;i<2;i++) { temp=0xfe; for(i=0;i<8;i++) { P1=temp; delay(150); temp=_crol_(temp,1); P1=0xff; delay(150); } temp=0xbf; for(i=0;i<7;i++) { P1=temp; delay(150); temp=_cror_(temp,1); P1=0xff; delay(150); } } P1=0xff; for(i=0;i<10;i++) { P1=~P1; delay(170); } temp=0xfe; j=0; for(i=0;i<8;i++) { j++; P1=temp; delay(150); temp=_crol_(temp,a); P1=0xff; delay(150); } temp=0xfe; //赋初值 for(j=0;j<8;j++) { for(i=0;i<8-j;i++) //左移 { P1=temp; //点亮小灯 delay(150); //延时200毫秒 temp=_crol_(temp,1); //将a变量循环左移一位 } temp=_crol_(temp,j); //补齐,方便下面的左移一位 P1=0xff; //全部关闭 temp=temp<<1; //左移一位让多一个灯点亮 } for(i=0;i<3;i++){ P1=0xaa; //10101010 delay(150); P1=~P1; delay(150); } for(j=0;j<3;j++) { temp=0xfe; for(i=0;i<8;i++) { P1=temp; delay(100); temp=_crol_(temp,1); } temp=0xbf; for(i=0;i<7;i++) { P1=temp; delay(100); temp=_cror_(temp,1); } } for(j=0;j<3;j++) { temp=0xfe; a=0x7f; for(i=0;i<5;i++) { P1=temp&a; delay(100); temp=_crol_(temp,1); a=_cror_(a,1); } } for(j=0;j<3;j++) { temp=0xef; a=0xf7; for(i=0;i<5;i++) { P1=temp&a; delay(100); temp=_crol_(temp,1); a=_cror_(a,1); } } for(j=0;j<3;j++) { P1=0x00; delay(380); P1=0xff; delay(380); } } } void delay(int z) { int x,y; for(x=100;x>0;x--) for(y=z;y>0;y--); } 因篇幅问题不能全部显示,请点此查看更多更全内容