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

📄 调试程序1.i

📁 这段程序是步进电机的细分驱动程序
💻 I
📖 第 1 页 / 共 4 页
字号:
		mustermotor_contorl (500,1);

	    if(Work.clear_select==1)
		   {
			   if(Work.mission_number)
			       armround_control1(1,3,9421);
			   else
			       armround_control1(2,3,12103);


			   DelayMs(20);
			   arm_down(6650*8);

			   ArmState=1;
			   mustermotor_contorl (volume+1300,0);
		       DelayMs(10);
		       arm_up ();

			  ArmState=0;

		      over_flag=1;

			  armround_control1(3,0,5718);
		  }
		  else
		  {
			if(Work.mission_number)
			  armround_control1(1,0,3703);
		      else
		          armround_control1(2,0,6385);
		  }

			  DelayMs(20);

			  arm_down(3120*8);
		      OutputMotor(0x02,0x00,0x00);
			  mustermotor_init();
	          Pump_Delay(clear_S);

			 DelayMs(100);

		     if(Work.clear_select==0)
		     over_flag=2;

    }



void   motor_right (unsigned char motor_number,unsigned char modulus ,unsigned int delaytime)
   {unsigned int t;
 unsigned char  change;
	   OutputMotor(motor_number,H1DACData[step1[motor_number]],H2DACData[step1[motor_number]]);
	   step1[motor_number]+=modulus;
	   for(t=0;t<delaytime;t++);
	}



