Motor a pasos

#include<stdio.h> #include<stdlib.h> #include<dos.h> #define COM 0x2f8 void giro(int sentido,int veces); unsigned int D_REG=0x378; unsigned int E_REG=0x379; unsigned int D_IN; unsigned int D_OUT; int main(void){ ////////////////////////////////////////////////////////////////////// //Configuración de los parámetros del puerto serie outport(0x2fb,0x80); /* DLAB=1 */ outport(0x2f8,0x06); /* divisor (Low) =0x06 vel 19200 baudios */ outport(0x2f9,0x00); /* divisor (High)=0x00 vel 19200 baudios */ outport(0x2fb,0x07); /* 8 bits ,2 stop, sin paridad */ outport(0x2fc,0x08); /* out 2 = 1 */ outport(0x2f9,0x01); ///////////////////////////////////////////////////////////////////// //lectura del puerto //valor = inportb(COM); //escritura del puerto serie (valor en decimal) //outportb(COM, 102); while(1){ D_IN=inportb(E_REG); // printf("%u\n",D_IN); D_OUT=0x03; if(D_IN<160){ printf("GIRO HACIA. 720 grados.\n"); giro(1,160*32); } else if(D_IN<192){ printf("GIRO HACIA. 180 grados.\n"); giro(0,32*32); } else if(D_IN<224){ printf("GIRO HACIA. 360 grados.\n"); giro(1,96*32); } else{ printf("GIRO HACIA. 1080 grados.\n"); giro(0,192*32); } char a; scanf("%c",&a); if(a=='a') break; } return 0; } //Funcion de giro void giro(int sentido,int veces){ int actual=0; while(actual<veces){ outportb(D_REG,D_OUT); delay(5); if(sentido==1){ D_OUT<<=1; if(D_OUT==0x18) D_OUT=0x09; else if(D_OUT>0x12) D_OUT=0x03; } else{ D_OUT>>=1; if(D_OUT==0x01) D_OUT=0x09; else if(D_OUT==0x04) D_OUT=0x0C; } actual++; } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.