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

📄 chongqibeng.c

📁 基于C51的充气泵控制系统程序源码
💻 C
📖 第 1 页 / 共 2 页
字号:
					{
						if(a3>0x01)
						{
							a3=a3-1;
						}
					}
					for(;;)
					{
						key=kbscan();
						if(key==0)
							break;
					}
					break;
				}
	      		else if(key==0x03)
				{
					cc=(cc+1)%4;
					if(cc!=0)
					{
						P2_1=1;
						delay1(8);
						P2_1=0;
					}
					if(cc==0)
					{	
						P2_1=1;
						delay2(60);
						P2_1=0;
						WriteEeprom(0x20,a1,a2,a3);
						break;
					}
					for(;;)
					{
						key=kbscan();
						if(key==0)
							break;
					}
					break;
				}
			}
			if(cc==0)
				break;
	}
}
uchar kbscan()//键盘扫描函数,确定是否有键按下,返回值为0.1.2.3.4.5分别表示无键,功能键,+,-,检漏键,多个键按下
{
	uchar i,z,j,k=0,temp=0x08;
	z=(~P1)&0x0f;
	LED_DISPLAY(b,cc);
	if(z!=0x00)
	{
		delay1(2);
		z=(~P1)&0x0f;
		if(z!=0x00)
		{
			for(i=1;i<=4;i++)
			{
				if((z&temp)==temp)
				{
					j=i;
					k=k+1;
				}
				temp=(temp>>1);
			}
		}
	}
	if(k==1)
	{
		return(j);
	}
	else if(k==0)
	{
		return(0);
	}
	else
	{
		return(5);
	}
}

