📄 test_stepmotor.c
字号:
//头文件定义
#include "def.h"
#include "2410addr.h"
#include "config.h"
#include "board.h"
//步进电机地址
#define StepMotor_Address *(volatile U16 *)( 0x28700000 ) //nGCS7
/********************************************************************
Function name: Motor_Delay
Parameter : j:延迟参数
Description : 软件延迟
Return : void
Argument : void
Autor & date :
*********************************************************************/
void Motor_Delay( U16 j )
{
U16 k, l ;
for(l=0;l<=j;l++)
for(k=0;k<=500;k++);
}
/********************************************************************
Function name: Setep_Motor
Parameter : delay:延迟参数 m:正转还是反转
Description : 步进电机控制函数
Return : void
Argument : void
Autor & date :
*********************************************************************/
void Step_Motor( U16 delay, U8 m )
{
if( m > 0 )
{
StepMotor_Address = 0x01 ; //StepMotor output
Motor_Delay( delay ); //延时
StepMotor_Address = 0x08 ; //StepMotor output
Motor_Delay( delay ); //延时
StepMotor_Address = 0x02 ; //StepMotor output
Motor_Delay( delay ); //延时
StepMotor_Address = 0x04 ; //StepMotor output
Motor_Delay( delay ); //延时
}
else
{
StepMotor_Address = 0x04 ; //StepMotor output
Motor_Delay( delay ); //延时
StepMotor_Address = 0x02 ; //StepMotor output
Motor_Delay( delay ); //延时
StepMotor_Address = 0x08 ; //StepMotor output
Motor_Delay( delay ); //延时
StepMotor_Address = 0x01 ; //StepMotor output
Motor_Delay( delay ); //延时
}
}
/********************************************************************
Function name: Setep_Motor
Parameter : delay:延迟参数 m:正转还是反转
Description : 步进电机控制函数
Return : void
Argument : void
Autor & date :
*********************************************************************/
void Test_StepMotor(void)
{
U16 m ;
U8 p ;
U16 MOTOR_DELAY_TIME = 100 ;
printf( "FFT-S32410X Step Motor TEST, press ESC key to exit !\n" ) ;
printf( "Press '+' or '-' to increase or decrease the speed\n" ) ;
while( (m=getkey())!=ESC_KEY )
{
if( m != 0 )
{
if( m == 't' )
{
p = !p ;
printf( "Turn on is reverse!\n" ) ;
}
else
{
if( m == '+' ) MOTOR_DELAY_TIME+=5 ;
if( m == '-' ) MOTOR_DELAY_TIME-=5 ;
if( MOTOR_DELAY_TIME<50 ) MOTOR_DELAY_TIME = 50 ;
if( MOTOR_DELAY_TIME>1000 ) MOTOR_DELAY_TIME = 1000 ;
printf( "DelayTime = %d\n", MOTOR_DELAY_TIME ) ;
}
}
Step_Motor( MOTOR_DELAY_TIME, 100 ) ;
}
StepMotor_Address = 0x00 ; //StepMotor output
}
/********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -