Control stepping motor forward and reverse based on 51 single chip microcomputer

Control stepping motor forward and reverse based on 51 single chip microcomputer

This time, the uln2003 module is used to link the stepper motor;
## The working principle of
stepper motor The stepper motor is a motor that converts electrical pulse signals into corresponding angular displacement or linear displacement. Each time a pulse signal is input, the rotor rotates by an angle or one step forward. The output angular displacement or linear displacement is proportional to the number of input pulses, and the speed is proportional to the pulse frequency.
Stepping motors have many structural forms and classification methods. Generally, they are divided into three types: reluctance type, permanent magnet type and mixed magnet type according to the excitation mode; according to the number of phases, they can be divided into single-phase, two-phase, three-phase and multiple equal forms. .

Therefore, we can control the level of the I/O port of the single-chip microcomputer to control the stepper motor. In this design, the four-phase single-shot working mode is adopted. In this working mode, the A, B, C, and D three-phase wheels are energized and the current Switch three times, the magnetic field rotates once, and the rotor rotates forward through a pitch angle. Therefore, this energization method is called four-phase single four-beat work.

  1. Motor forward code unsigned char code tableZ[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};
  2. Unsigned char code tableF[8]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};

code show as below

#include <reg52.h>
#define uint unsigned int 
#define uchar unsigned char
unsigned char code tableZ[8]={
    
    0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};
unsigned char code tableF[8]={
    
    0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};//²½½øµç»úzheng
void delay(unsigned int t);
sbit S3=P3^4; //反转
sbit S4=P3^5; //反停
sbit S5=P3^6; // 正停
//正转写入数据
void  motor_z()
 {
    
     
   unsigned char i,j;
  
      for (i=0; i<8; i++)  
        {
    
    
     if(S5==0){
    
    break;}
     for(j=0;j<8;j++){
    
    
      P1 = tableZ[i]&0x1f;    
          delay(50);
     }
                       
        }
 }
//反转写入数据
void motor_f(){
    
    
 unsigned char i,j;
       for (i=0; i<8; i++)  
        {
    
    
     if(S4==0){
    
    break;}
     for(j=0;j<8;j++){
    
    
      P1 = tableF[i]&0x1f;   
          delay(50);
     }
                    
        }
}
void delay(unsigned int t)//延时函数
{
    
                               
   unsigned int k;
   while(t--)
   {
    
    
     for(k=0; k<60; k++)
     {
    
     }
   }
}

void main()
{
    
    
while(1){
    
    
motor_z();
if(S3 == 0){
    
    
motor_f();
}
}
}

The protel simulation diagram is as follows

Insert picture description here

Guess you like

Origin blog.csdn.net/Lucifer_min/article/details/109248939