uchar kbscan1()//键盘扫描函数,确定是否有键按下,返回值为0.1.2.3.4.5分别表示无键,功能键,+,-,检漏键,多个键按下
{
	uchar i,z,j,k=0,t=0,temp=0x08;
	z=(~P1)&0x0f;
	LED_DISPLAY1(cc);
	if(z!=0x00)
	{
		for(t=0;t<200;t++);
		z=(~P1)&0x0f;
		if(z!=0x00)
		{
			for(i=1;i<=4;i++)
			{
				if((z&temp)==temp)
				{
					j=i;
					k=k+1;
				}
				temp=(temp>>1);
			}
		}
	}
	if(k==1)
	{
		return(j);
	}
	else if(k==0)
	{
		return(0);
	}
	else
	{
		return(5);
	}
}
void LED_DISPLAY(uint b,uchar i)//数据处理及显示程序
{
	uchar j,k,q,j1,k1,q1,biaozhi;
	uint shuru;	
	if(i==1)//设置最大值状态
	{
	  	shuru=a1;
	  	biaozhi=10;
	}
	else if(i==2)//设置最小值状态 
	{
	  	shuru=a2;
	  	biaozhi=11;
	}
	else if(i==3)//设置一天充气次数状态 
	{
	  	shuru=a3;
	  	biaozhi=12;
	}	
	if(i==0||i==4||i==5)
	{		
	  	j=qiya/500;
	  	k=qiya%500/50;
	  	q=qiya%500%50/5;
	  	j1=b/100;
	  	k1=b%100/10;
	 	q1=b%100%10;
		if(j!=0)
		{
			P2=P2&0x03;
			P0=table1[j];
			P2=P2|0x20;
			delay3(2);
			P2=P2&0x03;
		 	P0=table2[k];
			P2=P2|0x40;
		 	delay3(2);
			P2=P2&0x03;
			P0=table1[q];
			P2=P2|0x80;
		 	delay3(2);
		}
		else
		{
			P2=P2&0x03;
		 	P0=table2[k];
			P2=P2|0x40;
		 	delay3(2);
			P2=P2&0x03;
			P0=table1[q];
			P2=P2|0x80;
		 	delay3(2);
			P2=P2&0x03;
		}
		z3=TLC1549read();
		if(j1!=0)
		{
			P2=P2&0x03;
			P0=table1[j1];
			P2=P2|0x04;
		 	delay3(2);
			P2=P2&0x03;
			P0=table1[k1];
			P2=P2|0x08;
		 	delay3(2);
			P2=P2&0x03;
			P0=table1[q1];
			P2=P2|0x10;
	 		delay3(2);
			P2=P2&0x03;
		}
		else
		{
			if(k1!=0)
			{
				P2=P2&0x03;
				P0=table1[k1];
				P2=P2|0x08;
		 		delay3(2);
			}
			P2=P2&0x03;
			P0=table1[q1];
			P2=P2|0x10;
	 		delay3(2);
			P2=P2&0x03;
		}
	}
	else if(i==1||i==2)
	{
	  	j=shuru/100;
	  	k=(shuru%100)/10;
	  	q=shuru%100%10;	
		if(k!=0)
		{
			if(i==1)
			{
			P2=P2&0x03;
			P0=table1[10];
			P2=P2|0x10;
			delay2(2);
			}
			else
			{
				P2=P2&0x03;
				P0=table1[11];
				P2=P2|0x10;
				delay3(4);
			}
			P2=P2&0x03;
			P0=table1[k];
			P2=P2|0x20;
	 		delay2(1);
			delay3(1);
			P2=P2&0x03;
			P0=table2[q];
			P2=P2|0x40;
		 	delay2(1);
			delay3(1);
			P2=P2&0x03;
			P0=table1[0];
			P2=P2|0x80;
			delay2(1);
			delay3(1);
			P2=P2&0x03;
		}
		else
		{
			if(i==1)
			{
				P2=P2&0x03;
				P0=table1[10];
				P2=P2|0x10;
				delay2(2);
				P2=P2&0x03;
			}
			else if(i==2)
			{
				P2=P2&0x03;
				P0=table1[11];
				P2=P2|0x10;
				delay3(4);
			}
			P2=P2&0x03;
			P0=table2[q];
			P2=P2|0x40;
		 	delay2(1);
			delay3(1);
			P2=P2&0x03;
			P0=table1[0];
			P2=P2|0x80;
			delay2(1);
			delay3(1);
			P2=P2&0x03;
			delay2(2);
		}
	}
	else
	{
		j=shuru/100;
	  	k=(shuru%100)/10;
	  	q=shuru%100%10;
		if(j!=0)
		{
			P2=P2&0x03;
			P0=table1[12];
			P2=P2|0x20;
			delay2(2);
			P2=P2&0x03;
			P0=table1[j];
			P2=P2|0x04;
	 		delay2(2);
			P2=P2&0x03;
			P0=table1[k];
			P2=P2|0x08;
	 		delay2(2);
			P2=P2&0x03;
			P0=table1[q];
			P2=P2|0x10;
	 		delay2(2);
			P2=P2&0x03;
		}
		else if(j==0)
		{
			if(k!=0)
			{
				P2=P2&0x03;
				delay2(1);
				P0=table1[12];
				P2=P2|0x20;
				delay2(2);
				P2=P2&0x03;
				P0=table1[k];
				P2=P2|0x08;
	 			delay2(2);
				P2=P2&0x03;
				P0=table1[q];
				P2=P2|0x10;
	 			delay2(2);
				P2=P2&0x03;
			}
			else
			{
				P2=P2&0x03;
				delay3(1);
				P0=table1[12];
				P2=P2|0x20;
				delay2(2);
				P2=P2&0x03;
				delay3(1);
				P0=table1[q];
				P2=P2|0x10;
	 			delay2(2);
				P2=P2&0x03;
				delay2(2);
			}
		}
	}
}

