"); //-->
电路如图所示:
M1是一个从旧的磁盘驱动器上拆下来的。它有5个引脚:公共端,线圈1,2,3和4.公
共端与各组线圈之间的电阻阻值很精确,均为75欧。那么当电压为+5V时,每组线圈的驱
动电流为60mA。ULN2003是一个达灵顿管阵列,用来扩展2051的驱动能力。当电压为50V时
最大可提供500mA的电流。从电路图上可看到,2051的四个输出端P1.4到P1.7连接到了ULN
2003的输入端。四个4.7K的电阻帮助2051从电源处获得更多的驱动电流。串口可随意选择.
程序
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 */
}
下载:HEX文件、C源代码
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。