#include #include #include #include #include "v25.h" #define STEPPORT 0x7900 /* STEPPING MOTOR PORT */ #define OUTPORT0 0x7880 #define PRE_SCALE 10 void main(void) { unsigned char speed, ch; unsigned char step = 1; unsigned char led = 1, prescaler = PRE_SCALE, photo; int direction = 0; do { printf("\nInput Speed 1 - 9 : "); speed = getch(); printf("%c", speed); } while ((speed < '1') || (speed > '9')); printf("\n"); for (;;) { photo = (peekb(V25_IRAM, V25_P1) & 0x20) ? 0x80 : 0xC0; outportb(OUTPORT0, led | photo); outportb(STEPPORT, step); delay((0x3B - speed) * 10); if (!(--prescaler)) prescaler = PRE_SCALE; if (direction) { step <<= 1; if (step == 0x10) step = 1; if (prescaler == PRE_SCALE) { led <<= 1; if (led == 0x40) led = 1; } } else { step >>= 1; if (step == 0) step = 0x08; if (prescaler == PRE_SCALE) { led >>= 1; if (led == 0) led = 0x20; } } if (kbhit()) { if ((ch = getch()) == ' ') direction = !direction; else if ((ch >= '1') && (ch <= '9')) speed = ch; else break; } } outportb(STEPPORT, 0); outportb(OUTPORT0, 0); }