Interfacing Stepper motor to 8051 MC

YouTube link is here  Interfacing Stepper motor with 8051 MC


Please find Code details below:

#include<reg51.h>
sbit w = P2^0;                          
sbit x = P2^1;                                      // Motor pins assigned to port 2
sbit y = P2^2;                           
sbit z = P2^3;                           
sbit H = P1^0;                               // Home switch is connected to port 1, pin-0
sbit R_45 = P1^2;                               // Rotate_45 switch is connected to port 1, pin-2
sbit R_90 = P1^4;                               // Rotate_90 switch is connected to port 1, pin-4
sbit R_135 = P1^6;                             // Rotate_135 switch is connected to port 1, pin-6
sbit R_180 = P1^7;                             // Rotate_180 switch is connected to port 1, pin-7

                                                     
void Home()                                //  Motor "Home" function (Starting stage)
{
 w = 0;
 x = 1;
 y = 0;
 z = 1;
}
void Rotate_45()                             // Motor "Rotate 45deg" function
{
 w = 0;
 x = 1;
 y = 0;
 z = 0;
}
void Rotate_90()                                        // Motor "Rotate 90deg" function
{
 w = 1;
 x = 1;
 y = 0;
 z = 0;
}
void Rotate_135()                                   // Motor "Rotate 135deg" function
{
 w = 1;
 x = 1;
 y = 1;
 z = 0;
}
void Rotate_180()                                     // Motor "Rotate 180deg" function
{
 w = 1;
 x = 0;
 y = 1;
 z = 0;
}
void main()                                        // Main function 
{
  H = 0;                                              // Initialize all switches to zero 
  R_45 = 0;
  R_90= 0;
  R_135 = 0;
R_180 = 0;
  while(1)
   {
     if(H==1)
        Home();                                  
     else if(R_45==1)
        Rotate_45();
     else if(R_90==1)
        Rotate_90();
     else if(R_135==1)
Rotate_135();
else if(R_180==1)
Rotate_180();
     else
         Home();
    }
}

Thank You :)

Comments

Popular posts from this blog

Interfacing 7 segment display with 8051

How to make robot car using 8051

Led Chaser using 8051