void LED_DISPLAY1(uchar i)
{
	if(i==1)
	{
		P2=P2&0x03;
		P0=table1[10];
		P2=P2|0x10;
		delay3(2);
		P2=P2&0x03;
	}
	else if(i==2)
	{
		P2=P2&0x03;
		P0=table1[11];
		P2=P2|0x10;
		delay2(2);
		P2=P2&0x03;
	}
	else
	{
		P2=P2&0x03;
		P0=table1[12];
		P2=P2|0x20;
		delay3(2);
		P2=P2&0x03;
	}
}
uint TLC1549read()//AD转换器读入程序,p3_2=sclk,p3_3=I/O,p3_5=CS/
{
	unsigned char HIGH=0x00;
	unsigned char LOW=0x00;
	unsigned char TEMP=0x00;
	unsigned int  SYN;
	unsigned char i;
	P3_5=1;
	_nop_();
	P3_2=0;
	_nop_();
	P3_5=0;
	_nop_();
	_nop_();
	_nop_();
	TEMP=P3_3;
	TEMP=TEMP<<1;
	HIGH=HIGH+TEMP;
	P3_2=1;
	_nop_();
	P3_2=0;
	_nop_();
	TEMP=P3_3;
	HIGH=HIGH+TEMP;
	for(i=8;i>0;i--)
	{
		P3_2=1;
		_nop_();
		P3_2=0;
		_nop_();
		TEMP=P3_3;
		TEMP=TEMP<<(i-1);
	   	LOW=LOW+TEMP;		
	}
	SYN=HIGH*256+LOW;
	P3_2=1;
	_nop_();
	_nop_();
	P3_2=0;
	_nop_();
	P3_5=1;	
	return(SYN);
}
void delay1(unsigned int time)//延迟函数
{
	unsigned int j;
     	for (j=0;j<time;j++)
		{	
			LED_DISPLAY(b,cc);
		}
}

void delay2(unsigned int time)
{
	unsigned int j,k;
     	for (j=0;j<time;j++)
		{
			for (k=0;k<200;k++);
		}
}

void delay3(unsigned int time)
{
	unsigned int j,k;
    for (j=0;j<time;j++)
	{
		for (k=0;k<133;k++);
	}
}
void initial()//初始化函数
{	
	P3_6=1;//关闭充气开关
	P3_7=1;//切断阀关闭
	P2=0x00;//蜂鸣器关
	b=0;//充气次数归零
	e=0;
	TR0=0;
	value=0;
	TH0=60;
	TL0=176;
	TMOD=0x01;
	IE=0x82;
	TR0=1;
	if(ReadEeprom(0x20,0x00)<1||ReadEeprom(0x20,0x00)>20)
	{
		WriteEeprom(0x20,max,min,cishu);
	}
}
void EraseEeprom(unsigned char t_addr) 
{ 
    isp_addrh=t_addr; 
    isp_addrl=0; 
    EA=0; 
    isp_contr=0x82;//最后三位表示系统等待时间,11要求cpu时钟频率至少为5MHz
    isp_cmd=3; //cmd为3,表示擦操作命令
    isp_trig=0x46; 
    isp_trig=0xb9; //以上两行表示操作开始
    delay2(10);
	isp_contr=0;     
    isp_cmd=0; 
    isp_trig=0; 
    isp_addrh=0; 
    isp_addrl=0; //以上表示后续操作,恢复使用前状态,以防误操作
    EA=1;
} 
void WriteEeprom(unsigned char t_addr,uchar dataa,uchar datab,uchar datac) 
{ 
		uchar num,addrl,i;
    	EraseEeprom(t_addr);
 	    for(i=0;i<3;i++)
		{
			if(i==0)
			{
				num=dataa;
				addrl=0x00;
			}
			else if(i==1)
			{
				num=datab;
				addrl=0x01;	
			}
			else
			{
				num=datac;
				addrl=0x02;
			}
        	isp_data=num;
        	isp_addrh=t_addr; 
        	isp_addrl=addrl;
        	EA=0;                
        	isp_contr=0x82;    
        	isp_cmd=2; //cmd为2表示写操作
        	isp_trig=0x46; 
        	isp_trig=0xb9;	 
			delay2(10);
        }
        isp_contr=0; 
        isp_cmd=0; 
        isp_trig=0;
        isp_addrh=0; 
        isp_addrl=0;//同上
        EA=1;		
}
uchar ReadEeprom(unsigned char s_addr,unsigned char addrl) 
{    
	uchar temp;
    isp_addrh=s_addr; 
    isp_addrl=addrl; 
    EA=0;    
    isp_contr=0x82;    
    isp_cmd=1; //1表示读操作
    isp_trig=0x46; 
    isp_trig=0xb9; 
    LED_DISPLAY(b,cc);	
	temp=isp_data; 
    isp_contr=0; 
    isp_cmd=0; 
    isp_trig=0; 
    isp_addrh=0; 
    isp_addrl=0;         
    EA=1;                       
  	return(temp);
} 

⌨️ 快捷键说明

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