来一个步进电机的测试程序
时间:10-02
整理:3721RD
点击:
/*******************************************
1,pul为脉冲输入
2,1246 on
3,步进电机可接4个
*******************************************/
#include <REGX51.H>
sbit motor1=P2^0;
sbit motor2=P2^1;
sbit motor3=P2^2;
sbit motor4=P2^3;
unsigned int step;
void timer0_init()
{
TMOD=0x01;
TH0=(65536-100)/256; //100
TL0=(65536-100)%256;
ET0=1;
EA=1;
TR0=1;
}
void delay(unsigned int a )
{
unsigned int x,y;
for(x=a;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
timer0_init();
while(1)
{
step=1600; //800个下降沿脉冲转一圈
}
}
void timer0() interrupt 1
{
TH0=(65536-100)/256;
TL0=(65536-100)%256;
if(step>0)
{
step--;
motor1=~motor1;
motor2=~motor2;
motor3=~motor3;
motor4=~motor4;
}
}
1,pul为脉冲输入
2,1246 on
3,步进电机可接4个
*******************************************/
#include <REGX51.H>
sbit motor1=P2^0;
sbit motor2=P2^1;
sbit motor3=P2^2;
sbit motor4=P2^3;
unsigned int step;
void timer0_init()
{
TMOD=0x01;
TH0=(65536-100)/256; //100
TL0=(65536-100)%256;
ET0=1;
EA=1;
TR0=1;
}
void delay(unsigned int a )
{
unsigned int x,y;
for(x=a;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
timer0_init();
while(1)
{
step=1600; //800个下降沿脉冲转一圈
}
}
void timer0() interrupt 1
{
TH0=(65536-100)/256;
TL0=(65536-100)%256;
if(step>0)
{
step--;
motor1=~motor1;
motor2=~motor2;
motor3=~motor3;
motor4=~motor4;
}
}