cxjandczz cxjandczz
企业管理,武汉
关注数: 2 粉丝数: 24 发帖数: 447 关注贴吧数: 65
大神帮我看下程序与端口访问出错 实现步进电机单相、二相、半步激磁三种方式正反运转。 #include<windows.h> #include<string.h> //#include<dos.h> #include<conio.h> #include<stdio.h> #define PC 0x302 #define CR 0x303 unsigned char pulse1 []={0x01,0x02,0x04,0x08}; unsigned char pulse2 []={0x09,0x03,0x06,0x0c}; unsigned char pulse3 []={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09}; char mode=1,dd; void forward(void); void reverse(void); void gotoxy(int a,int b){ int x=0x0b; HANDLE hOutput; COORD loc; loc.X = a; loc.Y=b; hOutput = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOutput, loc); } main() { char ch; //_outp(CR,0x90); system("CLS"); puts("f"); puts("fsdf"); puts("fsf"); puts("dsf"); puts("sdcv"); puts("ds"); while(1) { if(kbhit()) { ch=getch(); if(ch==107)forward(); /*k*/ if(ch==109)reverse(); /*m*/ if(ch=='1')mode=1; if(ch=='2')mode=2; if(ch=='3')mode=3; if(ch==27)break; gotoxy(3,8); printf("Mode:%d",mode); } //_outp(PC,0xff); } } void forward(void) { int i,c,no; if(mode==1||mode==2)no=4; else no=8; printf(" forward"); for(c=0;c<10;c++) for(i=0;i<no;i++) { if(mode==1)_outp(PC,~pulse1[i]); if(mode==2)_outp(PC,~pulse2[i]); if(mode==3)_outp(PC,~pulse3[i]); Sleep(50); } } void reverse(void) { int i,c,no; if(mode==1||mode==2)no=3; else no=7; printf(" reverse"); for(c=0;c<10;c++) for(i=no;i>=0;i--) { if(mode==1)_outp(PC,~pulse1[i]); if(mode==2)_outp(PC,~pulse2[i]); if(mode==3)_outp(PC,~pulse3[i]);Sleep(50); } } 邮箱[email protected] 谢谢了~~
1 下一页