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

📄 _io.c

📁 全自动剥线机(C语言源码+DOC文档说明)
💻 C
📖 第 1 页 / 共 5 页
字号:
   { *g_char_ptr = CN_CUTOPENHG; } /* the cutter motor open direction.  */
   TH0 = CNCUTTACCE[d_speed][0];
   TL0 = CNCUTTACCE[d_speed][1];
   d_halfpulse =(d_dist/2)+(d_dist%2);
   g_generalbit = TRUE;
   TR0 = 1; /* start the Timer0. */
   for(d_counter=0;d_counter<d_dist;d_counter++)
   {
      g_char_ptr = (uchar xdata *)AD_CUMOTOR;
      Reset_Watchdog();
      if(d_movedirect==CN_CUTCLOSE)
      { *g_char_ptr = CN_CUTCLOSLW; }
      else
      { *g_char_ptr = CN_CUTOPENLW; }
      if(acckind==CN_CUTACCEL)  /* the accelerate. */
      {
         if(d_counter<d_halfpulse)  /* the accelerate stage.   */
         {
            if(d_counter<CNCUTACCSTEP)
            {
               g_thvalue = CNCUTTACCE[d_speed][d_counter*2];
               g_tlvalue = CNCUTTACCE[d_speed][d_counter*2+1];
            }
            else
            {   
               g_thvalue = CNCUTTACCE[d_speed][(CNCUTACCSTEP-1)*2];
               g_tlvalue = CNCUTTACCE[d_speed][(CNCUTACCSTEP-1)*2+1];
            }   
         } 
         else /* the decelerate stage. */
         {
            if((d_dist-d_counter)<CNCUTACCSTEP)
            {
               g_thvalue = CNCUTTACCE[d_speed][(d_dist-d_counter-1)*2];
               g_tlvalue = CNCUTTACCE[d_speed][(d_dist-d_counter-1)*2+1];
            }
            else
            {
               g_thvalue = CNCUTTACCE[d_speed][(CNCUTACCSTEP-1)*2];
               g_tlvalue = CNCUTTACCE[d_speed][(CNCUTACCSTEP-1)*2+1];
            }     	 
         }
      }
      else  /* the constant accelerate. */
      {
         g_thvalue = CNCUTTACCE[d_speed][0];
         g_tlvalue = CNCUTTACCE[d_speed][1];
      }	
      Delay_us(CN_10us);
      if(d_movedirect==CN_CUTCLOSE)
      { *g_char_ptr = CN_CUTCLOSHG; }
      else
      { *g_char_ptr = CN_CUTOPENHG; }
      for(;g_generalbit==TRUE;)
      {} /* wait for Timer0 interrupt. */
      g_generalbit=TRUE;
   }
   TR0 = 0; /* stop the Timer0. */
}    

#if CN_AUTODETECT
/***************************************************************************

NAME:       Cutter_Detectrad

FUNCTION:   This procedure will move the cutter to auto detect the wire radius.  

INPUTS:     None

OUTPUTS:    NONE

***************************************************************************/
void Cutter_Detectrad()
{
   uchar d_counter;
   uchar d_speed;
   
   g_char_ptr = (uchar xdata *)(AD_CURPROG+AD_RUNSPEED);
   d_speed = *g_char_ptr; /* get the current speed stage. */	      	
   g_char_ptr = (uchar xdata *)AD_CUMOTOR;
  *g_char_ptr = CN_CUTCLOSHG;     /* the cutter motor close direction. */
   TH0 = CN_RADDETECT[d_speed][0];
   TL0 = CN_RADDETECT[d_speed][1];
   g_generalbit = TRUE;
   TR0 = 1; /* start the Timer0. */
   for(d_counter=0;d_counter<CN_ZEROTOCLOSE;d_counter++)
   {
      g_char_ptr = (uchar xdata *)AD_CUMOTOR;
      Reset_Watchdog();
     *g_char_ptr = CN_CUTCLOSLW;
      if(d_counter<CNCUTDCTSTEP)
      {
         g_thvalue = CN_RADDETECT[d_speed][d_counter*2];
         g_tlvalue = CN_RADDETECT[d_speed][d_counter*2+1];
      }
      else
      {   
         g_thvalue = CN_RADDETECT[d_speed][(CNCUTDCTSTEP-1)*2];
         g_tlvalue = CN_RADDETECT[d_speed][(CNCUTDCTSTEP-1)*2+1];
      }  
      Delay_us(CN_10us);
     *g_char_ptr = CN_CUTCLOSHG;
      for(;g_generalbit==TRUE;)
      {} /* wait for Timer0 interrupt. */
      g_generalbit=TRUE;
   }
   TR0 = 0; /* stop the Timer0. */
}
#endif       

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

