📄 c51bbs论坛c51编程二相步进电机32细分驱动程序.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0051)http://www.c51bbs.com/c51bbs/topic/c51bbs812029.htm -->
<HTML><HEAD><TITLE>C51BBS论坛>>C51编程:二相步进电机32细分驱动程序</TITLE>
<META http-equiv=Content-Type content="text/html; charset=Gb2312">
<SCRIPT language=javascript>function MM_findObj(n, d) { var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;}function MM_changeProp(objName,x,theProp,theValue) {var obj = MM_findObj(objName);if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");}</SCRIPT>
<LINK href="C51BBS论坛C51编程二相步进电机32细分驱动程序.files/nobgcolor.css" type=text/css
rel=stylesheet>
<META content="MSHTML 6.00.2900.2912" name=GENERATOR></HEAD>
<BODY bgColor=#efefef leftMargin=35
background=C51BBS论坛C51编程二相步进电机32细分驱动程序.files/c51bbs.jpg topMargin=80><TD
class=pw>用【<SPAN style="CURSOR: hand"
onclick="MM_changeProp('spancontent','','style.fontSize','9pt','SPAN')"> 小
</SPAN>|<SPAN style="CURSOR: hand"
onclick="MM_changeProp('spancontent','','style.fontSize','10.5pt','SPAN')"> 中
</SPAN>|<SPAN style="CURSOR: hand"
onclick="MM_changeProp('spancontent','','style.fontSize','12pt','SPAN')"> 大
</SPAN>】字体浏览</TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD><SPAN id=spancontent>
<H3>C51编程:二相步进电机32细分驱动程序 [lenvy] <FONT
color=#d5d5d5>2008-5-16 9:45:55</FONT></H3>
<P>小弟刚接触步进电机,最近用AT89C51写了一个32细分的驱动程序,驱动芯片用<BR>NJU39610+NJM3771,望各位大侠给我看看,提下意见,有哪要改的?<BR>/*******************************************************************<BR>程序实现功能:对二相步进电机进行32细分;采用定时器中断,每0.5ms电机<BR> 走一步;<BR> 暂时单片机外部控制部分只有控制正转、反转键<BR>*******************************************************************/<BR>#include <reg51.h><BR>#include <absacc.h> <BR>#include <stdio.h> <BR>#include <intrins.h> <BR>#include <math.h> <BR>#include <string.h> <BR><BR>//NJU39610端口定义<BR> <BR>#define DA_PORT P1 <BR>sbit DA_WR=P3^4; //NJU39610数据写入端;<BR>sbit DA_A0=P3^7; //NJU39610通道选择端;<BR><BR>//对外接口引脚定义 <BR>sbit ST_CLK =P3^2; //外部脉冲信号输入;<BR>sbit ST_STOP=P3^3; //控制步进电机开关;<BR>sbit ST_DIR =P2^7; //控制步进电机转动方向;<BR><BR>//全局变量定义 <BR>unsigned char data xf_step; //细分步<BR>数(二相电机单二拍走一循环为64步) <BR>unsigned char xdata xf32_sin[64]={0,6,12,18,24,31,37,43, //32细分<BR>后走一个循环的细分数据;<BR> 48,54,60,65,71,76,81,85,<BR> 90,94,98,102,106,109,112,115,<BR> 118,120,122,124,125,126,127,127,<BR> 128,127,127,126,125,124,122,120,<BR> 118,115,112,109,106,102,98,94,<BR> 90,85,81,76,71,65,60,54,<BR> 48,43,37,31,24,18,12,6<BR> }; <BR>unsigned char xdata xf32_cos[64]={128,127,127,126,125,124,122,120,<BR> 118,115,112,109,106,102,98,94,<BR> 90,85,81,76,71,65,60,54,<BR> 48,43,37,31,24,18,12,6,<BR> 0,6,12,18,24,31,37,43,<BR> 48,54,60,65,71,76,81,85,<BR> 90,94,98,102,106,109,112,115,<BR> 118,120,122,124,125,126,127,127,<BR> }; <BR><BR><BR>StopMt() <BR>{ <BR> DA_A0=0; //选DA通道0;<BR> DA_PORT=0;<BR> DA_WR=0; //DA数据写入;<BR> _nop_(); <BR> DA_WR=1;<BR> DA_A0=1; //选DA通道1;<BR> DA_PORT=0;<BR> DA_WR=0; //DA数据写入;<BR> _nop_(); <BR> DA_WR=1; <BR>} <BR><BR>void t0(void)interrupt 1 using 0 <BR>{<BR> TH0=(65536-500)/256;<BR> TL0=(65536-500)/256; <BR> if(ST_DIR) //如果ST_DIR为1,则电机正转,D7位为低电<BR>平<BR> { <BR> DA_A0=0; //选DA通道0;<BR> DA_PORT=xf32_sin[xf_step]|0x80; <BR> DA_WR=0; //DA数据写入;<BR> _nop_(); <BR> DA_WR=1;<BR> DA_A0=1; //选DA通道1;<BR> DA_PORT=xf32_cos[xf_step]|0x80; <BR> DA_WR=0; //DA数据写入;<BR> _nop_(); <BR> DA_WR=1; <BR> } <BR> else //如果ST_DIR为0,则电机反转,D7位为高电<BR>平<BR> { <BR> DA_A0=0; //选DA通道0;<BR> DA_PORT=xf32_sin[xf_step]; <BR> DA_WR=0; //DA数据写入;<BR> _nop_(); <BR> DA_WR=1;<BR> DA_A0=1; //选DA通道1;<BR> DA_PORT=xf32_cos[xf_step]; <BR> DA_WR=0; //DA数据写入;<BR> _nop_(); <BR> DA_WR=1; <BR> } <BR> xf_step++; //0.5ms进次中断,电机走一步,每走64步重<BR>新循环<BR> if(xf_step>=64) {xf_step=0;} <BR>} <BR>void main(void) <BR>{ <BR> TMOD=0x01;<BR> TH0=(65536-500)/256;<BR> TL0=(65536-500)/256;<BR> TR0=1;<BR> ET0=1;<BR> EA=1; //开放系统中断<BR> StopMt(); <BR> while(1); <BR>}<BR><BR></P><IFRAME
name=cc src="C51BBS论坛C51编程二相步进电机32细分驱动程序.files/cc.htm" frameBorder=0
width="100%" scrolling=no height=75 allowTransparency
color="#efefef"> </IFRAME>
<UL>
<LI><B>(附图) [lenvy] <FONT
color=#d5d5d5>2008-5-16 9:48:13</FONT></B>
<P><IMG
src="C51BBS论坛C51编程二相步进电机32细分驱动程序.files/13744649.jpg"><BR><BR></P>
<LI><B>细分的原理是什么,是片子自带的,还是你用程序写出来的 [ersha] <FONT
color=#d5d5d5>2008-5-19 17:38:34</FONT></B>
<P><BR></P><!--Add Reply--></LI></UL></SPAN></TD></TR></TBODY></TABLE><A
href="http://www.c51bbs.com/c51bbs/moredata.asp?syid=812029">点击回主题参与讨论
>>></A><BR>_____________________________________________________________________________<BR>Copyright©,C51BBS论坛
1999-2006 <BR><BR></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -