AT89C2051驱动步进电机的电路和源码.doc
-
资源ID:17412209
资源大小:132KB
全文页数:4页
- 资源格式: DOC
下载积分:15金币
快捷下载
会员登录下载
微信登录下载
三方登录下载:
微信扫一扫登录
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
|
AT89C2051驱动步进电机的电路和源码.doc
【精品文档】如有侵权,请联系网站删除,仅供学习与交流AT89C2051驱动步进电机的电路和源码.精品文档.AT89C2051驱动步进电机的电路和源码电路如图所示:程序 stepper.c stepper.hex /* * STEPPER.C * sweeping stepper's rotor cw and cww 400 steps * Copyright (c) 1999 by W.Sirichote */ #include c:mc518051io.h /* include i/o header file */ #include c:mc518051reg.h register unsigned char j,flag1,temp; register unsigned int cw_n,ccw_n; unsigned char step8=0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90 #define n 400 /* flag1 mask byte 0x01 run cw() 0x02 run ccw() */ main() flag1=0; serinit(9600); dISAble(); /* no need timer interrupt */ cw_n = n; /* initial step number for cw */ flag1 |=0x01; /* initial enable cw() */ while(1) tick_wait(); /* wait for 10ms elapsed */ energize(); /* round-robin execution the following tasks every 10ms */ cw(); ccw(); cw() if(flag1&0x01)!=0) cw_n-; /* decrement cw step number */ if (cw_n !=0) j+; /* if not zero increment index j */ else flag1&=0x01; /* dISAble cw() execution */ ccw_n = n; /* reload step number to ccw counter */ flag1 |=0x02; /* enable cww() execution */ ccw() if(flag1&0x02)!=0) ccw_n-; /* decremnent ccw step number */ if (ccw_n !=0) j-; /* if not zero decrement index j */ else flag1&=0x02; /* dISAble ccw() execution */ cw_n = n; /* reload step number to cw counter */ flag1 |=0x01; /* enable cw() execution */ tick_wait() /* cputick was replaced by simpler ASM code 10ms wait */ asm" JNB TCON.5,*" /* wait for TF0 set */ asm" CLR TCON.5" /* clear TF0 for further set */ asm" ORL TH0,#$DC" /* reload TH0 with $DC, TL0 = 0 */ energize() P1 = step(j&0x07); /* only step 0-7 needed */