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

📄 main.c

📁 AVR ATEMG128 触摸屏驱动程序 C语言
💻 C
📖 第 1 页 / 共 4 页
字号:
	utoa(Fix_D,W_PD_MID,10);
	a = strnlen(W_PD_MID,10);
	Sc16_Tx_A_OPEN;
	Fa_A( W_D_22,5);
	Fa_A( W_PD_MID,a);
	Fa_A( W_Enter,1 );

}
//***********读*流量***********************
void Read_Flow( uchar len )
{
	Sc16_Rx_A_OPEN;
	Flag_ReA = OFF;
	Flag_Gf= 0;
	Re_PA = 0;
	DelayMs(300);	
	//while( Re_PA < len );
	//Flag_ReA = ON;
	if( Re_PA > len )
	{
		Flag_Gf = 1;
		Flag_ReA = ON;
	}
	else
	{
		Flag_Gf = 0;
	}
}
//********显示 流量******************
void Disp_Flow(uchar a,uchar b)
{
	uchar i;
	Sc16_Tx_A_OPEN;
	Fa_A( W_RBS,2);
	Read_Flow(40);
	if( Flag_Gf == 1 )
	{
		for(i=0;i<7;i++)
		{
			Flow_MID[i] = Re_Sc16A[26+i];//[18+i];
		}
		//********************
		Return_Point();
		Move_Point(a,b+8 );
		//Disp_Date(Point_Kong,2);
		Send_byte(0x53);
		Send_byte(0x43);
		Send_byte(0x43);
		Send_byte(0x4d);		
		//********************
		Return_Point();
		Move_Point(a,b);
		Disp_Date(Point_Kong,7);
		Return_Point();
		Move_Point(a,b);
		Disp_Date(Flow_MID,7);
	}
}
//*******************************************
void Write_Value(uchar *p,uchar len )
{
	Sc16_Tx_B_OPEN;
	Fa_B( p,len);
}
//*******************************************
void Read_Value(uchar len )
{
	Sc16_Tx_B_OPEN;
	Re_PB = 0;
	while( Re_PB < len );
	Sc16_Tx_B_OPEN;	
}
//********写 Plump 的设置点******************
void Write_Plump_SetPoint(void)
{
	Valve =(float) Fix_Press/1000;//加/1000
	Valve = 1+(log10( Valve * 10000));
	Valve *= 10;
	dtostrf(Valve,4,1,Point_Date);
//	Write_Value(Plump_Open,2);	
//	DelayMs(600);
	Write_Value(Plump_Set_Point,2);
	Write_Value(Point_Date,4);
	Write_Value(Plump_End,1);
}
//*************开阀**************************
void Write_Plump_SetPoint_1(void)
{
	Valve = 1;
	dtostrf(Valve,4,1,Point_Date);
	Write_Value(Plump_Set_Point,2);
	Write_Value(Point_Date,4);
	Write_Value(Plump_End,1);
}
//*************关阀******************************
void Write_Plump_SetPoint_8(void)
{
	Valve = 80;
	dtostrf(Valve,4,1,Point_Date);
//	Write_Value(Plump_Open,2);	
//	DelayMs(600);
	Write_Value(Plump_Set_Point,2);
	Write_Value(Point_Date,4);
	Write_Value(Plump_End,1);
}
//*******************************************
void Write_Plum_P(void)
{
	Valve =Fix_18_P;
	dtostrf(Valve,4,1,Point_Date);
	Write_Value(Plump_P,1);
	Write_Value(Point_Date,4);
	Write_Value(Plump_End,1);
}
//*******************************************
void Write_Plum_P90(void)
{
	Valve =90;
	dtostrf(Valve,4,1,Point_Date);
	Write_Value(Plump_P,1);
	Write_Value(Point_Date,4);
	Write_Value(Plump_End,1);
}
//*******************************************
void Write_Plum_D(void)
{
	Valve = Fix_18_D;
	dtostrf(Valve,4,1,Point_Date);
	Write_Value(Plump_D,1);
	Write_Value(Point_Date,4);
	Write_Value(Plump_End,1);
}
//*******开电源************************************

