stepper.c

来自「Embedded C 这本书的范例光碟程式」· C语言 代码 · 共 87 行

C
87
字号
/*------------------------------------------------------------------*-

   Stepper.C (v1.00)

  ------------------------------------------------------------------
   
   Simple stepper control functions for robot.

   COPYRIGHT
   ---------

   This code is associated with the book:

   EMBEDDED C by Michael J. Pont 
   [Pearson Education, 2002: ISBN: 0-201-79523-X].

   This code is copyright (c) 2001 by Michael J. Pont.
 
   See book for copyright details and other information.

-*------------------------------------------------------------------*/

#include "Main.h"
#include "Port.h"

#include "Stepper.h"

// ------ Public variable definitions ------------------------------

bit Motor_L;
bit Motor_R;

// ------ Private variable definitions -----------------------------

static bit Stepper_state_G;

/*------------------------------------------------------------------*-

  STEPPER_Init()

-*------------------------------------------------------------------*/
void STEPPER_Init(void)
   {
   Stepper_state_G = 0;

   Motor_L = 0;
   Motor_R = 0;
   }


/*------------------------------------------------------------------*-

  STEPPER_Update()

  Controls two stepper motors.  

-*------------------------------------------------------------------*/
void STEPPER_Update(void)
   {
   // Step the motors, as required
   if (Stepper_state_G == 1)
      {
      Stepper_state_G = 0;

      if (Motor_L == 1)
         {
         Motor_L_pin = 1;
         }

      if (Motor_R == 1)
         {
         Motor_R_pin = 1;
         }
      }
   else
      {
      Stepper_state_G = 1;

      Motor_L_pin = 0;
      Motor_R_pin = 0;
      }
   }

/*------------------------------------------------------------------*-
  ---- END OF FILE -------------------------------------------------
-*------------------------------------------------------------------*/

⌨️ 快捷键说明

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