Interface stepper motor to 8051 using Driver
YouTube link is here Interface stepper motor to 8051 using Driver

Please check code details below:
#include <regx51.h>
sbit En=P2^0; // Enable pin is set to P2.0
sbit Rs=P2^1; // Reset pin is set to P2.1
sbit H_F=P2^2; // Half / Full pin is set to P2.2
sbit Cw_Ccw=P2^3; // Clockwise / Counter CW pin is set to P2.3
sbit Clock=P2^4; // Clock pin is set to P2.4
sbit Stop_Button=P1^0; // To stop the Stepper motor
sbit F_Button = P1^2; // Half wave Button
sbit Ccw_Button = P1^4; // Anti Clockwise Button
void delay() // 500ms Delay function using Timers
{
int count=0;
while(count!=500) // This loop Counts 500 times
{
TMOD = 0x01; // Timer0 mode1
TH0 = 0xFC; //initial value for 1ms in TH0 and TL0
TL0 = 0x66;
TR0 = 1; // To Enable the Timer-0
while(!TF0); // check overflow condition
TR0 = 0; // Timer-0 Disable
TF0 = 0; // Clear flag
count++;
}
}
void clock_pulse() // Using Delay we Generate Clock pulse
{
Clock = 1; // This clock pulse assign to P2.4
delay();
Clock = 0;
delay();
}
void Stop() // Stop Function
{
En = 1; //To stop the Stepper motor we need this
Rs = 0;
}
void Half_wave() // Half wave function
{
clock_pulse(); // Used to run the S-motor in Half wave mode
H_F = 1;
}
void Full_wave() // Full wave function
{
clock_pulse(); // Used to run the S-motor in Full-wave mode
H_F = 0;
}
void main() // Main Function
{
En = 0; // Initailly all pins set to 0
Rs = 1; // Except Reset pin
H_F = 0;
Cw_Ccw = 0;
while(1)
{
if(Stop_Button==0) // Condition for Stop the S-motor
Stop();
else if(Ccw_Button==0) // Condition for S-motor runs in Anti-Clock wise direction
{
En = 1;
Rs = 1;
Cw_Ccw = 0;
if(F_Button==0) // Condition for Full wave mode
Full_wave();
else
Half_wave(); // Condition for Half wave mode
}
else
{ // Initial this condition is active.
En = 1;
Rs = 1;
Cw_Ccw = 1; // Used to run S-motor in Clockwise direction
if(F_Button==0)
Full_wave();
else
Half_wave();
}
}
}
Comments
Post a Comment