/* CONTROL DE ACTUADORES Y SENSORES MEDIANTE PUERTO PARALELO Control de un motor de c.c. Motor conectado a los 2 primeros pines de datos mediante una etapa de potencia (transistores TIP125-120) + - D0 --- (etapa) --- M --- (etapa) --- D1 2002 V¡ctor R. Gonz lez */ #include #include #include /* Direcciones del puerto paralelo */ #define LPT_BASE 0x378 #define DATOS LPT_BASE #define ESTADO LPT_BASE+1 #define CONTROL LPT_BASE+2 /* Valores que activan el giro y la parada del motor */ #define APAGA_MOTOR 0x03 /* D0=1 (pin2), D1=1 (pin 3) */ #define GIRO_HORARIO 0x02 /* D0=0 (pin2), D1=1 (pin 3) */ #define GIRO_ANTIHORARIO 0x01 /* D0=1 (pin2), D1=0 (pin 3) */ /* Macro que env¡a un valor al puerto de DATOS */ #define Activa(valor) outportb (DATOS, valor) main () { unsigned tecla, pos_x, pos_y; Activa(APAGA_MOTOR); /* Comienza con el motor detenido */ printf("Control de un motor c.c.:\n"); printf("\t - = giro en sentido horario\n"); printf("\t + = giro en sentido antihorario\n"); printf("\t p = parada\n"); printf("\t s = salir\n\n"); pos_x = wherex(); pos_y = wherey(); tecla = 0; do { if ( kbhit() ) tecla = getch(); gotoxy(pos_x, pos_y); switch (tecla) { case '+': /* Giro en sentido antihorario */ printf("\t... giro antihorario ..."); Activa(GIRO_ANTIHORARIO); break; case '-': /* Giro en sentido horario */ printf("\t... giro horario ... "); Activa(GIRO_HORARIO); break; case 'p': /* Parada */ printf("\t... detenido ... "); Activa(APAGA_MOTOR); break; } } while (tecla != 's'); printf("\n"); Activa(APAGA_MOTOR); /* Detiene el motor si no lo estaba ya */ return 0; }