AT89C2051驱动步进电机的电路和源码

11-21| http://www.dianzi6.com | 电子电路图 - 单片机电路图|人气:949

AT89C2051驱动步进电机的电路和源码

相关元件PDF下载:


89C2051   ULN2003   MAX232   


程序

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\80dianzi6eg.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 */
}

如果觉得 AT89C2051驱动步进电机的电路和源码这篇文章不错,可以推荐给朋友分享哦。
本文Tags:电路图讲解,电路图练习,电子电路图 - 单片机电路图,
相关单片机电路图资料


温馨提示; 本站的资料全部免费下载,为方便下次找到本站记得将本站加入收藏夹哦,牢记网址http://www.dianzi6.com

此页提供AT89C2051驱动步进电机的电路和源码电路图讲解,电路图练习, 电子电路图 - 单片机电路图参考。本站还有更多的单片机电路图相关资料分享。
Copyright© www.dianzi6.com Inc. All rights reserved 。 1 2 3 4 5 6 7 8