|
< >电路如图所示:</P>
< ><img src="attachments/dvbbs/2004-11/2004112517489628.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=\'Click here to open new window\nCTRL+Mouse wheel to zoom in/out\';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=\'hand\'; this.alt=\'Click here to open new window\nCTRL+Mouse wheel to zoom in/out\';}" onclick="if(!this.resized) {return true;} else {window.open(\'attachments/dvbbs/2004-11/2004112517489628.gif\');}" onmousewheel="return imgzoom(this);" alt="" /></P>
< >程序
stepper.c
stepper.hex </P>
<P>/*
* STEPPER.C
* sweeping stepper's rotor cw and cww 400 steps
* Copyright (c) 1999 by W.Sirichote
*/ </P>
<P>#include c:\mc51\8051io.h /* include i/o header file */
#include c:\mc51\8051reg.h </P>
<P>register unsigned char j,flag1,temp;
register unsigned int cw_n,ccw_n; </P>
<P>unsigned char step[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90}
#define n 400 </P>
<P>/* flag1 mask byte
0x01 run cw()
0x02 run ccw()
*/ </P>
<P>main() </P>
<P>{
flag1=0;
serinit(9600);
disable(); /* no need timer interrupt */
cw_n = n; /* initial step number for cw */
flag1 |=0x01; /* initial enable cw() */ </P>
<P>while(1){
{
tick_wait(); /* wait for 10ms elapsed */ </P>
<P>energize(); /* round-robin execution the following tasks every 10ms */
cw();
ccw();
}
} </P>
<P>} </P>
<P>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 */
}
} </P>
<P>} </P>
<P>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 */
}
} </P>
<P>} </P>
<P>tick_wait(){ /* cputick was replaced by simpler ASM code 10ms wait */ </P>
<P>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 */
} </P>
<P>energize(){ </P>
<P>P1 = step[(j&0x07)]; /* only step 0-7 needed */
}</P>
<P>
</P> |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|