求四相八拍步进电机 51单片机完整控制程序
发布网友
发布时间:2022-05-11 23:25
我来回答
共2个回答
热心网友
时间:2023-10-25 10:53
#include<reg51.h>
#define uchar unsigned char
uchar stepd[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};
uchar num=0,fx=0;
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
void t0isr() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
P2=stepd[num];
if(fx==0){num++;num%=8;}
if(fx==1)
{
if(num==0)num=7;
else num--;
}
}
main()
{
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
TR0=1;
ET0=1;
EA=1;
while(1)
{
if(key1==0)
{
while(key1==0);
TR0=~TR0;
}
if(key2==0)
{
while(key2==0);
fx=0;
}
if(key3==0)
{
while(key3==0);
fx=1;
}
}
}
热心网友
时间:2023-10-25 10:54
你驱动器用什么,这个和程序有很大关系.