电子制作天地网站欢迎您的光临,欢迎提出宝贵意见或建议。本站信息产业部备案: 粤ICP备05114582号
89C2051驱动步进电机的电路和源码
Stepper motor driver

时间:2007-12-31 7:57:16 来源:未知 作者:未知 编辑: 【关闭


89C2051驱动步进电机的电路和源码,Stepper motor driver

关键字:步进电机驱动电路,89C2051步进电机驱动

程序

stepper.c
stepper.hex

/*
* STEPPER.C
* sweeping stepper's rotor cw and cww 400 steps
* Copyright (c) 1999 by W.Sirichote
*/

#include c:\mc51\8051io.h /* include i/o header file */
#include c:\mc51\8051reg.h

register unsigned char j,flag1,temp;
register unsigned int cw_n,ccw_n;

unsigned char step[8]={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 */
}

电路图


◆相关文章◆
◆ 编辑推荐 ◆
用户:
更多评论
您要为您所发的言论的后果负责,故请各位遵纪守法并注意语言文明。60个字以内
留言:
验证码:

免责声明:
●本站所有内容均来自网络,以学习为目的,如果侵犯了您的利益,请来信告知,立即删除,站长邮件为"diy+dzdiy.com",请将"+"变更为"@"
●电子制作存在风险,请注意人身安全,如果您在根据本站电路进行制作过程中发生伤害,本站不负任何责任。

版权所有:www.dzdiy.com ? 2001-2019 本站信息产业部备案: 粤ICP备05114582号