77 lines
2.2 KiB
C
77 lines
2.2 KiB
C
#include "thb6128.h"
|
||
#include "usart.h"
|
||
#include "stdlib.h"
|
||
#include "stdio.h"
|
||
#include "string.h"
|
||
#include "dac.h"
|
||
#include "led.h"
|
||
#include "motorstat.h"
|
||
/* EN-> PA11 M1 PB13
|
||
CW/CCW-> PA12 M2 PB14
|
||
CLK/cp-> PA8 M3 PB15
|
||
VREF-> PA4
|
||
FDT-> PA5
|
||
*/
|
||
|
||
extern int s1,s2;
|
||
void STEP_MOTOR_Init(void){ //接口初始化
|
||
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE); //使能PB,PE端口时钟
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_8|GPIO_Pin_4; // 端口配置
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
|
||
GPIO_Init(GPIOA, &GPIO_InitStructure); //根据设定参数初始化
|
||
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; //LED0-->PC13 端口配置
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
|
||
GPIO_Init(GPIOB, &GPIO_InitStructure); //根据设定参数初始化
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // 端口配置
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
|
||
GPIO_Init(GPIOC, &GPIO_InitStructure); //根据设定参数初始化
|
||
|
||
}
|
||
|
||
|
||
void STEP_MOTOR_FORWARD(void)
|
||
{
|
||
GPIO_ResetBits(GPIOA,GPIO_Pin_12); //将PA12拉低,正转
|
||
MotorStat.moveflag=1;
|
||
MotorStat.direction=0;
|
||
MotorStat.MoveMode=0;
|
||
s1=1;
|
||
}
|
||
void STEP_MOTOR_BACKWARD(void)
|
||
{
|
||
GPIO_SetBits(GPIOA,GPIO_Pin_12); //将PA12拉高,反转
|
||
MotorStat.moveflag=1;
|
||
MotorStat.direction=1;
|
||
MotorStat.MoveMode=0;
|
||
s2=1;
|
||
}
|
||
|
||
void STEP_MOTOR_EN (void) //使能
|
||
{
|
||
GPIO_SetBits(GPIOA,GPIO_Pin_11);
|
||
Dac1_Set_Vol(1000);//保持电流
|
||
}
|
||
|
||
void STEP_MOTOR_OPEN (void)//开启电机
|
||
{
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
|
||
}
|
||
void STEP_MOTOR_OFF (void) //脱机
|
||
{
|
||
MotorStat.moveflag=0;
|
||
GPIO_ResetBits(GPIOA,GPIO_Pin_11);
|
||
printf("ALREDAY_OFFLINE\r\n");
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, DISABLE);
|
||
}
|
||
|