Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 3846|回復: 0
打印 上一主題 下一主題

AT89C2051驅動步進馬達與原碼

[複製鏈接]
跳轉到指定樓層
1#
發表於 2006-8-6 15:43:48 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
AT89C2051驅動步進馬達與原碼



程序
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 */  
}

http://www.52dianzi.com/document/70.htm

20060312104952sv.gif (8.21 KB, 下載次數: 347)

20060312104952sv.gif
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-11-24 00:19 , Processed in 0.124421 second(s), 9 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表