|
void MOTOR_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //GPIOB使能
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15|GPIO_Pin_14|GPIO_Pin_13|GPIO_Pin_12|GPIO_Pin_11|GPIO_Pin_10|GPIO_Pin_9|GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽輸出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度為50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //根據設定參數初始化GPIOB.5
}
//細分
// x==1 全步
// x==2 半步
// x==4 1/4步
// x==8 1/8步
// x==16 1/16步
void Step_Micr1(u16 x)
{
switch(x)
{
case 1:Full_step1;break;
case 2:Half_step1;break;
case 4:Quarter_step1;break;
case 8:Eighth_step1;break;
case 16:Sixteenth_step1;break;
default:break;
}
}
//參數
//dir:FALSE正轉TRUE反轉
//period 周期
//step 脈沖
void Step_Control1(u8 dir1,u16 period1,u32 steps1)
{
u32 i;
for(i=0; i <= steps1;i++)
{
DIR1 = dir1;
STEP1 = 1;
delay_us(1);
STEP1 = 0;
delay_us(period1);
}
}
//此函數可抱死
// 0 抱死
// 1 正常
void Step_Enable1()
{
ENABLE1 = 0;
}
|
-
-
代碼.7z
2023-6-13 03:27 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
190.76 KB, 下載次數: 45, 下載積分: 黑幣 -5
評分
-
查看全部評分
|