void Open_Power(void)
{
	sbi(PORTF,PF0);
}
//*******关电源************************************
void Close_Power(void)
{
	cbi( PORTF,PF0);
}
//*******************************************
void Open_Window(void)
{
	sbi(PORTF,PF1);
}
//*******************************************
void Close_Window(void)
{
	cbi( PORTF,PF1);
}
//*******************************************
uchar Flag_Time3= OFF;
SIGNAL( SIG_OVERFLOW3 )
{
	TCNT3 = 0xE3DF;	
	Flag_Time3 = ON;

}
//*******************************************
void Open_Time3(void)
{
	TCCR3B = _BV(CS12) | _BV(CS10);
	TCNT3 = 0xC7BF;				//2S中断一次
	ETIMSK = _BV(TOIE3);	
	Flag_Time3 = OFF;
}
//*******************************************
void Close_Time3(void)
{
	TCCR3B = 0;
	TCNT3 = 0;
	ETIMSK = 0;
	Flag_Time3 = OFF;
}
//*******************************************
void GONGF(void)
{
	sei();
	Close_Power();
	Close_Window();
	Write_Flow_Rat_0();
	DelayMs(6);
	Write_Plump_SetPoint_1();
	DelayMs(6);
}
//********主程序***********************************
int		main()
{
			int W1;
			uint16_t Buff=0;
			uchar a;		
			uchar bb=0;			
//****************************************
			MCUCR = 0xc0;
			Uart0_Init();
			Uart1_Init();
			Sc16_Init();
			LCD_Init();
			DDRF = 0XFF;
			PORTF = 0;						
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&			
			sei();			
			DelayMs(30);	
			Write_Flow(W_One,5);				//定义 Flow is A;
			Close_Window();
			DelayMs(30);
			cli();
//*****STEP-1*****************************
			eeprom_busy_wait();
			W1 = eeprom_read_word(10);
			eeprom_busy_wait();
			if(W1 != 1)
			{
				eeprom_busy_wait();
				eeprom_write_word(10,1);
				eeprom_busy_wait();
				//%%%%%%%%%%屏6%%%%%%%%%%%%%%%%%%%
				eeprom_write_word(20,45);				//Fix_Flow
				eeprom_busy_wait();
				eeprom_write_word(22,388);				//Fix_Press
				eeprom_busy_wait();
				eeprom_write_word(24,20);				//Fix_Time

				//%%%%%%%%%%%屏17&&&&&&&&&&&&&&%%%
				eeprom_busy_wait();
				eeprom_write_word(30,200);				//Fix_P
				eeprom_busy_wait();
				eeprom_write_word(32,500);				//Fix_D
				eeprom_busy_wait();

				//%%%%%%%%%%%%屏18&&&&&&&&&&&&&&&&
				eeprom_write_word(40,100);				//Fix_18_Press
				eeprom_busy_wait();
				eeprom_write_word(42,12);				//Fix_18_P
				eeprom_busy_wait();
				eeprom_write_word(44,5);				//Fix_18_D
				eeprom_busy_wait();
				//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
				sei();
				goto Pin_2;
			}
			cli();	
		//	DelayMs(2000);
		//	Disp_Pin(1);
			//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			eeprom_busy_wait();
			Fix_Flow = eeprom_read_word(20);
			eeprom_busy_wait();
			Fix_Press = eeprom_read_word(22);
			eeprom_busy_wait();
			Fix_Time = eeprom_read_word(24);
			eeprom_busy_wait();
			Fix_P = eeprom_read_word(30);
			eeprom_busy_wait();
			Fix_D = eeprom_read_word(32);
			eeprom_busy_wait();
			Fix_18_Press = eeprom_read_word(40);
			eeprom_busy_wait();
			Fix_18_P = eeprom_read_word(42);
			eeprom_busy_wait();
			Fix_18_D = eeprom_read_word(44);
			Read_Eeprom();
STAR:		ratio_x = (float)(touch_rightbottom_x - touch_lefttop_x)  / 320;
			ratio_y = (float)(touch_rightbottom_y - touch_lefttop_y)  / 240;
			Key_Wz();
			DelayMs(5000);		
//*************STEP-2**********************
Pin_4:		Disp_Pin(4);
			sei();
			Close_Power();
			Close_Window();
			RxLen = 0;			
			Flag_Rec = OFF;
loop1:		while( Flag_Rec == OFF);
			RxLen = 0;			
			Flag_Rec = OFF;
			Asc_Dig();	
			if((KEY_LEFT_P[0] <= X_Zb) && (X_Zb <= KEY_LEFT_P[2]) && (Y_Zb <=KEY_LEFT_P[1])&&(KEY_LEFT_P[3]<= Y_Zb))
				goto Pin_16;
			if((KEY_RIGH_P[0] <= X_Zb) && (X_Zb <= KEY_RIGH_P[2]) && (Y_Zb <=KEY_RIGH_P[1])&&(KEY_RIGH_P[3]<= Y_Zb))
				{
					cli();
					eeprom_busy_wait();
					eeprom_write_word(20,Fix_Flow);				//Fix_Flow
					eeprom_busy_wait();
					eeprom_write_word(22,Fix_Press);				//Fix_Press
					eeprom_busy_wait();
					eeprom_write_word(24,Fix_Time);				//Fix_Time
					//
					eeprom_busy_wait();
					eeprom_write_word(30,Fix_P);				//Fix_P
					eeprom_busy_wait();
					eeprom_write_word(32,Fix_D);				//Fix_D
					eeprom_busy_wait();
					//
					eeprom_write_word(40,Fix_18_Press);				//Fix_18_Press
					eeprom_busy_wait();
					eeprom_write_word(42,Fix_18_P);				//Fix_18_P
					eeprom_busy_wait();
					eeprom_write_word(44,Fix_18_D);				//Fix_18_D
					eeprom_busy_wait();
					eeprom_busy_wait();
					DelayMs(60);
					eeprom_busy_wait();
					sei();
					goto Pin_5;
				}
			goto loop1;
//*************STEP-3***********************
Pin_16:		Disp_Pin(16);
			RxLen = 0;
loop2:		Flag_Rec = OFF;
			while(Flag_Rec == OFF);
			Asc_Dig();
			if((KEY_P16_1P[0] <= X_Zb) && (X_Zb <= KEY_P16_1P[2]) && (Y_Zb <=KEY_P16_1P[1])&&(KEY_P16_1P[3]<= Y_Zb))
				goto Pin_2;
			if((KEY_P16_2P[0] <= X_Zb) && (X_Zb <= KEY_P16_2P[2]) && (Y_Zb <=KEY_P16_2P[1])&&(KEY_P16_2P[3]<= Y_Zb))
				goto Pin_6;
			if((KEY_P16_3P[0] <= X_Zb) && (X_Zb <= KEY_P16_3P[2]) && (Y_Zb <=KEY_P16_3P[1])&&(KEY_P16_3P[3]<= Y_Zb))
				goto Pin_17;
			if((KEY_LEFT_P[0] <= X_Zb) && (X_Zb <= KEY_LEFT_P[2]) && (Y_Zb <=KEY_LEFT_P[1])&&(KEY_LEFT_P[3]<= Y_Zb))
				goto Pin_4;
			goto loop2;		
	//***************************
Pin_2:		Disp_Pin(2);			
			Flag_Rec = OFF;
			RxLen = 0;
			while( Flag_Rec == OFF );			
			Asc_Dig();			
			touch_lefttop_x = X_Zb;
			touch_lefttop_y = Y_Zb;
			Flag_Rec = OFF;
			Disp_Pin(3);
			while( Flag_Rec == OFF );			
			Asc_Dig();
			touch_rightbottom_x = X_Zb;
			touch_rightbottom_y = Y_Zb;			
//********EEprom write******
			cli();
			Disp_Pin(1);
			eeprom_busy_wait();
			eeprom_write_word(0,touch_lefttop_x);
			eeprom_busy_wait();
			eeprom_write_word(2,touch_lefttop_y);
			eeprom_busy_wait();
			eeprom_write_word(4,touch_rightbottom_x);
			eeprom_busy_wait();
			eeprom_write_word(6,touch_rightbottom_y);
			eeprom_busy_wait();	
			DelayMs(60);			
			eeprom_busy_wait();
			goto STAR;
//**************************
Pin_5:		Disp_Pin(20);
			Flag_Rec = ON;
			RxLen = 0;			
			Write_Flow_Rat_0();
			Write_Plum_P();
			Write_Plum_D();
			Open_Window();
			Open_Time3();
Brush5:		PRESS_Write(PRESS_TX,6);
			asm("nop");			
			if( Flag_ZD == ON)
			{
				Flag_ZD = OFF;
				Disp_Press(7,12);
				if( WWW > 750)
					{
						Close_Time3();
						goto Pin_14;
					}
			}					
loop5:		Flag_Rec = OFF;
			RxLen = 0;
			while(Flag_Rec == OFF)	
			{
				if(Flag_Time3 == ON)
					{
						Flag_Time3 = OFF;
						goto Brush5;
					}
			}			
			Asc_Dig();
			if((KEY_LEFT_P[0] <= X_Zb) && (X_Zb <= KEY_LEFT_P[2]) && (Y_Zb <=KEY_LEFT_P[1])&&(KEY_LEFT_P[3]<= Y_Zb))
				{
					Close_Time3();
					Close_Power();
					goto Pin_4;
				}

			if((KEY_RIGH_P[0] <= X_Zb) && (X_Zb <= KEY_RIGH_P[2]) && (Y_Zb <=KEY_RIGH_P[1])&&(KEY_RIGH_P[3]<= Y_Zb))
				{
					Close_Time3();
					goto Pin_14;
				}			
			goto loop5;
//*****************************************
Pin_14:		Disp_Pin(14);
			RxLen = 0;
loop14:		Flag_Rec = OFF;			
			while(Flag_Rec == OFF );			
			Asc_Dig();
			if((KEY_LEFT_P[0] <= X_Zb) && (X_Zb <= KEY_LEFT_P[2]) && (Y_Zb <=KEY_LEFT_P[1])&&(KEY_LEFT_P[3]<= Y_Zb))
				goto Pin_4;
			if((KEY_RIGH_P[0] <= X_Zb) && (X_Zb <= KEY_RIGH_P[2]) && (Y_Zb <=KEY_RIGH_P[1])&&(KEY_RIGH_P[3]<= Y_Zb))
				goto Pin_7;
			goto loop14;
//*****************************************
Pin_6:		Disp_Pin(6);
			Flag_Rec = ON;
			//*******Fix_Flow*****
			Return_Point();
			Move_Point(4,22);
			Clear_Data(Point_Kong,8);
			//********
			Return_Point();
			Move_Point(4,37);
			Send_byte(0x25);
			//********
			utoa(Fix_Flow,Point_Date,10);
			a = strnlen(Point_Date,10);
			Return_Point();
			Move_Point(4,22);
			Disp_Date(Point_Date,a);

			//******Fix_Press*****
			Return_Point();
			Move_Point(7,22);//15);
			Clear_Data(Point_Kong,8);
			//*******
			Return_Point();
			Move_Point(7,36);
			Send_byte(0x6d);
			Send_byte(0x54);
			//********
			utoa(Fix_Press,Point_Date,10);
			a = strnlen(Point_Date,10);
			Return_Point();
			Move_Point(7,22);
			Disp_Date(Point_Date,a);
			//*******Fix_Time*****
			Return_Point();
			Move_Point(10,22);//15);
			Clear_Data(Point_Kong,8);
			//**********
			Return_Point();
			Move_Point(10,37);
			Send_byte(0x53);
			//**********
			utoa(Fix_Time,Point_Date,10);
			a = strnlen(Point_Date,10);
			Return_Point();
			Move_Point(10,22);
			Disp_Date(Point_Date,a);
			//**************************
loop6:		Flag_Rec = OFF;
			RxLen = 0;
			while( Flag_Rec == OFF );			
			Asc_Dig();
			//*********SET UP ****FLOW PRESSURE TIME ***
			if((KEY_P6_rateP[0] <= X_Zb) && (X_Zb <= KEY_P6_rateP[2]) && (Y_Zb <=KEY_P6_rateP[1])&&(KEY_P6_rateP[3]<= Y_Zb))
				{
					Key_board( &Fix_Flow);
					goto Pin_6;
				}
			if((KEY_P6_pressP[0] <= X_Zb) && (X_Zb <= KEY_P6_pressP[2]) && (Y_Zb <=KEY_P6_pressP[1])&&(KEY_P6_pressP[3]<= Y_Zb))
				{
					GonGon = Fix_Press;
					Key_board( &Fix_Press);
					if( Fix_18_Press > Fix_Press )
					{
						Fix_Press = GonGon;
						goto Pin_19;
					}
					goto Pin_6;
				}
			if((KEY_P6_timeP[0] <= X_Zb) && (X_Zb <= KEY_P6_timeP[2]) && (Y_Zb <=KEY_P6_timeP[1])&&(KEY_P6_timeP[3]<= Y_Zb))
				{
					Key_board( &Fix_Time);
					goto Pin_6;
				}
			if((KEY_LEFT_P[0] <= X_Zb) && (X_Zb <= KEY_LEFT_P[2]) && (Y_Zb <=KEY_LEFT_P[1])&&(KEY_LEFT_P[3]<= Y_Zb))
				goto Pin_4;
			if((KEY_RIGH_P[0] <= X_Zb) && (X_Zb <= KEY_RIGH_P[2]) && (Y_Zb <=KEY_RIGH_P[1])&&(KEY_RIGH_P[3]<= Y_Zb))
				goto Pin_18;
			goto loop6;
//*****************************************
Pin_zx:		Disp_Pin(6);
			Flag_Rec = OFF;
			RxLen = 0;
			//*******Fix_Flow*****
			Return_Point();
			Move_Point(4,15);
			Clear_Data(Point_Kong,8);
			//********
			Return_Point();
			Move_Point(4,30);
			Send_byte(0x25);
			//********
			utoa(Fix_Flow,Point_Date,10);
			a = strnlen(Point_Date,10);
			Return_Point();
			Move_Point(4,15);
			Disp_Date(Point_Date,a);

			//******Fix_Press*****
			Return_Point();
			Move_Point(7,15);

⌨️ 快捷键说明

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