⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shuiben.c

📁 单片机控制水泵实现星三角转换
💻 C
字号:
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define OFF 1
#define ON 0
#define high 0
#define low  1
#define A 1
#define B 0
#define OFF_delay  	600
#define	ON_delay	100
//////////水池1111/////////////
sbit OUT1_A=P3^3;
sbit OUT1_B=P3^2;
sbit H1=P3^7;
sbit M1=P3^6;
sbit L1=P2^0;

//////////水池2222/////////////
sbit OUT2_A=P1^7;
sbit OUT2_B=P1^6;
sbit H2=P2^1;
sbit M2=P2^2;
sbit L2=P2^3;

//////////水池3333/////////////
sbit OUT3_A=P1^5;
sbit OUT3_B=P1^4;
sbit H3=P2^4;
sbit M3=P2^5;
sbit L3=P2^6;

//////////水池4444/////////////
sbit OUT4_A=P1^3;
sbit OUT4_B=P1^2;
sbit H4=P2^7;
sbit M4=P0^7;
sbit L4=P0^6;

//////////水池5555/////////////
sbit OUT5_A=P1^1;
sbit OUT5_B=P1^0;
sbit H5=P0^5;
sbit M5=P0^4;
sbit L5=P0^3;

//////////水池6666/////////////
sbit OUT6_A=P3^4;
sbit OUT6_B=P3^5;
sbit H6=P0^2;
sbit M6=P0^1;
sbit L6=P0^0;

//uchar data1_H,data2_H,data3_H,data4_H,data5_H,data6_H;
//uchar data1_L,data2_L,data3_L,data4_L,data5_L,data6_L;
uchar AB1,AB2,AB3,AB4,AB5,AB6;
uchar ERROR1,ERROR2,ERROR3,ERROR4,ERROR5,ERROR6;
uint time1,time2,time3,time4,time5,time6;
void interruptT1() interrupt 3
{
TH1=0x4C;
TL1=0x00;
if (ERROR1==ON)
	{
	time1++;
	if (time1==ON_delay)
		if(H1==high)
		{
		OUT1_A=ON;
		OUT1_B=ON;
		}
		else
		{
		ERROR1=OFF;
		time1=0;
		}
	if (time1>OFF_delay)
		{
		OUT1_A=OFF;
		OUT1_B=OFF;
		ERROR1=OFF;
		time1=0;
		}
	}

if (ERROR2==ON)
	{
	time2++;
	if (time2==ON_delay)
		if(H2==high)
		{
		OUT2_A=ON;
		OUT2_B=ON;
		}
		else
		{
		ERROR2=OFF;
		time2=0;
		}
	if (time2>OFF_delay)
		{
		OUT2_A=OFF;
		OUT2_B=OFF;
		ERROR2=OFF;
		time2=0;
		}
	}

if (ERROR3==ON)
	{
	time3++;
	if (time3==ON_delay)
		if(H3==high)
		{
		OUT3_A=ON;
		OUT3_B=ON;
		}
		else
		{
		ERROR3=OFF;
		time3=0;
		}
	if (time3>OFF_delay)
		{
		OUT3_A=OFF;
		OUT3_B=OFF;
		ERROR3=OFF;
		time3=0;
		}
	}


if (ERROR4==ON)
	{
	time4++;
	if (time4==ON_delay)
		if(H4==high)
		{
		OUT4_A=ON;
		OUT4_B=ON;
		}
		else
		{
		ERROR4=OFF;
		time4=0;
		}
	if (time4>OFF_delay)
		{
		OUT4_A=OFF;
		OUT4_B=OFF;
		ERROR4=OFF;
		time4=0;
		}
	}


if (ERROR5==ON)
	{
	time5++;
	if (time5==ON_delay)
		if(H5==high)
		{
		OUT5_A=ON;
		OUT5_B=ON;
		}
		else
		{
		ERROR5=OFF;
		time5=0;
		}
	if (time5>OFF_delay)
		{
		OUT5_A=OFF;
		OUT5_B=OFF;
		ERROR5=OFF;
		time5=0;
		}
	}


if (ERROR6==ON)
	{
	time6++;
	if (time6==ON_delay)
		if(H6==high)
		{
		OUT6_A=ON;
		OUT6_B=ON;
		}
		else
		{
		ERROR6=OFF;
		time6=0;
		}
	if (time6>OFF_delay)
		{
		OUT6_A=OFF;
		OUT6_B=OFF;
		ERROR6=OFF;
		time6=0;
		}
	}
}


void Initial (void)
{
P1=0XFF;
P2=0XFF;
P3=0XFF;
P0=0XFF;
AB1=A;
AB2=A;
AB3=A;
AB4=A;
AB5=A;
AB6=A;

ERROR1=OFF;
ERROR2=OFF;
ERROR3=OFF;
ERROR4=OFF;
ERROR5=OFF;
ERROR6=OFF;
time1=0;
time2=0;
time3=0;
time4=0;
time5=0;
time6=0;

TMOD=0x10;
TH1=0x4C;//11.0592m 50ms
TL1=0x00;
ET1=1;
EA=1;
TR1=1;
}


