stepmotor_main.c

来自「s3c2410平台 步进电机的demo」· C语言 代码 · 共 63 行

C
63
字号
/* * stepmotor_main.c * * S3C2410-S STEPMOTOR * derived from s3c2410_exio.c * * Author: wang bin <wbinbuaa@163.com>	 * Date  : $Date: 2005/07/25 $  * * $Revision: 1.0.0.1 $ *						 * This file is subject to the terms and conditions of the GNU General Public * License.  See the file COPYING in the main directory of this archive * for more details. */#include <stdio.h>#include <fcntl.h>#include <string.h>#include <sys/ioctl.h>#define STEPMOTOR_IOCTRL_PHASE 		0x13static int step_fd = -1;char *STEP_DEV="/dev/exio/0raw";/****************************************************************        A,	AB,	B,	BC,	C	CD,	D,	DA ****************************************************************///char stepdata[]={0x10,0x30,0x20,0x60,0x40,0xc0,0x80,0x90};char stepdata[]={0x90,0x80,0xc0,0x40,0x60,0x20,0x30,0x10};void Delay(int t){	int i;	for(;t>0;t--)		for(i=0;i<400;i++);}/****************************************************************/int main(int argc, char **argv){	int i,j = 0;		if((step_fd=open(STEP_DEV, O_WRONLY))<0){		printf("Error opening /dev/exio/0raw device\n");		return 1;	}	printf("/dev/exio/0raw device opened\n");	for (j=0;j<4;j++) {		for (i=0; i<sizeof(stepdata)/sizeof(stepdata[0]); i++) {			ioctl(step_fd, STEPMOTOR_IOCTRL_PHASE, stepdata[i]);			}		Delay(10);		for(i=0;i<sizeof(stepdata)/sizeof(stepdata[0]);i++){			ioctl(step_fd,STEPMOTOR_IOCTRL_PHASE,stepdata[i]);			}		printf("Delay(100)\n");		Delay(100);	}		close(step_fd);		printf("Step motor start running!\n");	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?