2020-03-03 02:45:55 来源:范文大全收藏下载本文
#include
#define uchar unsigned char
#define uint unsigned int
uchar code stepmotor_table[]={0x02,0x04,0x08,0x01};//B-C-D-A-B顺时针 单四拍
//uchar code stepmotor_table[]={0x06,0x0c,0x09,0x03};//BC-CCD-DA-AB-BC顺时针 双四拍
//uchar code stepmotor_table[]={0x02,0x06,0x04,0x0c,0x08,0x09,0x01,0x03};//B-BC-C-CD-D-DA-A-AB-B顺时针
//uchar code stepmotor_table[]={0x01,0x08,0x04,0x02 } ;//A-D-C-B-A 逆时针 单四拍
//uchar code stepmotor_table[]={0x09,0x0c,0x06,0x03} ;//AD-DC-CB-BA-AD 逆时针 双四拍
// uchar code stepmotor_table[]={0x01,0x09,0x08,0x0c,0x04,0x06,0x02,0x03}; //A-AD-D-DC-C-CB-B-BA-A逆时针 双四拍
//x=1时延时 1ms 转速为60/(x*48*0.001)rpm(转每分钟)
void DelayMS(uint x)
{
uchar i;
TMOD=0x01;
{
TH1=(65536-1000)/256;//TH1=oxfc ;
TL1=(65536-1000)%256;//TL1=ox18 ;
TR1=1;
while(!TF1);
TF1=0;
}
}
void main()
{
uchar i;
uintj ;
THOD=0x10;
while(1)
{
for(j=0;j
{
for(i=0;i
{
P1=stepmotor_table[i];//取数据
DelayMS(25) ;//调节x值,调节转速大小
}
}
}
}
人人范文网 m.inrrp.com.cn 手机版