为什么我的电机在转动的时候,只是A相和C相的指示灯亮呢,而BD两相的指示灯不亮,以下是我的程序
请大神指教
#include "STC89C5AS02.h"
#define uint unsigned int
#define uchar unsigned char
sbit IN1=P0^0;
sbit IN2=P0^1;
sbit IN3=P0^2;
sbit IN4=P0^3;
sbit IN5=P0^4;
sbit IN6=P0^5;
sbit IN7=P0^6;
sbit IN8=P0^7;
//电机正反转控制字
uchar M1Z[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09}; //电机1正转:A-AB-B-BC-C-CD-D-DA
uchar M1F[8]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09}; //电机1反转:D-DC-C-CB-B-BA-A-AD
uchar M2Z[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90}; //电机2正转:A-AB-B-BC-C-CD-D-DA
uchar M2F[8]={0x10,0x30,0x20,0x60,0x40,0xc0,0x80,0x90}; //电机2反转:D-DC-C-CB-B-BA-A-AD
//ms延时函数
void Delay_xms(uint x)
{
uint i,j;
for(i=0;i<x;i++)
for(j=0;j<112;j++);
}
void main()
{
uint i;
while(1)
{
for(i=0;i<=7;i++)
{
P0=M1Z[i]; //电机1正传
Delay_xms(100);
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>