Monday, 1 October 2012


Interfacing Stepper motor with 8051 microcontroller

Interfacing Stepper motor with driver circuit and 8051 microcontroller.
There are 3 buttons for forward, reverse and stop functions.

Circuit Diagram

C Code

Code:
#include <reg51.h>
#include <absacc.h>
sbit p10=P1^0;
sbit p11=P1^1;
sbit p12=P1^2;

#define  UP   20
#define  DOWN  30
#define  STOP  40

void delay()//Delay process
{
 unsigned i,j,k;
 for(i=0;i<0x02;i++)
  for(j=0;j<0x02;j++)
   for(k=0;k<0xff;k++);
}

main()
{
 unsigned char temp;
 while(1)
 {
  if(p10==0)
  {
   temp=UP;//Control is transferred
   P2=0X00;
   delay();
  }
  if(p11==0)
  {
   temp=DOWN;//Inversion of control
   P2=0X00;
   delay();
  }
  if(p12==0)
  {
   temp=STOP;//Control stop
  }
  switch(temp)
  {
  case DOWN : P2=0X01;//Inversion of control //0011
     delay();
     delay();
     P2=0X02;//0110
     delay();
     delay();
     P2=0X04;//1100
     delay();
     delay();
     P2=0X08;//1001
     delay();
     delay();
     break;
  case UP : P2=0X08;//Control is transferred
     delay();
     delay();
     P2=0X04;
     delay();
     delay();
     P2=0X02;
     delay();
     delay();
     P2=0X01;
     delay();
     delay();
     break;
  case  STOP ://Control stop
     P2=0X00;
     delay();
     delay();     
     break;
  }
   }
}
Download proteus file: ex-22.zip

No comments:

Post a Comment