1、#include#include #define uint unsigned int#define uchar unsigned char/延时void delay(uint k) uint i,j;for(i=k;i-;i0)for(j=100;j-;j0);void main()uchar temp0,temp1;uchar yi;uchar yi0,yi1; uint i,j,k,a,b;j=k=a=b=3;/全部亮P0=P1=P2=P3=0x00;delay(700);P0=P1=P2=P3=0xff;/每个 io 口独自亮for(i=2;i-;i0)P1=P0=0x00;delay(
2、500);P1=P0=0xff;P3=P2=0x00;delay(500);P3=P2=0xff;/全部亮,闪三次for(i=2;i-;i0)P0=P1=P2=P3=0x00;delay(100);P0=P1=P2=P3=0xff;delay(100);/P1、P2 亮,P3、P0 暗for(i=3;i-;i0)P1=0x00,P2=0x00; P3=0xff,P0=0xff;delay(500);P1=0xff,P2=0xff,P3=0x00,P0=0x00;delay(500);/四个点的流水while(j0)temp0=0xfe,temp1=0x7f;P1=P3=temp0,P2=P0=
3、temp1;delay(100);for(i=7;i-;i0)temp0=_crol_(temp0,1),temp1=_cror_(temp1,1);P1=P3=temp0,P2=P0=temp1;delay(100); j-;/全部亮,闪三次for(i=3;i-;i0)P0=P1=P2=P3=0x00;delay(300);P0=P1=P2=P3=0xff;delay(300); /四个 IO 口同样跟踪流水while(k0)temp0=0xfe,temp1=0x7f;P1=P3=temp0,P2=P0=temp1;delay(60);for(i=7;i-;i0)temp0=temp01;P
4、1=P3=temp0,P2=P0=temp1;delay(60);k-;P0=P1=P3=P2=0xff;while(k0)temp0=temp01,temp1=temp10)yi=_crol_(yi,1);P1=P0=yi;delay(50);P1=P0=0xff;yi=0xfe;P3=P2=yi;delay(50);for(i=7;i-;i0)yi=_crol_(yi,1);P3=P2=yi;delay(50);P3=P2=0Xff;/两边单个返回流水for(i=7;i-;i0) yi=_cror_(yi,1);P3=P2=yi;delay(50);P3=P2=0xff;for(i=7;i
5、-;i0)yi=_cror_(yi,1);P0=P1=yi;delay(50); /全部亮,闪三次P0=P1=P3=P2=0xff;for(i=3;i-;i0)P0=P1=P2=P3=0x00;delay(100);P0=P1=P2=P3=0xff;delay(100);/流水灯yi0=0xfe,yi1=0x7f;P3=P2=yi1,P1=P0=yi0;delay(100);for(i=7;i-;i0)yi0=yi01;P1=P0=yi0,P3=P2=yi1;delay(100);P1=P2=P3=P0=0xff;delay(200);yi0=0x7f,yi1=0xfe;P1=P0=yi0,P
6、3=P2=yi1;for(i=7;i-;i0)yi0=yi01,yi1=yi10)P1=P10)P3=P30)P2=P21;delay(50);for(i=8;i-;i0)P0=P01;delay(50);/逆向大循环跟踪流水P1=P2=P3=P0=0xff;for(i=8;i-;i0)P0=P00)P2=P20)P3=P31;delay(50);for(i=8;i-;i0)P1=P11;delay(50); /全部亮,闪三次P0=P1=P3=P2=0xff;for(i=4;i-;i0)P0=P1=P2=P3=0x00;delay(100);P0=P1=P2=P3=0xff;delay(100
7、);/全部亮,只有一个暗的在流水temp0=0x01,temp1=0x00;P1=P0=temp0,P3=P2=temp1;delay(100);for(i=7;i-;i0)temp0=_crol_(temp0,1);P1=P0=temp0;delay(100);P1=P0=0x00;temp1=0x01;P3=P2=temp1;delay(100);for(i=7;i-;i0)temp1=_crol_(temp1,1);P3=P2=temp1;delay(100);/全部亮,逆向一个暗在流水temp0=0x00,temp1=0x80;P1=P0=temp0,P3=P2=temp1;delay
8、(100);for(i=7;i-;i0)temp1=_cror_(temp1,1);P3=P2=temp1;delay(100);P3=P2=0x00;temp0=0x80;P1=P0=temp0;delay(100); for(i=7;i-;i0)temp0=_cror_(temp0,1);P1=P0=temp0;delay(100);/花样temp0=0xaa,temp1=0x55;P1=P3=temp0,P2=P0=temp1;delay(500);for(;a-;a0)for(i=7;i-;i0)temp0=_crol_(temp0,1),temp1=_cror_(temp1,1);P
9、1=P3=temp0,P2=P0=temp1;delay(500);for(;b-;b0)temp0=0xee,temp1=0x77;P1=P3=temp0,P2=P0=temp1;delay(300);for(i=7;i-;i0)temp0=_crol_(temp0,1),temp1=_cror_(temp1,1);P1=P3=temp0,P2=P0=temp1;delay(300); /环形逐个亮P1=P2=P3=P0=0xff;for(i=8;i-;i0)P0=P00)P2=P20)P3=P31;delay(50);for(i=8;i-;i0)P1=P11;delay(50); /逐个熄灭for(i=7;i-;i0)P0=P00)P2=P20)P3=P31;P3=P3;delay(50);P3=0xff;for(i=7;i-;i0)P1=P11;P1=P1;delay(50);P1=0xff; 如需仿真文件,和电路连接,请移步中国电子 DIY 之家论坛 搜 心形流水灯