步进电机控制C程序.docVIP

  • 8
  • 0
  • 约1.51千字
  • 约 2页
  • 2019-10-15 发布于江西
  • 举报
// 实验二十三 步进电机控制 #include reg51.h #define Astep 0x01 #define Bstep 0x02 #define Cstep 0x04 #define Dstep 0x08 unsigned char dly_c; void delay() { unsigned char tt,cc; cc = dly_c; tt = 0x0; do{ do { }while(--tt); }while(--cc); } void main() { unsigned char state=1,count=0; int n=0; dly_c = 170; // 双四拍工作方式 while(n++!=100) // 步计数器100步 { P1 = Astep+Bstep; delay(); P1 = Bstep+Cstep; delay(); P1 = Cstep+Dstep; delay(); P1 = Dstep+Astep; delay(); if(dly_c20state==1) dly_c-=6; if(dly_c==20count25) { state=2; count++; } if(state==2count==25) { state=3; count=0; } if(state==3dly_c170) dly_c+=6; if(state==3dly_c==170) state=1; } //delay(); // 单四拍工作方式 while(n--!=0) { P1 = Dstep+Astep; P1=P1|0x80; delay(); P1 = Cstep+Dstep; P1=P1|0x80; delay(); P1 = Bstep+Cstep; P1=P1|0x80; delay(); P1 = Astep+Bstep; P1=P1|0x80; delay(); if(dly_c20state==1) dly_c-=6; if(dly_c==20count25) { state=2; count++; } if(state==2count==25) { state=3; count=0; } if(state==3dly_c170) dly_c+=6; if(state==3dly_c==170) state=1; } }

文档评论(0)

1亿VIP精品文档

相关文档