void   motor_left (unsigned char motor_number,unsigned char modulus,unsigned int delaytime)
   {unsigned int t;
 unsigned char  change;
       OutputMotor(motor_number,H1DACData[step1[motor_number]],H2DACData[step1[motor_number]]);
	   step1[motor_number]-=modulus;
	   for(t=0;t<delaytime;t++);
	 }




 void  arm_up (void)
   {
 unsigned int i,Count;
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
      g[0]=(*(volatile unsigned char *)0x30)&0x04;


	  for(Count=0;Count<1500;Count++)
	  {
	  	   motor_right (1,1,1550-Count);
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
      	   g[0]=(*(volatile unsigned char *)0x30)&0x04;
		   if(!g[0])
		   {
			   break;
		   }
	  }


	  if(ArmState==1)
	  {
	   	  for(i=52800-2*1500;i>0;i--)
	 	   {
		     	motor_right (1,1,50);
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
      	   		g[0]=(*(volatile unsigned char *)0x30)&0x04;
		   		if(!g[0])
		   		{
			   	 break;
		   		}
	  		}
	  }
	  else
	  {
	   	  for(i=26400-2*1500;i>0;i--)
	 	   {
		     	motor_right (1,1,50);
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
      	   		g[0]=(*(volatile unsigned char *)0x30)&0x04;
		   		if(!g[0])
		   		{
			   	 break;
		   		}
	  		}
	  }


	  for(Count=0;Count<1500;Count++)
	  {
	  	   motor_right (1,1,50+Count);
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
      	   g[0]=(*(volatile unsigned char *)0x30)&0x04;
		   if(!g[0])
		   {
			   break;
		   }
	  }

       while(g[0])
       {
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
        g[0]=(*(volatile unsigned char *)0x30)&0x04;
        motor_right (1,1,1550);
	   }

	      for(i=0;i<10;i++)
	       {
		    motor_left (1,1,1550);
		   }
		  for(i=0;i<50;i++)
	       {
		      motor_right (1,1,1550);
		   }
	      while(g[0]);
		  OutputMotor(0x01,0x00,0x00);

    }



 void   armround_init  (void)
    {unsigned int  i;
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
	  g[1]=(*(volatile unsigned char *)0x30)&0x08;
	if(g[1])
	   {
	    for(i=0;i<1500;i++)
	     {
		   motor_left (2,1,600);
		 }
	    }
	  else
	    {
	    for(i=0;i<1500;i++)
	     {
		   motor_right (2,1,600);
		 }
	    }

	  g[1]=(*(volatile unsigned char *)0x30)&0x08;
     if(g[1]==0)
	    {

	       g[1]=(*(volatile unsigned char *)0x30)&0x08;
		   while(g[1]==0)
		    {

	          g[1]=(*(volatile unsigned char *)0x30)&0x08;
			  motor_right (2,1,600);
		     }
		}
	 else
      {

	        g[1]=(*(volatile unsigned char *)0x30)&0x08;
			while(g[1])
		     {

	           g[1]=(*(volatile unsigned char *)0x30)&0x08;
			   motor_left (2,1,600);
		     }
		   }

            g[5]=(*(volatile unsigned char *)0x30)&0x10;
            if(g[5])
	     {
	   		for(i=400;i>0;i--)
			{
			     motor_right (2,1,600);
			}

			while(1)
			{
			 	  g[5]=(*(volatile unsigned char *)0x30)&0x10;
				  if(g[5])
				  break;
			      motor_left(2,1,600);
			}
			for(i=0;i<82;i++)
	       {
	         motor_left (2,1,600);
	       }

	   }

 }



 void  plate_init  (void)
   {
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
	  g[2]=(*(volatile unsigned char *)0x30)&0x40;
	  while(g[2]==0)
	    {
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
	      g[2]=(*(volatile unsigned char *)0x30)&0x40;
	      motor_right (3,1,400);
	    }

(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
	  g[4]=(*(volatile unsigned char *)0x30)&0x20;
	  while(g[4]==0)
	    {
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
	      g[4]=(*(volatile unsigned char *)0x30)&0x20;
	      motor_right (3,1,400);
	    }

	}



 void  mustermotor_init (void)
   {
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
	  g[3]=(*(volatile unsigned char *)0x30)&0x80;
	  while(g[3])
	   {
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
	     g[3]=(*(volatile unsigned char *)0x30)&0x80;
	     motor_left (4,2,350);
	   }
	      while(g[3]);
         OutputMotor(0x04,0x00,0x00);
	}



 void  arm_down (unsigned int  down)
   {
   	   unsigned  int  s,Count;

   	   for(Count=0;Count<1500;Count++)
	   {
	       motor_left (1,1,1550-Count);
	   }

	   for (s=down-2*1500;s>0;s--)
       {
          motor_left (1,1,50);
		  needle_egis ();
       }
       for(Count=0;Count<1500;Count++)
	   {
	       motor_left (1,1,50+Count);
		   needle_egis ();
	   }
   	   OutputMotor(0x01,0x00,0x00);
   }





  void  mustermotor_contorl (unsigned int any_muter,unsigned char updown)
  {unsigned int i;
     if(updown)
      {
        for (i=0;i<any_muter;i++)
           {
             motor_right (4,2,350);
           }
      }
    else
      {
        for (i=0;i<any_muter;i++)
          {
            motor_left (4,2,350);
          }
      }
	       OutputMotor(0x04,0x00,0x00);
  }



  void   plate_oneround  (void)
  {unsigned int i;
       for(i=0;i<640;i++)
	     {
            motor_right (3,1,500);
         }
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
	        g[4]=(*(volatile unsigned char *)0x30)&0x20;
	        while(g[4]==0)
	         {
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
	           g[4]=(*(volatile unsigned char *)0x30)&0x20;
	           motor_right (3,1,500);
	         }
		    while(g[4]==0);
  }





  void   plate_round  (unsigned char newplate_number,unsigned char sample)
 {unsigned int i,y;
    if (sample)
      {
	    if(newplate_number>30)
		   newplate_number=30;
	       if(newplate_number>=oldplate_number)
		   plate_sport=newplate_number-oldplate_number;
		   else
		   plate_sport=(newplate_number+30)-oldplate_number;
	          for(i=0;i<plate_sport;i++)
	             {
                  plate_oneround();
		         }
	              oldplate_number=newplate_number;
	  }
    else
      {
	     if(newplate_number>5)
		    newplate_number=5;
            if(((newplate_number-1)*6)>=(oldplate_number-1))
		        plate_sport=((newplate_number-1)*6)-(oldplate_number-1);
	        else
			    plate_sport=(((newplate_number-1)*6)+30)-(oldplate_number-1);

		          for(i=0;i<plate_sport;i++)
	                {
	                  plate_oneround();
                    }
			          oldplate_number=(newplate_number-1)*6+1;
	   }

	 if(oldplate_number>30)
	    oldplate_number-=30;

  }








void armround_move(unsigned char leftOrRight,unsigned char GuOu,unsigned long movenum)
{
 unsigned long count;
 unsigned long GuOucount=0;

	if(GuOu==1)
		GuOucount=4500;
	else if(GuOu==2)
		GuOucount=8000;

	if(leftOrRight==0)
	{
		for(count=0;count<400;count++)
		{
			motor_left(2,1,1100-count*2);
		}
	}
	else
	{
		for(count=0;count<400;count++)
		{
			motor_right(2,1,1100-count*2);
		}
	}



	if(leftOrRight==0)
	{
		for(count=GuOucount;count>0;count--)
		{
			motor_left(2,1,300);
		}
	}
	else
	{
		for(count=GuOucount;count>0;count--)
		{
			motor_right(2,1,300);
		}
	}



	if(leftOrRight==0)
	{
		for(count=movenum-GuOucount-400*2-82;count>0;count--)
		{

	        g[5]=(*(volatile unsigned char *)0x30)&0x10;
			if(g[5]!=0)
				break;
			motor_left(2,1,300);
		}
	}
	else
	{
		for(count=movenum-GuOucount-400*2-82;count>0;count--)
		{

	        g[5]=(*(volatile unsigned char *)0x30)&0x10;
			if(g[5]!=0)
				break;
			motor_right(2,1,300);
		}
	}

	if(leftOrRight==0)
	{
		for(count=0;count<400;count++)
		{

	        g[5]=(*(volatile unsigned char *)0x30)&0x10;
			if(g[5]!=0)
				break;
			motor_left(2,1,300+count*2);
		}
	}
	else
	{
		for(count=0;count<400;count++)
		{

	        g[5]=(*(volatile unsigned char *)0x30)&0x10;
			if(g[5]!=0)
				break;
			motor_right(2,1,300+count*2);
		}
	}


	if(leftOrRight==0)
	{
		while(1)
		{

	        g[5]=(*(volatile unsigned char *)0x30)&0x10;
			if(g[5]!=0)
				break;
			motor_left(2,1,1100);
		}
	}
	else
	{
		while(1)
		{

	        g[5]=(*(volatile unsigned char *)0x30)&0x10;
			if(g[5]!=0)
				break;
			motor_right(2,1,1100);
		}
	}

}






void armround_control1(unsigned char initstate,unsigned char endstate,unsigned long movenum)
{
 unsigned long count;
	if( (initstate==0) && (endstate==1) )
	{
		armround_move(0,0,movenum);
		for(count=0;count<15+yp_value;count++)
		     motor_left(2,1,1100);
	}
	else if( (initstate==0) && (endstate==2) )
	{
		armround_move(0,1,movenum);
		for(count=0;count<15+by_value;count++)
		     motor_left(2,1,1100);
	}
	else if( (initstate==2) && (endstate==3) )
	{
		armround_move(1,2,movenum);
		for(count=0;count<(15+wz_value);count++)
		     motor_right(2,1,1100);
	}
	else if( (initstate==2) && (endstate==0) )
	{
		armround_move(1,1,movenum);

        for(count=0;count<400;count++)
		    motor_right(2,1,1100);

		while(1)
		{
		     g[5]=(*(volatile unsigned char *)0x30) & 0x10;
			 if(g[5])
			      break;
			motor_left(2,1,1100);
		}
		for(count=0;count<82;count++)
		     motor_left(2,1,1100);
	}
	else if( (initstate==1) && (endstate==0) )
	{
		armround_move(1,0,movenum);

		for(count=0;count<400;count++)
		    motor_right(2,1,1100);

		while(1)
		{
		     g[5]=(*(volatile unsigned char *)0x30) & 0x10;
			 if(g[5])
			      break;
			motor_left(2,1,1100);
		}
		for(count=0;count<82;count++)
		     motor_left(2,1,1100);
	}
	else if( (initstate==1) && (endstate==3) )
	{
		armround_move(1,1,movenum);

		for(count=0;count<(15+wz_value);count++)
		     motor_right(2,1,1100);
	}
	else if( (initstate==0) && (endstate==3) )
	{
		armround_move(1,0,movenum);

		for(count=0;count<15+wz_value;count++)
		     motor_right(2,1,1100);
	}
	else if( (initstate==3) && (endstate==0) )
	{
	 	 armround_move(0,0,movenum);

		 for(count=0;count<82;count++)
		     motor_left(2,1,1100);
    }

}




#pragma  interrupt_handler TIMER1: 15
void   TIMER1  (void)
  {unsigned int i;
 asm("cli");
(*(volatile unsigned int *)0x4C) = 0X78F5;
(*(volatile unsigned int *)0x4C) = 0X78F5;
	  switch(over_flag)
	   {
		 case 0:
		 TxdBuf[0]=0x00;
		 break;
		 case 1:
		 {
		   over_flag=0;
	       TxdBuf[0]=0x0A;
(*(volatile unsigned char *)0x4E) = 0x00;
		   break;
		  }
		 case 2:
		 {
		 over_flag=0;
	     TxdBuf[0]=0x0B;
(*(volatile unsigned char *)0x4E) = 0x00;
		 break;
		 }
		 default:
		 break;
		 }
(*(volatile unsigned char *)0x30)=(*(volatile unsigned char *)0x32);
	       TxdBuf[1]=(*(volatile unsigned char *)0x30)&0X3F;
		   D12_WriteEndpoint(3,2,TxdBuf);
 asm("sei");

   }



 void  write_eeprom  (void)
  {
(*(volatile unsigned char *)0x59) = 0x00;
      while((*(volatile unsigned char *)0x3C)&0X02);
      switch( Debugger.place_number)
       {
         case 0:
(*(volatile unsigned int *)0x3E)=0X0001;
              break;
         case 1:
(*(volatile unsigned int *)0x3E)=0X0002;
              break;
         case 2:
(*(volatile unsigned int *)0x3E)=0X0003;
              break;
         case 3:
(*(volatile unsigned int *)0x3E)=0X0004;
              break;
         default:
              break;
       }

(*(volatile unsigned char *)0x3D)=Debugger.recoup_value;
(*(volatile unsigned char *)0x3C)|=0X04;
(*(volatile unsigned char *)0x3C)|=0X02;
(*(volatile unsigned char *)0x59) = 0x01;
  }



 unsigned char  read_eeprom (unsigned int  address)
  {
(*(volatile unsigned char *)0x59) = 0x00;
    while((*(volatile unsigned char *)0x3C)&0X02);
(*(volatile unsigned int *)0x3E)=address;
(*(volatile unsigned char *)0x3C)|=0X01;
	return(*(volatile unsigned char *)0x3D);
(*(volatile unsigned char *)0x59) = 0x01;
 }



 void   eeprom_value (void)
  {
	free=read_eeprom (0x0000);
	by_value=read_eeprom (0x0001);
    yp_value=read_eeprom (0x0002);
    wz_value=read_eeprom (0x0003);
    zx_value=read_eeprom (0x0004);
    zx_value=zx_value*16;

  }




void main(void)
{
   unsigned int  k,u,ii;
   unsigned char Data;
   unsigned char StrLen;

   unsigned int TestCount;
   unsigned int TestCount1;
   unsigned char LeftOrRight=0;

  for(u=0;u<10000;u++);


   init_devices();
   INT_Init();

(*(volatile unsigned char *)0x62) = 0xFF;
   InitMotor(0x01);
   InitMotor(0x02);
   InitMotor(0x03);
   InitMotor(0x04);
   OutputMotor(0x01,0x00,0x00);
   OutputMotor(0x02,0x00,0x00);
   OutputMotor(0x03,0x00,0x00);
   OutputMotor(0x04,0x00,0x00);




   eeprom_value();

   ArmState=0;

(*(volatile unsigned char *)0x59) = 0x00;
   reconnect_USB();
(*(volatile unsigned char *)0x59) = 0x01;

(*(volatile unsigned char *)0x4F)=0x00;
(*(volatile unsigned char *)0x4E) =0x00;

(*(volatile unsigned int *)0x4C) = 0XFFFF;
(*(volatile unsigned int *)0x4C) = 0XFFFF;
   while(1)
    {



		if (setup_packet)
		{

(*(volatile unsigned char *)0x59) = 0x00;
			setup_packet = 0;
(*(volatile unsigned char *)0x59) = 0x01;
			control_handler();
		}

#line 2177 "D:\LZY归档\最新进样器文件\最新带锁进样器程序\调试程序1.c"
	    if(reset_flag==1)
	    {
		    reset_flag=0;
		    muster_init();
			oldplate_number=1;
		}

	    if(Work_flag)
	    {
		   Work_flag=0;
		   if(Work.clear_select<2)
		  {
		    one_course ();
		    Work_flag=0;
		  }
           else if(Work.clear_select==2)
			push_air();
		}
        if(debug_flag==1)
         {
           debug_flag=0;
           if(Debugger.place_number<4)
               write_eeprom();

		   if(Debugger.place_number==6)
			 {
              switch( Debugger.init_place)
               {
				case 0:
			     {
                   armup_init ();
	               armround_init();
				   break;
                 }
			    case 1:
				 {
				   armup_init ();
	               plate_init();
				   armround_init();
				   armround_control1(0,2,6385);
				   break;
				  }
			     case 2:
				  {
				   armup_init ();
	               plate_init();
				   armround_init();
				   armround_control1(0,1,3703);
				   break;
				  }
				  case 3:
				  {
				   armup_init ();
				   armround_init();
				   armround_control1(0,3,5718);
				   break;
				  }
				  default:
				  break;
			  }
	     }

	   else if(Debugger.place_number==7)
		 {
		   switch(Debugger.armup_down)
			{
			  OutputMotor(0x02,0x00,0x00);
			  case 0:
			   {
			     for(k=0;k< Debugger.setp_num;k++)
	              {
		            motor_left (1,8,800);
		          }
			     break;
			   }
			  case 1:
			   {
				 for(k=0;k< Debugger.setp_num;k++)
	              {
		            motor_right (1,8,800);
		          }
				 break;
			   }
			  default:
			  break;
			 }
		   }

		else if(Debugger.place_number==4)
		 {
		     if(Debugger.water_pump==1)
(*(volatile unsigned char *)0x62)&=0XFE;
             else
(*(volatile unsigned char *)0x62)|=0X01;
		 }

	   else if(Debugger.place_number==5)
		 {
             if(Debugger.air_pump==1)
(*(volatile unsigned char *)0x62)&=0XFC;
             else
(*(volatile unsigned char *)0x62)|=0X02;
			   }

	      }
     }
 }





















⌨️ 快捷键说明

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