main()
{
Initial ();
while(1)
{
/////////////////////////1111111111111111111/////////////////////////////////
if((L1==high)&&(M1==high)&&(H1==low))//中水位
	{
	if (AB1==A) 	OUT1_A=ON;
	else 		OUT1_B=ON;
	ERROR1=OFF;
	time1=0;
	}
else 
if((L1==high)&&(M1==high)&&(H1==high))//高水位
	{
	OUT1_A=ON;
	OUT1_B=ON;
	ERROR1=OFF;
	time1=0;
	}
else
if((L1==low)&&(M1==low)&&(H1==low)&&(ERROR1==OFF))//低水位
	{
	if ((OUT1_A==ON)|(OUT1_B==ON))
		{
		OUT1_A=OFF;
		OUT1_B=OFF;
		if (AB1==A) AB1=B;
		else 		AB1=A;
		}
	time1=0;
	}	
else ///故障
if (H1==high)//高水位
	{
	ERROR1=ON;
	}	

/////////////////////////2222222222222222222/////////////////////////////////
if((L2==high)&&(M2==high)&&(H2==low))//中水位
	{
	if (AB2==A) 	OUT2_A=ON;
	else 		OUT2_B=ON;
	ERROR2=OFF;
	time2=0;
	}
else 
if((L2==high)&&(M2==high)&&(H2==high))//高水位
	{
	OUT2_A=ON;
	OUT2_B=ON;
	ERROR2=OFF;
	time2=0;
	}
else
if((L2==low)&&(M2==low)&&(H2==low)&&(ERROR2==OFF))//低水位
	{
	if ((OUT2_A==ON)|(OUT2_B==ON))
		{
		OUT2_A=OFF;
		OUT2_B=OFF;
		if (AB2==A) AB2=B;
		else 		AB2=A;
		}
	time2=0;
	}	
else ///故障
if (H2==high)//高水位
	{
	ERROR2=ON;
	}	

/////////////////////////3333333333333333333/////////////////////////////////
if((L3==high)&&(M3==high)&&(H3==low))//中水位
	{
	if (AB3==A) 	OUT3_A=ON;
	else 		OUT3_B=ON;
	ERROR3=OFF;
	time3=0;
	}
else 
if((L3==high)&&(M3==high)&&(H3==high))//高水位
	{
	OUT3_A=ON;
	OUT3_B=ON;
	ERROR3=OFF;
	time3=0;
	}
else
if((L3==low)&&(M3==low)&&(H3==low)&&(ERROR3==OFF))//低水位
	{
	if ((OUT3_A==ON)|(OUT3_B==ON))
		{
		OUT3_A=OFF;
		OUT3_B=OFF;
		if (AB3==A) AB3=B;
		else 		AB3=A;
		}
	time3=0;
	}	
else ///故障
if (H3==high)//高水位
	{
	ERROR3=ON;
	}	
/////////////////////////4444444444444444444/////////////////////////////////
if((L4==high)&&(M4==high)&&(H4==low))//中水位
	{
	if (AB4==A) 	OUT4_A=ON;
	else 		OUT4_B=ON;
	ERROR4=OFF;
	time4=0;
	}
else 
if((L4==high)&&(M4==high)&&(H4==high))//高水位
	{
	OUT4_A=ON;
	OUT4_B=ON;
	ERROR4=OFF;
	time4=0;
	}
else
if((L4==low)&&(M4==low)&&(H4==low)&&(ERROR4==OFF))//低水位
	{
	if ((OUT4_A==ON)|(OUT4_B==ON))
		{
		OUT4_A=OFF;
		OUT4_B=OFF;
		if (AB4==A) AB4=B;
		else 		AB4=A;
		}
	time4=0;
	}	
else ///故障
if (H4==high)//高水位
	{
	ERROR4=ON;
	}	

/////////////////////////5555555555555555555/////////////////////////////////
if((L5==high)&&(M5==high)&&(H5==low))//中水位
	{
	if (AB5==A) 	OUT5_A=ON;
	else 		OUT5_B=ON;
	ERROR5=OFF;
	time5=0;
	}
else 
if((L5==high)&&(M5==high)&&(H5==high))//高水位
	{
	OUT5_A=ON;
	OUT5_B=ON;
	ERROR5=OFF;
	time5=0;
	}
else
if((L5==low)&&(M5==low)&&(H5==low)&&(ERROR5==OFF))//低水位
	{
	if ((OUT5_A==ON)|(OUT5_B==ON))
		{
		OUT5_A=OFF;
		OUT5_B=OFF;
		if (AB5==A) AB5=B;
		else 		AB5=A;
		}
	time5=0;
	}	
else ///故障
if (H5==high)//高水位
	{
	ERROR5=ON;
	}	
/////////////////////////6666666666666666666/////////////////////////////////
if((L6==high)&&(M6==high)&&(H6==low))//中水位
	{
	if (AB6==A) 	OUT6_A=ON;
	else 		OUT6_B=ON;
	ERROR6=OFF;
	time6=0;
	}
else 
if((L6==high)&&(M6==high)&&(H6==high))//高水位
	{
	OUT6_A=ON;
	OUT6_B=ON;
	ERROR6=OFF;
	time6=0;
	}
else
if((L6==low)&&(M6==low)&&(H6==low)&&(ERROR6==OFF))//低水位
	{
	if ((OUT6_A==ON)|(OUT6_B==ON))
		{
		OUT6_A=OFF;
		OUT6_B=OFF;
		if (AB6==A) AB6=B;
		else 		AB6=A;
		}
	time6=0;
	}	
else ///故障
if (H6==high)//高水位
	{
	ERROR6=ON;
	}	



}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -