📄 motor.c
字号:
#include "Reg51.h"
#include "Main.h"
#include "Motor.h"
sbit SM_1A = P1^4;
sbit SM_2A = P1^5;
sbit SM_XB = P1^6;
sbit PWR_ON = P1^7;
char Motor_Status = 3;
void Mortor_Init(void){
Motor_Status = 3;
Power_On();
Delay(20);
Motor_Rotate(5,FORWARD);
Power_Off();
}
void Power_On(void){
PWR_ON = 1;
Mortor_Power_On();
}
void Power_Off(void){
PWR_ON = 0;
Mortor_Power_Off();
}
void Mortor_Power_On(void){
SM_XB=0; // M1B=0 , M2B=0, Current = MAX
}
void Mortor_Power_Off(void){
SM_XB=1; // M1B=1 , M2B=1, Current = 0
PWR_ON = 0;
}
void Motor_Rotate(uchar Step,uchar Direction){
uchar i;
for (i=0;i<Step;i++)
{
if (Direction==FORWARD) //forward
{
if(Motor_Status>=3)
{Motor_Status=0;}
else
{Motor_Status++;}
}
else //backward
{
if(Motor_Status<=0)
{Motor_Status=3;}
else
{Motor_Status--;}
}
switch (Motor_Status)
{
case 0:
SM_1A = 0;
SM_2A = 0;
// M1A=0 , M2A=0 , Step=1
break;
case 1:
SM_1A = 1;
SM_2A = 0;
// M1A=0 , M2A=1 , Step=2
break;
case 2:
SM_1A = 1;
SM_2A = 1;
// M1A=1 , M2A=1 , Step=3
break;
case 3:
SM_1A = 0;
SM_2A = 1;
// M1A=1 , M2A=0 , Step=4
break;
default:
SM_1A = 0;
SM_2A = 0;
// M1A=0 , M2A=0 , Step=1
break;
}
Delay(2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -