怎么无法实现电机正反转?下面是代码
#include <reg52.h>
#include <math.h>
#define en_spin P0 &=0XDF
#define dis_spin P0 |=0X20 //PD5
#define spin_c P0 &=0XEF
#define spin_cw P0 |=0X10 //PD4
#define spin_1 P2 |=0X08
#define spin_0 P2 &=0XF7 //PD3
#define en_pull P2 &=0XFB
#define dis_pull P2 |=0X04 //PD2
#define pull_c P2 &=0XFD
#define pull_cw P2 |=0x02 //PD1
#define pull_1 P2 |=0X01
#define pull_0 P2 &=0XFE //PD0
#define NOPP P2 &=0xFF
void delay(unsigned int x)
{
while(--x);
}
void main()
{
unsigned int it,i;
it=50;
i=16*200*300/(5*3) ;
P2=0X10;
P0=0X10 ;
spin_c; pull_cw;
while(i--)
{
pull_1; spin_1;
delay(it);spin_0;NOPP;
delay(it);pull_0;NOPP;
delay(it);
spin_1;NOPP;
delay(it);spin_0;
pull_1;delay(it);NOPP;NOPP;
delay(it);pull_0;
spin_1;
delay(it);spin_0;NOPP;
delay(it);NOPP;
pull_1;delay(it);
spin_1;NOPP;
delay(it);spin_0;pull_0;
delay(it);NOPP;NOPP;
delay(it-5);
}
}
|