/**************************** 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);
}
}
}
}