di2590.txt ;************************************************************************************************** ; LISTING 1 - STEPPER-MOTION-CONTROL PROGRAM ; ; "PC's BIOS interrupt drives twin stepper motors," EDN, Sep 14, 2000, pg 184 ; ; http://www.ednmag.com/ednmag/reg/2000/09142000/designideas.htm#18di3 ; *************************************************************************************************** #include #include #include #define OUT_PORT 0X378 /* Out port address of LPT2 */ #define CTRL_PORT 0X37A /* Control port address of LPT2 */ #define INTRTIMER 0x1C /* BIOS Timer (INT 1CH)Interrupt */ /*----------------------------------------------------------------------*/ /*-------------------------GLOBAL VARS----------------------------------*/ static int TICKER; static int DATA; void interrupt (*timerhandler)(); void interrupt STEPPERHANDLER(); /*----------------------------Handler routine for INT 1C---------------*/ void interrupt STEPPERHANDLER() { disable(); switch(TICKER % 16) /* Reminder in No. of TICKER divide by 16 sets four cases for setting four DATA type. This method of TICKER Processing sets the ON time of the stepper of 220 milli seconds. For various ON time tuning this division factor is to be changed and the corresponding reminder is to be included in the case field. */ { case 0: DATA = 0xCC; break; /* First step for clockwise full step i.e., 1 1 0 0 */ case 4: DATA = 0x66; break; /* Second step for clockwise full step i.e., 0 1 1 0 */ case 8: DATA = 0x33; break; /* Third step for clockwise full step i.e., 0 0 1 1 */ case 12: DATA = 0x99; break; /* Fourth step for clockwise full step i.e., 1 0 0 1 */ } outportb(OUT_PORT,DATA); ++TICKER; enable(); } /* END OF STEPPERHANDLER */ void INSTALLSTEPPERHANDLER() { disable(); timerhandler = getvect(INTRTIMER); setvect(INTRTIMER,STEPPERHANDLER); enable(); } void CLEARSTEPPERHANDLER() { disable(); setvect(INTRTIMER,timerhandler); enable(); } void main(void) { clrscr(); outportb(CTRL_PORT,0x01); INSTALLSTEPPERHANDLER(); while (TICKER <=100) /* This loop is only to test whether the Sequential DATA is properly sent to LPT2 port. This can be removed in the original program*/ printf("TICKER No: %d Value %X sent to port number %x\n", TICKER, DATA,OUT_PORT); CLEARSTEPPERHANDLER(); return; }