NAME:       Cut_Rst_Failure

FUNCTION:   This procedure will handle the cutter reset failure event.  

INPUTS:     NONE

OUTPUTS:    NONE

***************************************************************************/
void Cut_Rst_Failure()
{
   g_systemsta = CN_INFOSTA;
   Init_Crystal();
   Proinfo_Show(CN_CUTTDAMAGE);
   CN_LAMPON;     /* the lamp on. */
   g_lamponflag = TRUE;  /* show the lamp on. */
   g_outsw = CN_ALARMON;    /* the alarm on.          */
   g_char_ptr = (uchar xdata *)AD_OUTPUT;  /* point to the output port. */
  *g_char_ptr = g_outsw;    /* IO command output.     */ 
   g_fin_or_troub = FALSE;   /* the trouble mode.     */
   g_alarmflag = TRUE;      /* the system alarm mode. */
   g_t2counter = CN_330ms;  /* 330ms delay.           */
   g_keypress = FALSE;
   TR2 = 1;                 /* Start Timer2.          */        	         
}	

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

NAME:       Gear_Clearence_Get

FUNCTION:   This procedure will reset the cutter and get the gear clearence.  

INPUTS:     NONE

OUTPUTS:    cutter reset flag  success/failure

***************************************************************************/
bit Gear_clearence_Get()
{
   uchar d_counter;
   uchar d_filter;
   bit resetok;	
   
   resetok = TRUE;
   AD_POSIN = 1;   /* cutter position detect enable. */
   d_counter = 0;
   for(d_filter=0;d_filter<CN_FILTER;d_filter++)
   {
      if(AD_POSIN==CN_OVERZERO)
      {  
         d_counter++;
      }
   }
   if(d_counter>(CN_FILTER/2)) /* the cutter is over the zero, go open. */
   { 
      g_char_ptr = (uchar xdata *)AD_CUMOTOR;
     *g_char_ptr = CN_CUTOPENHG; /* the cutter motor open direction. */
      TH0 = CNCUTTACCE[0][0];
      TL0 = CNCUTTACCE[0][1];
      g_generalbit = TRUE;
      d_filter = 0;
      TR0 = 1; /* start the Timer0. */
      for(d_counter=0;d_counter<CN_RESETLIMIT;d_counter++)
      {
       	 g_char_ptr = (uchar xdata *)AD_CUMOTOR;
      	 Reset_Watchdog();
        *g_char_ptr = CN_CUTOPENLW;
         if(d_counter<CNCUTACCSTEP)
         {
            g_thvalue = CNCUTTACCE[0][d_counter*2];
            g_tlvalue = CNCUTTACCE[0][d_counter*2+1];
         }
         else
         {   
            g_thvalue = CNCUTTACCE[0][(CNCUTACCSTEP-1)*2];
            g_tlvalue = CNCUTTACCE[0][(CNCUTACCSTEP-1)*2+1];
         }   
         Delay_us(CN_10us);
        *g_char_ptr = CN_CUTOPENHG;
         if(AD_POSIN==CN_UNDERZERO)
         {
            for(d_filter=0;d_filter<CN_FILTER;d_filter++)
            {
               if(AD_POSIN==CN_OVERZERO)
               {  
               	  d_filter = 0;
                  break;  
               }
            }
         }
         for(;g_generalbit==TRUE;)
         {} /* wait for Timer0 interrupt. */
         if(d_filter>=CN_FILTER) /* by filter, the cutter is under zero truely. */
         {  break;  }  /* break the open cutter move. */
         g_generalbit=TRUE;
      }
      if(d_counter>=CN_RESETLIMIT)
      { resetok = FALSE; }
      if(TRUE==resetok)
      {
         g_char_ptr = (uchar xdata *)AD_BACKCLEAR;
         if(d_counter>=CN_TESTFORGEAR+CN_MINCLEARENCE) 
         {
           *g_char_ptr = d_counter-CN_TESTFORGEAR; /* record the back gear clearence. */
         }
      }      
      TR0 = 0; /* stop the Timer0. */
      g_char_ptr = (uchar xdata *)AD_CUMOTOR;
      if(d_counter>=CNCUTACCSTEP)
      {
         d_counter = CNCUTACCSTEP-1;
      }
     *g_char_ptr = CN_CUTOPENHG; /* the cutter motor open direction. */
      TH0 = CNCUTTACCE[0][d_counter*2];
      TL0 = CNCUTTACCE[0][d_counter*2+1];
      g_generalbit = TRUE;
      TR0 = 1; /* start the Timer0. */  	
      for(;;d_counter--)
      {
      	  g_char_ptr = (uchar xdata *)AD_CUMOTOR;
      	  Reset_Watchdog();
         *g_char_ptr = CN_CUTOPENLW;	
          g_thvalue = CNCUTTACCE[0][d_counter*2];
          g_tlvalue = CNCUTTACCE[0][d_counter*2+1];
          Delay_us(CN_10us);
         *g_char_ptr = CN_CUTOPENHG;
          for(;g_generalbit==TRUE;)
          {} /* wait for Timer0 interrupt. */
          g_generalbit=TRUE;
          if(d_counter==0)
          {
             break;
          }   
      }
      TR0 = 0; /* stop the Timer0. */
   }
   g_char_ptr = (uchar xdata *)AD_CUMOTOR;
  *g_char_ptr = CN_CUTCLOSHG; /* the cutter motor close direction. */
   TH0 = CNCUTTACCE[0][0];
   TL0 = CNCUTTACCE[0][1];
   g_generalbit = TRUE;
   TR0 = 1; /* start the Timer0. */
   if(TRUE==resetok)
   { 
      for(d_counter=0;d_counter<CN_RESETLIMIT;d_counter++) /* move cutter close, and catch the original point. */
      {
         g_char_ptr = (uchar xdata *)AD_CUMOTOR;
         Reset_Watchdog();
        *g_char_ptr = CN_CUTCLOSLW;	
         g_thvalue = CNCUTTACCE[0][0];
         g_tlvalue = CNCUTTACCE[0][1];
         Delay_us(CN_10us);
        *g_char_ptr = CN_CUTCLOSHG;
         if(AD_POSIN==CN_OVERZERO)
         {
            for(d_filter=0;d_filter<CN_FILTER;d_filter++)
            {
               if(AD_POSIN==CN_UNDERZERO)
               {  
                  d_filter = 0;
                  break;  
               }
            }
            if(d_filter>=CN_FILTER) /* by filter, the cutter is over zero truely. */
            {  break;  }  /* break the open cutter move. */
         }
         for(;g_generalbit==TRUE;)
         {} /* wait for Timer0 interrupt. */
         g_generalbit=TRUE;
      }
      if(d_counter>=CN_RESETLIMIT)
      { resetok = FALSE; }
      if(TRUE==resetok)
      {
         g_char_ptr = (uchar xdata *)AD_FRONTCLEAR;
         if(d_counter>=CNCUTACCSTEP+CN_MINCLEARENCE)
         {
           *g_char_ptr = d_counter-CNCUTACCSTEP; /* record the front gear clearence. */	
         }
      }  
   }   
   TR0 = 0; /* stop the Timer0. */
   
   return resetok;
}  

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

