0% found this document useful (0 votes)
22 views2 pages

Stepper Motor

The document describes a program for interfacing a stepper motor that rotates in a clockwise direction by default. A switch (SW27) can be pressed to change the rotation direction, which triggers an interrupt to toggle the direction flag. The program includes a delay routine and continuously checks the direction to control the motor's movement accordingly.

Uploaded by

CHIRAG V CHANDRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Stepper Motor

The document describes a program for interfacing a stepper motor that rotates in a clockwise direction by default. A switch (SW27) can be pressed to change the rotation direction, which triggers an interrupt to toggle the direction flag. The program includes a delay routine and continuously checks the direction to control the motor's movement accordingly.

Uploaded by

CHIRAG V CHANDRA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/**************************** Stepper Motor

*******************************

Object : To demonstrate the Stepper motor interface.

Output: whenever you run the program the motor rotates in clockwise.
If you want to change the direction press the switch SW27.
when you press the button, INT0 interrupts the main program
and changes the direction of the motor .

*************************************************************************
*/
#include "at89c51ed2.h"

static bit Dir=0;


//sbit buzzer = P0^5;

void ChangeDir(void) interrupt 0 /* Int Vector at 000BH, Reg Bank 1


*/
{
Dir = ~Dir; /* Complement the Direction flag */
}
void delay(unsigned int x) /* Delay Routine */
{
for(;x>0;x--);
}
main()
{
unsigned char Val,i;
EA=0x1; /* Enable Interrupt flag and Interrupt
0 & Serial Interrupt */
EX0=0x1;
ES=1; /*since the monitor is using the serial interrupt it has
to be enabled*/

while(1)
{

if(Dir) //* If Dir Clockwise


{

Val = 0x08;
for(i=0;i<4;i++)
{
P0 = Val; //* Write data for clock wise
direction
Val = Val >> 1;
delay(10000);

}
}
else // AntiClockwise Direction
{

Val = 0x01;
for(i=0;i<4;i++)
{
P0 = Val; // Write data for anticlock wise
direction
Val = Val<<1;
delay(10000);
}
}
}
}

You might also like