新手上路
- 积分
- 38
- 金钱
- 38
- 注册时间
- 2017-7-20
- 在线时间
- 11 小时
|
void Motor_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//GPIOB
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
// GPIO_ResetBits(GPIOA,GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_6|GPIO_Pin_9);
}
void motor_CW(void)
{
int motor_step=0;
switch(motor_step)
{
case 0:
PBout(0)=1;
PBout(1)=0;
PBout(2)=0;
PBout(3)=0;
break;
case 1:
PBout(0)=1;
PBout(1)=1;
PBout(2)=0;
PBout(3)=0;
break;
case 2:
PBout(0)=0;
PBout(1)=1;
PBout(2)=0;
PBout(3)=0;
break;
case 3:
PBout(0)=0;
PBout(1)=1;
PBout(2)=1;
PBout(3)=0;
break;
case 4:
PBout(0)=0;
PBout(1)=0;
PBout(2)=1;
PBout(3)=0;
break;
case 5:
PBout(0)=0;
PBout(1)=0;
PBout(2)=1;
PBout(3)=1;
break;
case 6:
PBout(0)=0;
PBout(1)=0;
PBout(2)=0;
PBout(3)=1;
break;
case 7:
PBout(0)=1;
PBout(1)=0;
PBout(2)=0;
PBout(3)=1;
break;
default:
PBout(0)=0;
PBout(1)=0;
PBout(2)=0;
PBout(3)=0;
break;
}
motor_step++;
if(motor_step>7)
motor_step=0;
}
void motor_CCW(void) //Äæê±Õë
{
int motor_step=0;
switch(motor_step){
case 0:
PBout(0)=1;
PBout(1)=0;
PBout(2)=0;
PBout(3)=1;
break;
case 1:
PBout(0)=0;
PBout(1)=0;
PBout(2)=0;
PBout(3)=1;
break;
case 2:
PBout(0)=0;
PBout(1)=0;
PBout(2)=1;
PBout(3)=1;
break;
case 3:
PBout(0)=0;
PBout(1)=0;
PBout(2)=1;
PBout(3)=0;
break;
case 4:
PBout(0)=0;
PBout(1)=1;
PBout(2)=1;
PBout(3)=0;
break;
case 5:
PBout(0)=0;
PBout(1)=1;
PBout(2)=0;
PBout(3)=0;
break;
case 6:
PBout(0)=1;
PBout(1)=1;
PBout(2)=0;
PBout(3)=0;
break;
case 7:
PBout(0)=1;
PBout(1)=0;
PBout(2)=0;
PBout(3)=0;
break;
default:
PBout(0)=0;
PBout(1)=0;
PBout(2)=0;
PBout(3)=0;
break;
}
motor_step++;
if(motor_step>7)
motor_step=0;
}
void motor_loop(uint8_t dir)
{
if(dir)
motor_CW();
else
motor_CCW();
}
#include "delay.h"
#include "motor.h"
//#include "adc.h"
int main()
{
Motor_Init();
while(1)
{
void motor_CW();
}
}
这是我写的步进电机驱动的代码,用的是uln2003驱动板,IN1,IN2,IN3,IN4连接的分别是PB0,PB1,PB2,PB3.驱动板也外加有直流电源,但是步进电机毫无反应啊。求大神看看,指点指点啊!!!!
|
|