NAME:       Cutter_Reset

FUNCTION:   This procedure will move cutter to the original point.  

INPUTS:     NONE

OUTPUTS:    cutter reset flag  success/failure

***************************************************************************/
bit Cutter_Reset()
{
   uchar d_counter;
   uchar d_filter;
   uchar d_speed;
   bit resetok;	
   
   g_char_ptr = (uchar xdata *)(AD_CURPROG+AD_RUNSPEED);
   d_speed = *g_char_ptr; /* get the current speed stage. */	
   resetok = TRUE;
   AD_POSIN = 1;   /* cutter position detect enable. */
   d_counter = 0;
   for(d_filter=0;d_filter<CN_FILTER;d_filter++)
   {
      if(AD_POSIN==CN_OVERZERO)
      {  
         d_counter++;
      }
   }
   if(d_counter>(CN_FILTER/2)) /* the cutter is over the zero, go open. */
   { 
      g_char_ptr = (uchar xdata *)AD_CUMOTOR;
     *g_char_ptr = CN_CUTOPENHG; /* the cutter motor open direction. */
      TH0 = CNCUTTACCE[d_speed][0];
      TL0 = CNCUTTACCE[d_speed][1];
      g_generalbit = TRUE;
      d_filter = 0;
      TR0 = 1; /* start the Timer0. */
      for(d_counter=0;d_counter<CN_RESETLIMIT;d_counter++)
      {
       	 g_char_ptr = (uchar xdata *)AD_CUMOTOR;
      	 Reset_Watchdog();
        *g_char_ptr = CN_CUTOPENLW;
         if(d_counter<CNCUTACCSTEP)
         {
            g_thvalue = CNCUTTACCE[d_speed][d_counter*2];
            g_tlvalue = CNCUTTACCE[d_speed][d_counter*2+1];
         }
         else
         {   
            g_thvalue = CNCUTTACCE[d_speed][(CNCUTACCSTEP-1)*2];
            g_tlvalue = CNCUTTACCE[d_speed][(CNCUTACCSTEP-1)*2+1];
         }   
         Delay_us(CN_10us);
        *g_char_ptr = CN_CUTOPENHG;
         if(AD_POSIN==CN_UNDERZERO)
         {
            for(d_filter=0;d_filter<CN_FILTER;d_filter++)
            {
               if(AD_POSIN==CN_OVERZERO)
               {  
               	  d_filter = 0;
                  break;  
               }
            }
         }
         for(;g_generalbit==TRUE;)
         {} /* wait for Timer0 interrupt. */
         if(d_filter>=CN_FILTER) /* by filter, the cutter is under zero truely. */
         {  break;  }  /* break the open cutter move. */
         g_generalbit=TRUE;
      }
      if(d_counter>=CN_RESETLIMIT)
      { resetok = FALSE; }
      if(TRUE==resetok)
      {
         g_currentradius = d_counter; /* save this value for wire radius auto detect.*/
      }   
      TR0 = 0; /* stop the Timer0. */
      g_char_ptr = (uchar xdata *)AD_CUMOTOR;
      if(d_counter>=CNCUTACCSTEP)
      {
         d_counter = CNCUTACCSTEP-1;
      }
     *g_char_ptr = CN_CUTOPENHG; /* the cutter motor open direction. */
      TH0 = CNCUTTACCE[d_speed][d_counter*2];
      TL0 = CNCUTTACCE[d_speed][d_counter*2+1];
      g_generalbit = TRUE;
      TR0 = 1; /* start the Timer0. */  	
      for(;;d_counter--)
      {
      	  g_char_ptr = (uchar xdata *)AD_CUMOTOR;
      	  Reset_Watchdog();

⌨️ 快捷键说明

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