setmotor.c
来自「在博创的44B0开发板上做的一个电机控制的程序」· C语言 代码 · 共 86 行
C
86 行
#include <stdio.h>#include <unistd.h>#include <linux/delay.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/ioctl.h>#include <pthread.h>#include "hardware.h"#include "motor.h"#include "exio.h"#include "motor.c"#include "exio.c"#define ADCCON_FLAG 0x40#define ADCCON_SLEEP 0x20#define ADCCON_ADIN0 (0x0<<2)#define ADCCON_ADIN1 (0x1<<2)#define ADCCON_ADIN2 (0x2<<2)#define ADCCON_ADIN3 (0x3<<2)#define ADCCON_ADIN4 (0x4<<2)#define ADCCON_ADIN5 (0x5<<2)#define ADCCON_ADIN6 (0x6<<2)#define ADCCON_ADIN7 (0x7<<2)#define ADCCON_READ_START 0x2#define ADCCON_ENABLE_START 0x1void Delay(int t){ //struct timespec dt={0,10000}; //dt.tv_nsec*=t; //nanosleep(&dt, NULL); int i; for(;t>0;t--) for(i=0;i<400;i++);}short device;int setmotor(int data,short dev){ //////////////////A, AB, B, BC, C, CD, D, DA int stepdata[]={0x10,0x30,0x20,0x60,0x40,0xc0,0x80,0x90}; int i,speed,count;// void *retval; init_exio(); device=dev; //start MotorPort init_MotorPort(); Delay(1); while(device==0) { if(k==0){ break; } speed=data; Delay(10); SetPWM(speed*MOTOR_CONT/1024); Delay(10); } SetPWM(0); Delay(1000); while(k!=0){} /* control step motor*/ i=0; while(device==1){ count=data; if(count>0){ i++; }else if (count<0){ i--; count=-count; } i=0x7&i; SETEXIOBITMASK(stepdata[i], 0xf0); Delay(512*10/count); } init_MotorPort(); exit_MotorPort(); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?