AT89C2051驱动步进电机的电路和源码电路如图所示: 程序:stepper.c stepper.hex /* * STEPPER.C * sweeping stepper's rotor cw and cww 400 steps * Copyright (c) 1999 by W.Sirichote */ #i nclude c:mc5151io.h /* include i/o header file */ #i nclude c:mc5151reg.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 */ }
导读:目前正在解读《AT89C2051驱动步进电机的源代码》的相关信息,《AT89C2051驱动步进电机的源代码》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《AT89C2051驱动步进电机的源代码》的详细说明。
简介:这里和大家分享了一个AT89C2051驱动步进电机的电路和源代码。
提醒:《AT89C2051驱动步进电机的源代码》最后刷新时间 2024-03-14 01:02:41,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《AT89C2051驱动步进电机的源代码》该内容的真实性请自行鉴别。