1.实现LED的左右流水灯的代码:#includereg52.hsbitADDR0=P1^0;sbitADDR1=P1^1;sbitADDR2=P1^2;sbitADDR3=P1^3;sbitENLED=P1^4;voidmain(){unsignedinti=0;unsignedcharcnt=0;unsignedintj=0;ENLED=0;ADDR3=1;ADDR2=1;ADDR1=1;ADDR0=0;while(1){if(j==0){P2=~(0x01cnt);for(i=0;i20000;i++);cnt++;if(cnt=8){cnt=0;j=1;}}if(j==1){P2=~(0x80cnt);for(i=0;i20000;i++);cnt++;if(cnt=8){cnt=0;j=0;}}}}2.偶数灯亮,奇数灯灭,然后偶数灯灭,奇数灯亮的闪烁的代码:#includereg52.hunsignedinti;voidmain(){P2=~(0xaa);for(i=0;i60000;i++);P2=~(0x55);for(i=0;i60000;i++);}1.LED的左右流水灯的现象:2.偶数灯亮,奇数灯灭,然后偶数灯灭,奇数灯亮的闪烁的现象: