Пример #1
0
void ZIGB_setting()
{
 ZIGB_menu_page();
 
 while((Uc_key_temp = get_key(1)) != 'A')
 {
  if(Uc_key_temp == '1')
  {
  	Uc_key_temp = 0;

	#if RESP_ON_UART0 == 1
	uart0_send_string("\n\n\rReading ZigBee Parameters...");
	#endif
	ZIGB_read();
	ZIGB_menu_page();
  }
  else if(Uc_key_temp == '2')
  {
   	Uc_key_temp = 0;
	ms_delay(1000);
	#if RESP_ON_UART0 == 1
	uart0_send_string("\n\n\rWritting ZigBee Parameters...");
	#endif
	ZIGB_write();
	ZIGB_menu_page();
  }
 }
}
Пример #2
0
void Main(void)
{	
	char recvbuf[128];
	//调用初始化程序
	uart0_no_fifo_poll_init();
	while(1)
	{
		uart0_send_string("输入字符串并按回车");
		uart0_get_string(recvbuf);
		uart0_send_string("输入的字符为: ");
		uart0_send_string(recvbuf);
	}
}
Пример #3
0
void ZIGB_exit_cmd()
{
 uart1_send_string("ATCN\r");
 if(ZIGB_responce(3,"OK\r"))
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rExit CMD: OK ");
   #endif
   ms_delay(10000);
  }
 else
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rExit CMD: ERROR ");
   #endif
   ms_delay(10000);
  }
}
//夹持器指尖触碰(INT4)中断处理函数
void interrupt_4_handler(void)
{
	if(ext_collision_alert_allow_int4)
	{
	    delay(50);
		uart0_send_string("zz43");
        ext_collision_alert_allow_int4=0;//全局变量
	}
}
//定时计数器1中断处理函数
void timer1_interrupt_handler(void)
{
    uchar msg_force_array[]="zz21w";
	force_ulong=ReadCount();//读取数据放入全局变量
	ulong_to_uchar_array(force_ulong);//数据类型转换
	msg_force_array[4]=force_high8;
	uart0_send_string(msg_force_array);//向上位机发送夹紧力实时数值(仅有效值高八位)
	TCNT1=0xC2F6;//需要重新设定周期500ms
}
Пример #6
0
 void sysproc_crt_display(void) 
{
	msg_envelope_t *msg;
	
	while (1) 
	{
		msg = receive_message(NULL);
		uart0_send_string((uint8_t*)msg->data);
		free_message(msg);	
	}
}
Пример #7
0
void ZIGB_cmd_mode()
{
 uart1_send_string("+++");
 clrscr();
 lcd_line1_disp("CMD Mode",0);

 if(ZIGB_responce(3,"OK\r"))
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rCMD: OK ");
   #endif
   ms_delay(10000);
  }
 else
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rCMD: ERROR ");
   #endif
   ms_delay(10000);
  }
}
Пример #8
0
void ZIGB_ch_wrt(U8 *ch_no)
{
  uart1_send_string("ATCH");
  uart1_send_string(ch_no);
  uart1_send_byte('\r');

   if(ZIGB_responce(3,"OK\r"))
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rCH: OK ");
   #endif
   ms_delay(10000);
  }
 else
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rCH: ERROR ");
   #endif
   ms_delay(10000);
  }
}
Пример #9
0
void ZIGB_my_wrt(U8 *my_add)
{
  uart1_send_string("ATMY");
  uart1_send_string(my_add);
  uart1_send_byte('\r');

   if(ZIGB_responce(3,"OK\r"))
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rMY: OK ");
   #endif
   ms_delay(10000);
  }
 else
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rMY: ERROR ");
   #endif
   ms_delay(10000);					  
  }
}
Пример #10
0
void ZIGB_pan_wrt(U8 *pan_add)
{
  uart1_send_string("ATID");
  uart1_send_string(pan_add);
  uart1_send_byte('\r');

   if(ZIGB_responce(3,"OK\r"))
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rPAN: OK ");
   #endif
   ms_delay(10000);
  }
 else
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rPAN: ERROR ");
   #endif
   ms_delay(10000);
  }
}
Пример #11
0
void ZIGB_dl_wrt(U8 *dest_add)
{
  uart1_send_string("ATDL");
  uart1_send_string(dest_add);
  uart1_send_byte('\r');
  if(ZIGB_responce(3,"OK\r"))
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rDL: OK ");
   #endif
   ms_delay(10000);
  }
 else
  {
   #if RESP_ON_UART0 == 1
   uart0_send_string("\n\n\rDL: ERROR ");
   #endif
   ms_delay(10000);
  }

}
Пример #12
0
void ZIGB_my_read()
{
  U8 temp_arr[20]= "000";
  U8 temp_cnt;
  
  uart1_send_string("ATMY");
  uart1_send_byte('\r');

  for(temp_cnt = 0; Uc_zigb_my[temp_cnt - 1] != '\r'; temp_cnt++)
  {
   	while((U1LSR & 0x01) == 0);
   	Uc_zigb_my[temp_cnt] = U1RBR;
  }

  Uc_zigb_my[temp_cnt - 1] = '\0';

  uart0_send_string("\n\n\rMY Address: ");
  uart0_send_string(&Uc_zigb_my[0]);

 

}
//---------------------------【主函数】↓-----------------------------------------------------------
void main(void)
{

 	//.....................[函数体内变量声明]...............................

 	uchar i;//清空指令存储变量时所用循环的计数变量
	
	//向舵机发送移动命令时所用的变量(下面2个)↓
	uchar motor_command[9]={0xff,0xff,0x00,0x05,0x03,0x20,0x00,0x00,0x00};//
	uchar CHECK;//舵机指令最后一位校验码
	
	//上电手指复位阶段用到的变量(下面2个)↓
	//保证舵机停止命令只进行一次
	uchar cage_0=1;
	uchar cage_1=1;
	
	//正常工作模式(模式一)手指松开阶段用到的变量(下面2个)↓
	//保证每次夹紧操作时舵机停止命令只进行一次	
	uchar approach_0;
	uchar approach_1;
	
	//夹紧第二阶段的while循环跳出指示
	uchar hold_stage_2_continue=1;
	
	//大循环中查询两端限位和空夹所用到的变量(下面7个)↓
	//while大循环从两端限位后开始,因此不允许再次发送舵机停止命令,而是等待限位结束
	uchar stop_allow_cage_0=0;
	uchar stop_allow_cage_1=0;
	//不允许手指向端部移动,允许手指向中间移动,设置四个变量是因为考虑到两端限位跟空夹
	uchar release_allow_motor_0=0;
	uchar release_allow_motor_1=0;
	uchar hold_allow_motor_0=1;
	uchar hold_allow_motor_1=1;
	//允许上电复位后就开始检测是否空夹
	uchar stop_allow_empty=1;
	
	//调试模式手指移动速度,初始值为通过串口设定前的默认值
	uchar PARA2=0x10,PARA3=0x01;//保证低速,仅允许通过串口命令更改其值!
	
	//一般模式手指移动速度,仅允从EEPROM中获取数值
	uchar com_finger0_ratio_1_PARA2,com_finger0_ratio_1_PARA3;//手指0,Ratio 1
	uchar com_finger0_ratio_2_PARA2,com_finger0_ratio_2_PARA3;//手指0,Ratio 2
	uchar com_finger0_ratio_3_PARA2,com_finger0_ratio_3_PARA3;//手指0,Ratio 3
	uchar com_finger1_ratio_1_PARA2,com_finger1_ratio_1_PARA3;//手指1,Ratio 1
	uchar com_finger1_ratio_2_PARA2,com_finger1_ratio_2_PARA3;//手指1,Ratio 2
	uchar com_finger1_ratio_3_PARA2,com_finger1_ratio_3_PARA3;//手指1,Ratio 3
	
	uchar msg_eeprom_array[17];//向上位机返回EEPROM中数值
	uchar msg_interrupt_array[7]={'z','z','4','4','0','0','0'};//向上位机返回夹持器与外部碰撞报警(中断)允许变量的值
	
	
	//.......................[初始化配置].........................
	
    uart0_init(19200);//串口0(与上位机通信)初始化,波特率均为19200
    uart1_init(19200);//串口1(与舵机通信)初始化,波特率均为19200
	timer1_init();//定时计数器1初始化
	force_data_init();//应变片读取初始化
	
	
	//限位的配置
	
	//PE2=接近开关0,高阻态输入
	DDRE&=(~BIT(2));//DDRE2=0
	PORTE&=(~BIT(2));//PORTE2=0
	
	//PE3=接近开关1,高阻态输入
	DDRE&=(~BIT(3));//DDRE2=0
	PORTE&=(~BIT(3));//PORTE2=0
	
    //PE5=INT5=限位0,带上拉电阻输入
    DDRE&=(~BIT(5));//意思是DDRE5=0,其余位不变。但注意不可按注释的方式写!
    PORTE|=BIT(5);//意思是PORTE5=1,其余位不变。但注意不可按注释的方式写!
	
    //PE6=INT6=限位1,带上拉电阻输入
    DDRE&=(~BIT(6));
    PORTE|=BIT(6);

	//PE7=空夹,带上拉电阻输入
    DDRE&=(~BIT(7));
    PORTE|=BIT(7);
	
	
	//................[功能:上电后手指复位]....................................

    SREG |= 0X80;//打开全局中断
    
    //相关变量初始化
    cage0_state=0;
    cage1_state=0;

    //命令舵机停止转动
    uart1_send_string((uchar*)no0stop,9);
	delay(50);
	uart1_send_string((uchar*)no1stop,9);
    delay(50);
	
    //使手爪松开
    uart1_send_string((uchar*)no0release,9);
	delay(50);
    uart1_send_string((uchar*)no1release,9);

    //等待两端限位触发	
	while(cage_0|cage_1)
	{
	    if(cage_0)
		{
    	    if(!(PINE & BIT(5)))//PE5=0进入
	    	{
		        delay(50);
				if(!(PINE & BIT(5)))
				{
			        uart1_send_string((uchar*)no0stop,9);
					//uart0_send_string("zz30");
					cage_0=0;
			    }
			
		    }
		}
		
	    if(cage_1)
		{
    	    if(!(PINE & BIT(6)))//PE6=0进入
	    	{
		        delay(50);
				if(!(PINE & BIT(6)))
				{
			        uart1_send_string((uchar*)no1stop,9);
					//uart0_send_string("zz31");
					cage_1=0;
			    }
			
		    }
		}
	}
	
    uart0_send_string("zz00");//向上位机报告准备就绪
	
	UCSR0B|=(1<<RXEN0)|(1<<RXCIE0);   //UART0接收使能,接收中断使能
	
	
//........................[while(1)大循环]............................................
	
    while(1)
	{
	 	 if(uart0_instr_flag==1)
		 {
	         switch(gripper_mood)
		     {
	             case 0:
			     {
			         if(array_cmp(uart0_instr,"0100")==0)
				     {
				         //uart0_send_string(" mood 0: enter 1-regular working mood! ");
					 	 gripper_mood=1;
						 ext_interrupt_init();//外部中断(夹持器与外部环境碰撞)初始化
						 //初始化后会立即出发一次INT0和INT1,所以报警允许变量需要先置0再置1
						 
						 //夹持器与外部碰撞报警(中断)允许变量
						 ext_collision_alert_allow_int0=1;//上侧
						 ext_collision_alert_allow_int1=1;//下侧
						 ext_collision_alert_allow_int4=1;//指尖

						 
						 //获取EEPROM中存储的RATIO值
    					 command_data_read_finger_0_ratio_1(&com_finger0_ratio_1_PARA2,&com_finger0_ratio_1_PARA3);
						 command_data_read_finger_0_ratio_2(&com_finger0_ratio_2_PARA2,&com_finger0_ratio_2_PARA3);
						 command_data_read_finger_0_ratio_3(&com_finger0_ratio_3_PARA2,&com_finger0_ratio_3_PARA3);
						 command_data_read_finger_1_ratio_1(&com_finger1_ratio_1_PARA2,&com_finger1_ratio_1_PARA3);
						 command_data_read_finger_1_ratio_2(&com_finger1_ratio_2_PARA2,&com_finger1_ratio_2_PARA3);
						 command_data_read_finger_1_ratio_3(&com_finger1_ratio_3_PARA2,&com_finger1_ratio_3_PARA3);
	
						 //获取EEPROM中存储的夹紧力阈值有效值高八位
						 command_data_read_force_high8(&force_judge);
						 
	
				     }
				 
				 	 if(array_cmp(uart0_instr,"0200")==0)
				 	 {
				         //uart0_send_string(" mood 0: enter 2-configuration mood! ");
					 	 gripper_mood=2;
						 ext_interrupt_init();//外部中断(夹持器与外部环境碰撞)初始化
						 //初始化后会立即出发一次INT0和INT1,所以报警允许变量需要先置0再置1
						 
						 //夹持器与外部碰撞报警(中断)允许变量
						 ext_collision_alert_allow_int0=1;//上侧
						 ext_collision_alert_allow_int1=1;//下侧
						 ext_collision_alert_allow_int4=1;//指尖
				 	 }
				 
				 	 break;
			     }
			 
		         case 1:
			     {
			     	 if(array_cmp(uart0_instr,"1000")==0)//调试模式·读取EEPROM中存储的RATIO和力阈值
				 	 {
						 //更新ratio变量值、力阈值和消息数组的值
						 
						 //获取EEPROM中存储的RATIO值
    					 command_data_read_finger_0_ratio_1(&com_finger0_ratio_1_PARA2,&com_finger0_ratio_1_PARA3);
						 command_data_read_finger_0_ratio_2(&com_finger0_ratio_2_PARA2,&com_finger0_ratio_2_PARA3);
						 command_data_read_finger_0_ratio_3(&com_finger0_ratio_3_PARA2,&com_finger0_ratio_3_PARA3);
						 command_data_read_finger_1_ratio_1(&com_finger1_ratio_1_PARA2,&com_finger1_ratio_1_PARA3);
						 command_data_read_finger_1_ratio_2(&com_finger1_ratio_2_PARA2,&com_finger1_ratio_2_PARA3);
						 command_data_read_finger_1_ratio_3(&com_finger1_ratio_3_PARA2,&com_finger1_ratio_3_PARA3);
	
						 msg_eeprom_array[0]='z';
						 msg_eeprom_array[1]='z';
						 msg_eeprom_array[2]='3';
						 msg_eeprom_array[3]='3';
						 msg_eeprom_array[4]=com_finger0_ratio_1_PARA2;
						 msg_eeprom_array[5]=com_finger0_ratio_1_PARA3;
						 msg_eeprom_array[6]=com_finger0_ratio_2_PARA2;
						 msg_eeprom_array[7]=com_finger0_ratio_2_PARA3;
						 msg_eeprom_array[8]=com_finger0_ratio_3_PARA2;
						 msg_eeprom_array[9]=com_finger0_ratio_3_PARA3;
						 msg_eeprom_array[10]=com_finger1_ratio_1_PARA2;
						 msg_eeprom_array[11]=com_finger1_ratio_1_PARA3;
						 msg_eeprom_array[12]=com_finger1_ratio_2_PARA2;
						 msg_eeprom_array[13]=com_finger1_ratio_2_PARA3;
						 msg_eeprom_array[14]=com_finger1_ratio_3_PARA2;
						 msg_eeprom_array[15]=com_finger1_ratio_3_PARA3;
	
						 //获取EEPROM中存储的夹紧力阈值有效值高八位
						 command_data_read_force_high8(&force_judge);
						 msg_eeprom_array[16]=force_judge;
						 
						 delay(50);
						 uart0_send_string_with_num(msg_eeprom_array,17);//上传EEPROM中存储的数值
	
					 }
	
					 
					 if(array_cmp(uart0_instr,"1100")==0)//松开
				 	 {
				         if(release_allow_motor_0)
						 {
						     //构造舵机指令
							 motor_command[2]=0x00;//ID=0
						 	 motor_command[6]=com_finger0_ratio_3_PARA2;
						 	 motor_command[7]=com_finger0_ratio_3_PARA3+0x04;
						 	 CHECK=ratio_command_check(0,com_finger0_ratio_3_PARA2,com_finger0_ratio_3_PARA3+0x04);
						 	 motor_command[8]=CHECK;
						 	 delay(50);
						 	 uart1_send_string(motor_command,9);//下发指令
						 }
						 
						 if(release_allow_motor_1)
						 {
						     //构造舵机指令
							 motor_command[2]=0x01;//ID=1
						 	 motor_command[6]=com_finger1_ratio_3_PARA2;
						 	 motor_command[7]=com_finger1_ratio_3_PARA3+0x04;
						 	 CHECK=ratio_command_check(1,com_finger1_ratio_3_PARA2,com_finger1_ratio_3_PARA3+0x04);
						 	 motor_command[8]=CHECK;
						 	 delay(50);
						 	 uart1_send_string(motor_command,9);//下发指令
						 }
				 	 }
				 
				 	 if(array_cmp(uart0_instr,"1200")==0)//夹紧
				 	 {
				         if(hold_allow_motor_0 & hold_allow_motor_1)
						 {
						     //第一阶段
							 //构造舵机指令
							 motor_command[2]=0x00;//ID=0
						 	 motor_command[6]=com_finger0_ratio_1_PARA2;
						 	 motor_command[7]=com_finger0_ratio_1_PARA3;
						 	 CHECK=ratio_command_check(0,com_finger0_ratio_1_PARA2,com_finger0_ratio_1_PARA3);
						 	 motor_command[8]=CHECK;
						 	 delay(50);
						 	 uart1_send_string(motor_command,9);//下发指令
							 
							 //构造舵机指令
							 motor_command[2]=0x01;//ID=1
						 	 motor_command[6]=com_finger1_ratio_1_PARA2;
						 	 motor_command[7]=com_finger1_ratio_1_PARA3;
						 	 CHECK=ratio_command_check(1,com_finger1_ratio_1_PARA2,com_finger1_ratio_1_PARA3);
						 	 motor_command[8]=CHECK;
						 	 delay(50);
						 	 uart1_send_string(motor_command,9);//下发指令
	
							 approach_0=1;
							 approach_1=1;
							 
							 //等接近开关触发,同时查询检测是否空夹
							 while((approach_0|approach_1)&&(PINE & BIT(7)))
							 {
	   						     if(approach_0)
								 {
								     if(!(PINE & BIT(2)))//PE2=0进入
									 {
		        					     delay(50);
										 if(!(PINE & BIT(2)))
										 {
			        					     uart1_send_string((uchar*)no0stop,9);
											 //uart0_send_string(" interrupt 5 ");
											 approach_0=0;
			    						 }
			
		    						 }
							 	 }
		
	    					 	 if(approach_1)
								 {
    	    					     if(!(PINE & BIT(3)))//PE3=0进入
	    						 	 {
		       					          delay(50);
								  	  	  if(!(PINE & BIT(3)))
								  	  	  {
			        			  	          uart1_send_string((uchar*)no1stop,9);
								  		  	  //uart0_send_string(" interrupt 6 ");
								  		  	  approach_1=0;
			    				          }
		    					     }
								 }
							 }
							 
							 if(PINE & BIT(7))//不空夹则进行第二阶段
							 {
							    //第二阶段
							 	//构造舵机指令
							 	motor_command[2]=0x00;//ID=0
						 	 	motor_command[6]=com_finger0_ratio_2_PARA2;
						 	 	motor_command[7]=com_finger0_ratio_2_PARA3;
						 	 	CHECK=ratio_command_check(0,com_finger0_ratio_2_PARA2,com_finger0_ratio_2_PARA3);
						 	 	motor_command[8]=CHECK;
						 	 	delay(50);
						 	 	uart1_send_string(motor_command,9);//下发指令
							 
							 	//构造舵机指令
								 motor_command[2]=0x01;//ID=1
						 	 	 motor_command[6]=com_finger1_ratio_2_PARA2;
						 		 motor_command[7]=com_finger1_ratio_2_PARA3;
						 	 	 CHECK=ratio_command_check(1,com_finger1_ratio_2_PARA2,com_finger1_ratio_2_PARA3);
						 		 motor_command[8]=CHECK;
						 	 	 delay(50);
						 	 	 uart1_send_string(motor_command,9);//下发指令
							 
							 	 //等待夹紧力达到阈值并继续判断是否空夹
							 	 force_high8=0;
								 hold_stage_2_continue=1;
							 	 while(hold_stage_2_continue && (PINE & BIT(7)))
							 	 {
								     force_ulong=ReadCount();
								 	 ulong_to_uchar_array(force_ulong);//目的是获取force_high8
									 if(force_high8>=force_judge)
									 {
									     hold_stage_2_continue=0;//下次循环跳出
										 
										 //停止舵机运行
							 	 		 delay(50);
							 	 		 uart1_send_string((uchar*)no0stop,9);
							 	 		 delay(50);
							 	 		 uart1_send_string((uchar*)no1stop,9);
							 
							 	 		 hold_allow_motor_0=0;//禁止0号手指向端部靠近
							 	 		 hold_allow_motor_1=0;//禁止1号手指向端部靠近
							 
							 	 		 //报告上位机已经夹紧
							 	 		 delay(50);
							 	 		 uart0_send_string("zz10");
										 delay(50);
							 	 		 uart0_send_string("zz10");
									 }
							 	 }
							 
							 	 
							 }
							 
						 }
				 	 }
					 
					 if(array_cmp(Type(uart0_instr),"13")==0)//设定手指0,Ratio 1
				 	 {
					     com_finger0_ratio_1_PARA2=uart0_instr[2];
						 com_finger0_ratio_1_PARA3=uart0_instr[3];
						 command_data_save_finger_0_ratio_1(com_finger0_ratio_1_PARA2,com_finger0_ratio_1_PARA3);
					 }
					 
					 if(array_cmp(Type(uart0_instr),"14")==0)//设定手指0,Ratio 2
				 	 {
					     com_finger0_ratio_2_PARA2=uart0_instr[2];
						 com_finger0_ratio_2_PARA3=uart0_instr[3];
						 command_data_save_finger_0_ratio_2(com_finger0_ratio_2_PARA2,com_finger0_ratio_2_PARA3);
					 }
					 
					 if(array_cmp(Type(uart0_instr),"15")==0)//设定手指0,Ratio 3
				 	 {
					     com_finger0_ratio_3_PARA2=uart0_instr[2];
						 com_finger0_ratio_3_PARA3=uart0_instr[3];
						 command_data_save_finger_0_ratio_3(com_finger0_ratio_3_PARA2,com_finger0_ratio_3_PARA3);
					 }
					 
					 if(array_cmp(Type(uart0_instr),"16")==0)//设定手指1,Ratio 1
				 	 {
					     com_finger1_ratio_1_PARA2=uart0_instr[2];
						 com_finger1_ratio_1_PARA3=uart0_instr[3];
						 command_data_save_finger_1_ratio_1(com_finger1_ratio_1_PARA2,com_finger1_ratio_1_PARA3);
					 }
					 
					 if(array_cmp(Type(uart0_instr),"17")==0)//设定手指1,Ratio 2
				 	 {
					     com_finger1_ratio_2_PARA2=uart0_instr[2];
						 com_finger1_ratio_2_PARA3=uart0_instr[3];
						 command_data_save_finger_1_ratio_2(com_finger1_ratio_2_PARA2,com_finger1_ratio_2_PARA3);
					 }
					 
					 if(array_cmp(Type(uart0_instr),"18")==0)//设定手指1,Ratio 3
				 	 {
					     com_finger1_ratio_3_PARA2=uart0_instr[2];
						 com_finger1_ratio_3_PARA3=uart0_instr[3];
						 command_data_save_finger_1_ratio_3(com_finger1_ratio_3_PARA2,com_finger1_ratio_3_PARA3);
					 }
					 
					 if(array_cmp(Type(uart0_instr),"19")==0)//设定force_judge
				 	 {
					     force_judge=uart0_instr[2];
						 command_data_save_force_high8(force_judge);
					 }
				 
				 	 break;
			     }
			 
		         case 2:
			     {
					 if(array_cmp(uart0_instr,"2100")==0)//调试模式·手指0停止
				 	 {
					     TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值
						 uart1_send_string((uchar*)no0stop,9);
				 	 }

					 if(array_cmp(uart0_instr,"2101")==0)//调试模式·手指0松开方向移动
				 	 {
					     if(release_allow_motor_0)
						 {
						     TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值
						 	 motor_command[2]=0x00;//ID=0
						 	 motor_command[6]=PARA2;
						 	 motor_command[7]=PARA3+0x04;//顺时针,绝对不可在此更改PARA3的值!
						 	 CHECK=ratio_command_check(0,PARA2,PARA3+0x04);
						 	 motor_command[8]=CHECK;
						 	 delay(50);
						 	 uart1_send_string(motor_command,9);
						 	 //delay(50);
						 	 //uart0_send_string_with_num(motor_command,9);
						 	 TIMSK|=BIT(2);//打开定时计数1中断,向上返回夹持力值
						 }
				 	 }
					 
					 if(array_cmp(uart0_instr,"2102")==0)//调试模式·手指0夹紧方向移动
				 	 {
					     if(hold_allow_motor_0)
						 {
						     TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值
						 	 motor_command[2]=0x00;//ID=0
						 	 motor_command[6]=PARA2;
						 	 motor_command[7]=PARA3;
						 	 CHECK=ratio_command_check(0,PARA2,PARA3);
						 	 motor_command[8]=CHECK;
						 	 delay(50);
						 	 uart1_send_string(motor_command,9);
						 	 //delay(50);
						 	 //uart0_send_string_with_num(motor_command,9);
						 	 TIMSK|=BIT(2);//打开定时计数1中断,向上返回夹持力值
						 }
				 	 }

					 if(array_cmp(uart0_instr,"2110")==0)//调试模式·手指1停止
				 	 {
					     TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值
						 uart1_send_string((uchar*)no1stop,9);
				 	 }

					 if(array_cmp(uart0_instr,"2111")==0)//调试模式·手指1松开方向移动
				 	 {
					     if(release_allow_motor_1)
						 {
						     TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值
						 	 motor_command[2]=0x01;//ID=1
						 	 motor_command[6]=PARA2;
						 	 motor_command[7]=PARA3+0x04;//顺时针,绝对不可在此更改PARA3的值!
						 	 CHECK=ratio_command_check(1,PARA2,PARA3+0x04);
						 	 motor_command[8]=CHECK;
						 	 delay(50);
						 	 uart1_send_string(motor_command,9);
						 	 //delay(50);
						 	 //uart0_send_string_with_num(motor_command,9);
						 	 TIMSK|=BIT(2);//打开定时计数1中断,向上返回夹持力值
						 }
				 	 }
					 
					 if(array_cmp(uart0_instr,"2112")==0)//调试模式·手指1夹紧方向移动
				 	 {
					     if(hold_allow_motor_1)
						 {
						     TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值
						 	 motor_command[2]=0x01;//ID=1
						 	 motor_command[6]=PARA2;
						 	 motor_command[7]=PARA3;
						 	 CHECK=ratio_command_check(1,PARA2,PARA3);
						 	 motor_command[8]=CHECK;
						 	 delay(50);
						 	 uart1_send_string(motor_command,9);
						 	 //delay(50);
						 	 //uart0_send_string_with_num(motor_command,9);
						 	 TIMSK|=BIT(2);//打开定时计数1中断,向上返回夹持力值
						 }
				 	 }

					 if(array_cmp(Type(uart0_instr),"22")==0)
				 	 {
						 TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值
						 delay(50);
						 uart1_send_string((uchar*)no0stop,9);
						 delay(50);
						 uart1_send_string((uchar*)no1stop,9);
						 PARA2=uart0_instr[2];
						 PARA3=uart0_instr[3];
						 //delay(50);
						 //uart0_send_string("ratio changed");
				 	 }
					 
					 if(array_cmp(uart0_instr,"2301")==0)//调试模式·设置手指0速度1(两指相同)夹紧第一阶段
				 	 {
					     command_data_save_finger_0_ratio_1(PARA2,PARA3);
						 //delay(50);
						 //uart0_send_string(" Finger-0 Ratio-1 Set Successfully! ");
					 }
					 
					 if(array_cmp(uart0_instr,"2302")==0)//调试模式·设置手指0速度2(两指相同)夹紧第二阶段
				 	 {
					     command_data_save_finger_0_ratio_2(PARA2,PARA3);
						 //delay(50);
						 //uart0_send_string(" Finger-0 Ratio-2 Set Successfully! ");
					 }
					 
					 if(array_cmp(uart0_instr,"2303")==0)//调试模式·设置手指0速度3(两指相同)松开阶段
				 	 {
					     command_data_save_finger_0_ratio_3(PARA2,PARA3);
						 //delay(50);
						 //uart0_send_string(" Finger-0 Ratio-3 Set Successfully! ");
					 }
					 
					 if(array_cmp(uart0_instr,"2311")==0)//调试模式·设置手指1速度1(两指相同)夹紧第一阶段
				 	 {
					     command_data_save_finger_1_ratio_1(PARA2,PARA3);
						 //delay(50);
						 //uart0_send_string(" Finger-1 Ratio-1 Set Successfully! ");
					 }
					 
					 if(array_cmp(uart0_instr,"2312")==0)//调试模式·设置手指1速度2(两指相同)夹紧第二阶段
				 	 {
					     command_data_save_finger_1_ratio_2(PARA2,PARA3);
						 //delay(50);
						 //uart0_send_string(" Finger-1 Ratio-2 Set Successfully! ");
					 }
					 
					 if(array_cmp(uart0_instr,"2313")==0)//调试模式·设置手指1速度3(两指相同)松开阶段
				 	 {
					     command_data_save_finger_1_ratio_3(PARA2,PARA3);
						 //delay(50);
						 //uart0_send_string(" Finger-1 Ratio-3 Set Successfully! ");
					 }
					 
					 if(array_cmp(Type(uart0_instr),"24")==0)//调试模式·设置夹紧力阈值
				 	 {
					     force_judge=uart0_instr[2];
						 command_data_save_force_high8(force_judge);
						 //delay(50);
						 //uart0_send_string(" Force Set Successfully! ");
					 }
					 
					 
					 if(array_cmp(uart0_instr,"2500")==0)//调试模式·读取EEPROM中存储的RATIO和力阈值
				 	 {
						 //更新ratio变量值、力阈值和消息数组的值
						 
						 //获取EEPROM中存储的RATIO值
    					 command_data_read_finger_0_ratio_1(&com_finger0_ratio_1_PARA2,&com_finger0_ratio_1_PARA3);
						 command_data_read_finger_0_ratio_2(&com_finger0_ratio_2_PARA2,&com_finger0_ratio_2_PARA3);
						 command_data_read_finger_0_ratio_3(&com_finger0_ratio_3_PARA2,&com_finger0_ratio_3_PARA3);
						 command_data_read_finger_1_ratio_1(&com_finger1_ratio_1_PARA2,&com_finger1_ratio_1_PARA3);
						 command_data_read_finger_1_ratio_2(&com_finger1_ratio_2_PARA2,&com_finger1_ratio_2_PARA3);
						 command_data_read_finger_1_ratio_3(&com_finger1_ratio_3_PARA2,&com_finger1_ratio_3_PARA3);
	
						 msg_eeprom_array[0]='z';
						 msg_eeprom_array[1]='z';
						 msg_eeprom_array[2]='3';
						 msg_eeprom_array[3]='3';
						 msg_eeprom_array[4]=com_finger0_ratio_1_PARA2;
						 msg_eeprom_array[5]=com_finger0_ratio_1_PARA3;
						 msg_eeprom_array[6]=com_finger0_ratio_2_PARA2;
						 msg_eeprom_array[7]=com_finger0_ratio_2_PARA3;
						 msg_eeprom_array[8]=com_finger0_ratio_3_PARA2;
						 msg_eeprom_array[9]=com_finger0_ratio_3_PARA3;
						 msg_eeprom_array[10]=com_finger1_ratio_1_PARA2;
						 msg_eeprom_array[11]=com_finger1_ratio_1_PARA3;
						 msg_eeprom_array[12]=com_finger1_ratio_2_PARA2;
						 msg_eeprom_array[13]=com_finger1_ratio_2_PARA3;
						 msg_eeprom_array[14]=com_finger1_ratio_3_PARA2;
						 msg_eeprom_array[15]=com_finger1_ratio_3_PARA3;
	
						 //获取EEPROM中存储的夹紧力阈值有效值高八位
						 command_data_read_force_high8(&force_judge);
						 msg_eeprom_array[16]=force_judge;
						 
						 delay(50);
						 uart0_send_string_with_num(msg_eeprom_array,17);//上传EEPROM中存储的数值
	
					 }
					 
				     break;
			     }
			 
		         default:break;
			 }
			 
			 if(array_cmp(uart0_instr,"3100")==0)//恢复触碰报警 ext interrupt 0 
			 {
			     ext_collision_alert_allow_int0=1;//上侧
			 }
			 
			 if(array_cmp(uart0_instr,"3200")==0)//恢复触碰报警 ext interrupt 1 
			 {
			     ext_collision_alert_allow_int1=1;//下侧
			 }
			 
			 if(array_cmp(uart0_instr,"3300")==0)//恢复触碰报警 ext interrupt 4 
			 {
			     ext_collision_alert_allow_int4=1;//指尖
			 }
			 
			 if(array_cmp(uart0_instr,"3400")==0)//读取报警允许变量的状态
			 {
			     msg_interrupt_array[4]=ext_collision_alert_allow_int0;
				 msg_interrupt_array[5]=ext_collision_alert_allow_int1;
				 msg_interrupt_array[6]=ext_collision_alert_allow_int4;
				 uart0_send_string_with_num(msg_interrupt_array,7);
			 }
			 
			 /*末尾应完成命令执行后的还原工作A-D*/
			 uart0_instr_flag=0; //A.命令接收标志位置0
			 uart0_r_instr_chk=0;//B.命令构造字符数计数置0
			 for(i=0;i<12;i++)//C.命令清除
			 {
		         uart0_instr[i]=0;
			 }
			 UCSR0B|=BIT(RXCIE0);//D.恢复UART0的接收中断			
	     }
		 

		/*
		    【偏向撞击保护的编程】
			(1)一旦手指碰撞到限位开关产生低电平,哪怕是抖动、不稳定的低电平,
			也要禁止手指继续向碰撞位置移动,此时不需要延迟防抖的处理;
			(2)只有当手指真正完全地离开了碰撞地点,限位开关IO成为稳定的高电平,
			才允许手指再次向碰撞的方向移动。
		*/
		
		if(!(PINE & BIT(5)))//检测手指0是否复位
		{
			if(stop_allow_cage_0)
			{
			    release_allow_motor_0=0;//禁止1号手指向端部靠近
				hold_allow_motor_0=1;//允许1号手指向中间靠近
				TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值
				delay(50);
				uart1_send_string((uchar*)no0stop,9);
				delay(50);
				uart0_send_string("zz30");
				delay(50);
				uart0_send_string("zz30");
				stop_allow_cage_0=0;
			}
		}
		else
		{
		    if(!stop_allow_cage_0)
			{
			    delay(500);
			    if(PINE & BIT(5))
				{
				    release_allow_motor_0=1;//允许1号手指向端部靠近
					stop_allow_cage_0=1;
				}
			}
		}
		
		if(!(PINE & BIT(6)))//检测手指1是否复位
		{
			if(stop_allow_cage_1)
			{
			    release_allow_motor_1=0;//禁止1号手指向端部靠近
				hold_allow_motor_1=1;//允许1号手指向中间靠近
				TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值
				delay(50);
				uart1_send_string((uchar*)no1stop,9);
				delay(50);
				uart0_send_string("zz31");
				delay(50);
				uart0_send_string("zz31");
				stop_allow_cage_1=0;
			}
		}
		else
		{
			if(!stop_allow_cage_1)
			{
			    delay(500);
			    if(PINE & BIT(6))
				{
				    release_allow_motor_1=1;//允许1号手指向端部靠近
					stop_allow_cage_1=1;
				}
			}
		}

		if(!(PINE & BIT(7)))//检测是否空夹
		{
			if(stop_allow_empty)
			{
			    hold_allow_motor_0=0;//禁止0号手指向端部靠近
				hold_allow_motor_1=0;//禁止1号手指向端部靠近
				TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值
				delay(50);
				uart1_send_string((uchar*)no1stop,9);
				delay(50);
				uart1_send_string((uchar*)no0stop,9);
				delay(50);
				uart0_send_string("zz32");
				delay(50);
				uart0_send_string("zz32");
				stop_allow_empty=0;
			}
		}
		else
		{
			if(!stop_allow_empty)
			{
			    delay(500);
			    if(PINE & BIT(7))
				{
				    hold_allow_motor_0=1;//允许0号手指向中间靠近
					hold_allow_motor_1=1;//允许1号手指向中间靠近
					stop_allow_empty=1;
				}
			}
		}
		
	}
}