Pages

program for Stepper motor interface in 8051


#include <REG51xD2.H>
static bit Dir=0;
void delay(unsigned int x) /* Delay Routine */
{
for(;x>0;x--);
}
void ChangeDir(void) interrupt 0 /* Int Vector at 000BH, Reg Bank 1 */
{
Dir = ~Dir; /* Complement the Direction flag */
ClrLcd();
if(Dir)
delay(32000);
else
delay(32000);
}
main()
{
unsigned char Val,i;
EA=0x1; /* Enable Interrupt flag and Interrupt 0 & Serial Interrupt */
EX0=0x1;
ES=0x1;
P0=0x00; /*since the monitor is using the serial interrupt it has to be enabled*/
while(1)
{
if(Dir) /* If Dir Clockwise */
{
Val = 0x88;
for(i=0;i<4;i++)
{
P0 = Val; /* Write data for clock wise direction*/
Val = Val>>1;
delay(575);
}
}
else /* AntiClockwise Direction */
{
Val = 0x11;
for(i=0;i<4;i++)
{
P0 = Val; /* Write data for anticlock wise direction*/
Val = Val<<1;
delay(575);
}
}
}
}

0 comments:

Post a Comment