1. You can now buy finished microcontroller project from us, Check out the Store for the complete list of projects.
  2. Need a custom project, Send us some details about your project. So that we can quote the price for it.

Interfacing Stepper motor with 8051 microcontroller 1.0

Interfacing Stepper motor with 8051 microcontroller

  1. sajiv jess
    Interfacing Stepper motor with driver circuit and 8051 microcontroller.
    There are 3 buttons for forward, reverse and stop functions.
    [​IMG]


    Code (Text):
    1. #include <reg51.h>
    2. #include <absacc.h>
    3. sbit p10=P1^0;
    4. sbit p11=P1^1;
    5. sbit p12=P1^2;
    6.  
    7. #define  UP  20
    8. #define  DOWN  30
    9. #define  STOP  40
    10.  
    11. void delay()//Delay process
    12. {
    13.     unsigned i,j,k;
    14.     for(i=0;i<0x02;i++)
    15.         for(j=0;j<0x02;j++)
    16.             for(k=0;k<0xff;k++);
    17. }
    18.  
    19. main()
    20. {
    21.     unsigned char temp;
    22.     while(1)
    23.     {
    24.         if(p10==0)
    25.         {
    26.             temp=UP;//Control is transferred
    27.             P2=0X00;
    28.             delay();
    29.         }
    30.         if(p11==0)
    31.         {
    32.             temp=DOWN;//Inversion of control
    33.             P2=0X00;
    34.             delay();
    35.         }
    36.         if(p12==0)
    37.         {
    38.             temp=STOP;//Control stop
    39.         }
    40.         switch(temp)
    41.         {
    42.         case DOWN : P2=0X01;//Inversion of control //0011
    43.                     delay();
    44.                     delay();
    45.                     P2=0X02;//0110
    46.                     delay();
    47.                     delay();
    48.                     P2=0X04;//1100
    49.                     delay();
    50.                     delay();
    51.                     P2=0X08;//1001
    52.                     delay();
    53.                     delay();
    54.                     break;
    55.         case UP :    P2=0X08;//Control is transferred
    56.                     delay();
    57.                     delay();
    58.                     P2=0X04;
    59.                     delay();
    60.                     delay();
    61.                     P2=0X02;
    62.                     delay();
    63.                     delay();
    64.                     P2=0X01;
    65.                     delay();
    66.                     delay();
    67.                     break;
    68.         case  STOP ://Control stop
    69.                     P2=0X00;
    70.                     delay();
    71.                     delay();                  
    72.                     break;
    73.         }
    74.   }
    75. }
Loading...