网站首页
IC库存
IC展台
电子资讯
技术资料
PDF文档
我的博客
IC72论坛
ic72 logo
资料首页最新产品 技术参数 电路图 设计应用 解决方案 代理商查询 IC替换 IC厂商 电子辞典
关键字: 技术文章 PDF资料 IC价格 电路图 代理商查询 IC替换 IC厂商 电子辞典

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 */

}

热门搜索:2320319 TLP6B SS7619-15 BQ25895MRTWR N060-002 2320351 PS-415-HGULTRA 2839211 TLP825 TLP810NET 2856142 TLP404 N060-004 SS7415-15 01B1002JF BT-M515RD TRAVELER3USB 8300SB2-LF SUPER6OMNI B TLP606B CC2544RHBR PDU2430 2320089 TLP1008TEL PM6NS
COPYRIGHT:(1998-2010) IC72 达普IC芯片交易网
客户服务:service@IC72.com 库存上载:IC72@IC72.com
(北京)联系方式: 在线QQ咨询:点击这里给我发消息 联系电话:010-82614113 传真:010-82614123