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

📄 keymatrix3.c

📁 C51写的单片机串口通信程序,用于键盘测试和USB接口测试!
💻 C
📖 第 1 页 / 共 2 页
字号:
		  }
		  break;
		 }
		  case 0xA4:
		  {
          	switch (ReceiveBuffer[1])
          	{case 0x01:
			if (HubCount1==0)
		  	{++HubCount1;
			Timer2500us=10;
			while(Timer2500us);
			latch1=0;		  //关闭译码器一
			latch2=1;		  //打开译码器二
			ScanH1=0xC0;
			P1=ScanH1;

			Timer100ms=20;
			while(Timer100ms);  
			latch2=0;		  
			SendBuffer[0]=0xA4;
          	SendBuffer[1]=0x30;
          	Send(2);}
			else if (HubCount1==1)
			{HubCount1=0;
			Timer2500us=10;
			while(Timer2500us);
			latch1=0;		  //关闭译码器一
			latch2=1;		  //打开译码器二
			ScanH1=0xD0;
			P1=ScanH1;

			Timer100ms=20;
			while(Timer100ms);  
			latch2=0;		  
			SendBuffer[0]=0xA4;
          	SendBuffer[1]=0x30;
          	Send(2);}
		   break;
		   case 0x00:
          	Timer2500us=10;
			while(Timer2500us);
			latch1=0;		  //关闭译码器一
			latch2=0;		  //关闭译码器二
			SendBuffer[0]=0xA4;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   default:
		   break;
		   }
		 break;
        }

		case 0xA5:
		{
          switch (ReceiveBuffer[1])
          {case 0x01:
		  	Timer2500us=4;
			while(Timer2500us);
			DelayTime=6;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x02:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=8;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x03:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=12;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x04:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=16;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x05:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=20;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x06:
          	Timer2500us=4;
			while(Timer2500us); 
			DelayTime=24;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x07:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=28;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
			case 0x08:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=32;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
			break;
		   default:
		   break;
		  }
		 break;
        }		 
        default:	//其它命令保留
        {
          break;
        }
      }		     //MsgOk在条件为真语句内 !!!
	 }

   else if (!FixDownRight)
     { 
	 
	   switch(ReceiveBuffer[0])
	  
	      { case 0xA0:		//收到启动命令消息
                {
                 switch (ReceiveBuffer[1])
                  {case 0x01:
		            if (PowerCount2==0)
		  	          { ++PowerCount2;
			            BoardPower3=0;		   //BOARD3电源开
			     Timer2500us=200;
           	     while(Timer2500us);  //延时500ms	   
		   	     SendBuffer[0]=0xA0;
           	     SendBuffer[1]=0x31;
           	     Send(2);}
			else if (PowerCount2==1)
			   {PowerCount2=0;
			     BoardPower4=0;		   //BOARD4电源开
			     Timer2500us=200;
           	     while(Timer2500us);  //延时500ms	   
		   	     SendBuffer[0]=0xA0;
           	     SendBuffer[1]=0x31;
           	     Send(2);}
					
		   break;
		   case 0x00:
		   if (OffCount2==0)
		   {++OffCount2;
			BoardPower3=1;		   //BOARD1电源关
		    Timer2500us=200;
           	while(Timer2500us);     //延时500ms
			SendBuffer[0]=0xA0;
            SendBuffer[1]=0x30;			   
          	Send(2); }
			else if (OffCount2==1)
			{OffCount2=0;
			BoardPower4=1;		   //BOARD1电源关
		/*    FixUpRight=0;		   //右边治具升
			Timer2500us=200;
           	while(Timer2500us);     //延时500ms
			FixUpRight=1;	*/	    
			SendBuffer[0]=0xA0;
            SendBuffer[1]=0x30;			   
          	Send(2); }
		   break;
		   default:
		   break;
		  }	
          break;
        }

        case 0xA1:	//收到结束命令
        { switch (ReceiveBuffer[1])
          {case 0x01:
		  	Timer2500us=25;
           	while(Timer2500us);     //延时500ms
		  	LedInL1=P0;
			LedInH1=P2;
			//LedInH1=LedInH1&&0x03;
			SendBuffer[0]=0xA1;
          	SendBuffer[1]=LedInH1;
			SendBuffer[2]=LedInL1;
			Send(3);
		   break;

		   case 0x00: //收到测试LED OFF命令
          	Timer2500us=25;
           	while(Timer2500us);     //延时500ms
		  	LedInL1=P0;
			LedInH1=P2;
			SendBuffer[0]=0xA1;
          	SendBuffer[1]=LedInH1;
			SendBuffer[2]=LedInL1;
			Send(3);
		   break;
		   default:
		   break;
		  }
         
          break;
        }
		case 0xA2:
		{ switch (ReceiveBuffer[1])
          {case 0x01:
		  	Timer2500us=25;
           	while(Timer2500us);     //延时500ms
			latch2=0;              //关闭译码器二
		  	latch1=1;			   //打开译码器一
		     for (ScanL1=0;ScanL1<=16;ScanL1++) 
		      	{P1=ScanL1; 
		       	Timer2500us=DelayTime;
               	while(Timer2500us);
			  	}
	           	latch1=0;		  //关闭译码器一
		       	latch2=1;		  //打开译码器二
			 for (ScanH1=0;ScanH1<=11;ScanH1++)
	          	{P1=(ScanH1<<4); 
			   	Timer2500us=DelayTime;
               	while(Timer2500us);
			  	}
	           	latch2=0;		 //关闭译码器二

			  	SendBuffer[0]=0xA2;
          	    SendBuffer[1]=0x30;
          		Send(2);
		   break;
		   case 0x00:
          	 Timer2500us=25;
               	while(Timer2500us);
			latch1=0;		  //关闭译码器一
		  	latch2=0;         //关闭译码器二
		   break;
		   default:
		   break;
		  }

		 break;
		}
		case 0xA3:
		{
         switch (ReceiveBuffer[1])
          {case 0x01:
		  	Timer2500us=10;
			while(Timer2500us);
			EncoderB=1;
			Timer2500us=2;
			while(Timer2500us);
		    EncoderA=1;
			Timer2500us=6;
			while(Timer2500us);
			EncoderB=0;
			Timer2500us=2;
			while(Timer2500us);
			EncoderA=0;
			Timer2500us=6;
			while(Timer2500us);
			EncoderB=1;
			Timer2500us=2;
			while(Timer2500us);
		    EncoderA=1;
			Timer2500us=6;
			while(Timer2500us);
			EncoderB=0;
			Timer2500us=2;
			while(Timer2500us);
			EncoderA=0;
			SendBuffer[0]=0xA3;
          	SendBuffer[1]=0x30;
          	Send(2);
		   	break;
		   	case 0x00:
          	Timer2500us=10;
			while(Timer2500us);
			EncoderA=1;
			Timer2500us=2;
			while(Timer2500us);
		    EncoderB=1;
			Timer2500us=6;
			while(Timer2500us);
			EncoderA=0;
			Timer2500us=2;
			while(Timer2500us);
			EncoderB=0;
			Timer2500us=6;
			while(Timer2500us);
			EncoderA=1;
			Timer2500us=2;
			while(Timer2500us);
		    EncoderB=1;
			Timer2500us=6;
			while(Timer2500us);
			EncoderA=0;
			Timer2500us=2;
			while(Timer2500us);
			EncoderB=0;
			SendBuffer[0]=0xA3;
          	SendBuffer[1]=0x30;
          	Send(2);
		   	break;
		   	default:
		   	break;
		  }
		  break;
		 }
		  case 0xA4:
		  {
          	switch (ReceiveBuffer[1])
          	{case 0x01:
			if (HubCount2==0)
			{++HubCount2;
		  	Timer2500us=10;
			while(Timer2500us);
			latch1=0;		  //关闭译码器一
			latch2=1;		  //打开译码器二
			ScanH1=0xE0;
			P1=ScanH1;

			Timer100ms=20;
			while(Timer100ms);  
			latch2=0;		  
			SendBuffer[0]=0xA4;
          	SendBuffer[1]=0x30;
          	Send(2);}
			else if (HubCount2==1)
			 {HubCount2=0;
		  	Timer2500us=10;
			while(Timer2500us);
			latch1=0;		  //关闭译码器一
			latch2=1;		  //打开译码器二
			ScanH1=0xF0;
			P1=ScanH1;

			Timer100ms=20;
			while(Timer100ms);  
			latch2=0;		  
			SendBuffer[0]=0xA4;
          	SendBuffer[1]=0x30;
          	Send(2);}
		   break;
		   case 0x00:
          	Timer2500us=10;
			while(Timer2500us);
			latch1=0;		  //关闭译码器一
			latch2=0;		  //关闭译码器二
			SendBuffer[0]=0xA4;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   default:
		   break;
		   }
		 break;
        }

		case 0xA5:
		{
          switch (ReceiveBuffer[1])
          {case 0x01:
		  	Timer2500us=4;
			while(Timer2500us);
			DelayTime=6;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x02:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=8;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x03:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=12;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x04:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=16;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x05:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=20;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x06:
          	Timer2500us=4;
			while(Timer2500us); 
			DelayTime=24;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
		   break;
		   case 0x07:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=28;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
			case 0x08:
          	Timer2500us=4;
			while(Timer2500us);
			DelayTime=32;
			SendBuffer[0]=0xA5;
          	SendBuffer[1]=0x30;
          	Send(2);
			break;
		   default:
		   break;
		  }
		 break;
        }		 
        default:	//其它命令保留
        {
          break;
        }
      }

	 }
	 MsgOk=0x00;  //每执行完一次串口指令信息,必须有清此标志位信息一下,否则将产生不能执行下一次串口中断
    } 
  }
}

//******************************************************************************  /

⌨️ 快捷键说明

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