开关控制·计数

这是一个是关于开关控制流水灯方向,以及记录按下按钮的次数以二进制数展示的实列(PS:都是一些很累赘的东西,看看就好)
#include<reg51.h>
#include<intRins.h>
sbit led = P0^0;
sbit bt1 = P3^0;
sbit bt2 = P3^1;
sbit bt3 = P3^2;
sbit bt4 = P3^3;
sbit bt5 = P3^4;
void yshi(i){
 while(i--);
}
unsigned int a = 0 , b = 0 , c = 0 , d = 0 ,e = 0 , i;
void ztai(e,f){
		if(e == 1){
			if(f == 0){
				 P0 = _crol_(P0,1);
			}else{
				 P2 = _crol_(P2,1);
			}
		}else{
			if(f == 0){
				 P0 = _cror_(P0,1);
			}else{
				 P2 = _cror_(P2,1);
			}	
		}
		yshi(20000); 
}
void main(){
//初始值
P0 = 0xfe;
P2 = 0xfe;
i = 0x01;
	while(1){
		//p0流水
		if(bt1 == 0){a = 1;b=0;}//判断按钮工作状态
		if(bt1 == 1&&a == 1){ztai(1,0);}
		if(bt2 == 0){b = 1;a = 0;}
		if(bt2 == 1&&b == 1){ztai(0,0);}
		//P2
		if(bt3 == 0){c = 1;d=0;}
		if(bt3 == 1&&c == 1){ztai(1,1);}
		if(bt4 == 0){d = 1;c = 0;}
		if(bt4 == 1&&d == 1){ztai(0,1);} 
		//p1计数
		if(bt5 == 1){e = 1;}
		if(bt5 == 0&&e==1){
		   P1 = ~i++; 
		   e = 0;
		}
      /*
     int a = 0x00;
		while(1){//关于计数另一种写法
			if(P0^0 == 0){
				while(P0^0 == 0);
				a+=0x01;
			}
			P1=~a;
		}	
      */
	}
}

开关控制·计数