Stepper motor control system based on single-chip microcomputer

1. Project Introduction:

This project uses the 51 microcontroller to implement a stepper motor control system, which can realize the forward and reverse rotation, acceleration and deceleration, start and stop of the stepper motor, and display the working status of the motor through LCD. Through this system, you can control the direction and speed of stepper motor start, rotation.

2. Main functions:

  • Stepper motor forward and reverse rotation: By controlling the input signal of the motor driver, the forward and reverse rotation of the stepper motor can be realized.
  • Acceleration and deceleration control: By gradually increasing or decreasing the pulse frequency of the stepper motor, the acceleration and deceleration of the motor can be achieved.
  • Start and stop control: By controlling the pulse signal of the stepper motor, the rotational motion of the motor can be started and stopped.
  • LCD displays motor working status: By connecting to the LCD display module, the working status of the motor can be displayed in real time, including direction, speed, status and other information.

 

3. Hardware composition:

  • 51 microcontroller development board: As the main controller, it is responsible for receiving user input and controlling stepper motor movement.
  • Stepper motor: used to drive mechanical devices to achieve rotational motion.
  • Stepper motor driver: used to receive control signals from the 51 microcontroller and drive the stepper motor to move.
  • LCD display module: used to display the working status information of the motor.

 

Components list:

Component Model Quantity
Microcontroller AT89C51 1
Crystal Oscillator 12MHZ 1
Resistor 10k 1
Capacitor 10uf 1
Capacitor 30pf 1
Button   7
Driver ULN2003 1
Stepper Motor 4-phase 5-wire 1
Display LCD1602 1
Resistor Network 10k 1

4. Software design:

  • Hardware initialization: Initialize the 51 microcontroller and LCD display module.
  • User input processing: Receive user instructions through keys or other input methods, including parameters such as direction, speed, and operation.
  • Control signal generation: According to the parameters input by the user, the corresponding control signal is generated to control the movement of the stepper motor.
  • Status display: Display the working status information of the stepper motor through LCD, including direction, speed and status, etc.

 

5. Project advantages:

  • Flexibility: The movement mode and parameters of the stepper motor can be controlled through user input according to the user's needs.
  • Real-time feedback: The working status of the motor is displayed in real time through the LCD display module to facilitate users to understand the operation of the motor.
  • Simple and easy to use: The design based on 51 microcontroller is simple, easy to understand and implement.

 

6. Part of the code

#include "reg51.h"
#include "lcd1602.h"
#define uchar unsigned char
#define uint unsigned int
sbit AA=P2^4;
sbit BB=P2^5;
sbit CC=P2^6;
sbit DD=P2^7;
sbit k1=P1^0;
sbit k2=P1^1;
sbit k3=P1^2;
sbit k4=P1^3;
sbit k5=P1^4;
sbit k6=P1^5;
uchar flag=0,fang=0;
uchar speed=0,time=0;
uchar start=0;
uchar sec=0;
uchar disp1[]="sudu:0 ";
void main()
{
init_1602();
TMOD|=0X01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
ET0=1;
EA=1;
TR0=1;
while(1)
{
if(!k1)
{
start=1;
}
if(!k2)
{
start=0;
}
if(!k3)
{
fang=0;
}
if(!k4)
{
fang=1;
}
if(!k5)
{
if(speed<9)
speed++;
while(!k5);
}
if(!k6)
{
if(speed>0)
speed--;
while(!k6);
}
}
}
void Timer0() interrupt 1
{
if(start==1)
{
if(time<10-speed)
{
time++;
}
else
{
time=0;
if(fang==0)
{
switch(flag)
{
case 0:BB=1;break;
case 2:CC=1;break;
case 3:BB=0;break;
case 4:DD=1;break;
case 5:CC=0;break;
case 6:AA=1;break;
case 7:DD=0;
}
if(flag<7)
flag++;
else
flag=0;
}
else
{
switch(flag)
{
case 0:DD=1;break;
case 1:AA=0;break;
case 2:CC=1;break;
case 3:DD=0;break;
case 4:BB=1;break;
case 5:CC=0;break;
case 6:AA=1;break;
case 7:BB=0;
}
if(flag<7) flag++;
else
flag=0;
}
}
}
if(sec<50)
sec++;
else
{
sec=0;
disp1[5]=speed+0x30;
write_string(1,0,disp1);
if(start)
{
if(fang==0)
{
write_string(2,6,"right");
}
else
{
write_string(2,6,"left ");
}
}
else
{
write_string(2,6,"stop ");
}
}
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
}

Call Us or Fill the Form