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

📄 新建 text file.txt

📁 适合51,AVR,ARM单片机使用的PS2键盘源代码。欢迎下载
💻 TXT
字号:
void ProcessData()
{
	unsigned char temp;
	BitData=Data_Buf[0];
	button_L=B_dat0;
	button_R=B_dat1;
	button_M=B_dat2;
	flag_X=B_dat4;
	flag_Y=B_dat5;
	length_X=Data_Buf[1];
	length_Y=Data_Buf[2];
	length_Z=Data_Buf[3]; 
	if(button_L+button_R+button_M==0)  /*没有键被按下*/
	{	
			if(Data_Buf[1]!=0)              /*如果位移不为0*/
			{		
				if(flag_X)                   //左?
				{
					temp=256-length_X;      //取位移绝对?
					X_Rmove+=temp/4;        //每4个单位为1毫米,取位移毫?
					count=0;
					if(X_Rmove>500)
					{
						P1=0XEF;            //5 
						P0=0X09;
						Delay_msec(500);
						P0=0X00;		
					}
			}
			else                                    //右移
			{
				X_Lmove+=length_X/4;   //每4个单位为1毫米,取位移毫米
				count=0;
				if(X_Lmove>500)
				{
					P1=0Xfe;            //1
					P0=0X0a;
					Delay_msec(500);
					P0=0X00;	
				}
			}			 
			Data_Buf[1]=0;                    /*清空位移*/
			Data_Buf[2]=0;
			Data_Buf[3]=0;
		}//end of the if(Data_Buf[1]!=0
		else 
		{
			if(flag_M)
			{
				if(count++>5)
				{
					X_Lmove=0;
					X_Rmove=0;
					count=0;
				} 
				flag_M=0;
			}
		}	   	
	}//end of the if(button_L+button_R+button_M==0)
	else                                      /*有键被按下*/
	{   
		if(button_L+button_M+button_R==1)
		{   
			if(button_L==1)		    		  /*左键被按下*/
			{	
				P1=0Xfd;                //2
				P0_0=1;
				Delay_msec(500);
				P0_0=0;	
			}			 
			else if(button_R==1)   
			{ 
				P1=0Xf7;                //4
				P0=0X03;
				Delay_msec(500);
				P0=0X00;			
			}
			else if(button_M==1)
			{  
				P1=0Xfb;                //3
				P0=0x07;
				Delay_msec(600);
				P0=0x00;		
			}	  
		}//end of the if(button_L+button_M+button_R==1)
		else
		{
			P1=0XFF;
			P0_3=1;
			Delay_msec(600);
			P0_3=0;		
		}	
	}
}

⌨️ 快捷键说明

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