main
This commit is contained in:
76
SYSTEM/thb6128/thb6128.c
Normal file
76
SYSTEM/thb6128/thb6128.c
Normal file
@ -0,0 +1,76 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
26
SYSTEM/thb6128/thb6128.h
Normal file
26
SYSTEM/thb6128/thb6128.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef __STEP_MOTOR_H
|
||||
#define __STEP_MOTOR_H
|
||||
#include "sys.h"
|
||||
#include "delay.h"
|
||||
|
||||
extern u8 STEP; //定义单步计数 全局变量
|
||||
|
||||
|
||||
#define STEP_MOTOR_PORT GPIOG //定义IO接口所在组
|
||||
#define STEP_MOTOR_A GPIO_Pin_2 //定义IO接口
|
||||
#define STEP_MOTOR_B GPIO_Pin_3 //定义IO接口
|
||||
#define STEP_MOTOR_C GPIO_Pin_4 //定义IO接口
|
||||
#define STEP_MOTOR_D GPIO_Pin_5 //定义IO接口
|
||||
#define STEP_MOTOR_CLK RCC_APB2Periph_GPIOG
|
||||
|
||||
|
||||
|
||||
void STEP_MOTOR_Init(void);//初始化
|
||||
void STEP_MOTOR_OFF (void);//断电状态
|
||||
void STEP_MOTOR_FORWARD(void);
|
||||
void STEP_MOTOR_BACKWARD(void);
|
||||
void STEP_MOTOR_OPEN (void);
|
||||
void STEP_MOTOR_EN (void);
|
||||
void switch_zheng (void);
|
||||
void switch_fan (void);
|
||||
#endif
|
||||
Reference in New Issue
Block a user