#define uint unsigned int
#define uchar unsigned char
uchar code tableCCW[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09}; 时针旋转相序表
sbit S3=P3^5; //反转 按键
sbit S4=P3^6; //正转 按键
sbit S5=P3^4; //停止 按键
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
//逆 void motorTurn_ccw() //转1圈,逆时针
{
uint i;
for(i=0;i<8;i++) //旋转45度, 8*5.625°=45°
{
P1=tableCCW[i];
delay(10); //调节转速
}
}
void main()
{
uchar r,a;
uchar N=128; //减速步进电机,减速比1/64,所以N=64时,步进电机外主轴转一圈
P1=0xff;
while(1)
{
for(a=0;a<4;a++)
{
for(r=0;r motorTurn_ccw(); } } while(1); } //电机逆时针转 } 因篇幅问题不能全部显示,请点此查看更多更全内容