我们学长布置的任务是写一段代码,独立按键实现常亮,闪烁,流水灯的切换,我希望它运行起来是按第一次常亮,按第二次闪烁,按第三次流水灯,按第四次长亮……,但是我的代码不尽人意,第三次按会熄灭,第四次按才是流水灯,长按至流水灯结束再按才是长亮,求大佬帮我指正
#include <REGX52.H>void Delay(unsigned int xms)//@12.000MHz{while(xms){unsigned char i, j;
i = 195;j = 138;do{while (--j);} while (--i);xms--;}}
void main(){
int count=0;while(1){if(P3_1==0){Delay(1);while(P3_1==0);Delay(1);
switch(count){case 0:P2=0xFE;count=(count+1)%3;break;case 1:while(1){P2_0 = ~P2_0;Delay(1); if(P3_1 == 0){ Delay(1); if(P3_1 == 0){ while(P3_1 == 0); Delay(1); count = (count + 1) % 3; P2 = 0xFF;break; }}}break;case 2:while(1){P2= 0xFE;Delay(1);P2= 0xFD;Delay(1);P2= 0xFB;Delay(1);P2= 0xF7;Delay(1);P2= 0xEF;Delay(1);P2= 0xDF;Delay(1);P2= 0xBF;Delay(1);P2= 0x7F;Delay(1);if(P3_1 == 0){ Delay(1); if(P3_1 == 0){ while(P3_1 == 0); Delay(1); count = (count + 1) % 3;break; }}}
break;}}}}
#include <REGX52.H>void Delay(unsigned int xms)//@12.000MHz{while(xms){unsigned char i, j;
i = 195;j = 138;do{while (--j);} while (--i);xms--;}}
void main(){
int count=0;while(1){if(P3_1==0){Delay(1);while(P3_1==0);Delay(1);
switch(count){case 0:P2=0xFE;count=(count+1)%3;break;case 1:while(1){P2_0 = ~P2_0;Delay(1); if(P3_1 == 0){ Delay(1); if(P3_1 == 0){ while(P3_1 == 0); Delay(1); count = (count + 1) % 3; P2 = 0xFF;break; }}}break;case 2:while(1){P2= 0xFE;Delay(1);P2= 0xFD;Delay(1);P2= 0xFB;Delay(1);P2= 0xF7;Delay(1);P2= 0xEF;Delay(1);P2= 0xDF;Delay(1);P2= 0xBF;Delay(1);P2= 0x7F;Delay(1);if(P3_1 == 0){ Delay(1); if(P3_1 == 0){ while(P3_1 == 0); Delay(1); count = (count + 1) % 3;break; }}}
break;}}}}