Four-wire two-phase stepper motor L298 driver

Publisher:boyatangLatest update time:2016-10-19 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
/ * =
... ​ ====================================================================================*/ #include #define uint unsigned int #define uchar unsigned char sbit a0=P1^0; //a phase 0 sbit a1=P1^1; //a phase 1 sbit en0=P1^2; //enable 1 sbit b0=P1^3; //b phase 0 sbit b1=P1^4; //b phase 1 sbit en1=P1^5; //enable 2 void yanshi(uint z); //delay function void zheng(uchar k,uchar j); //whole step void xifen(uchar k1,uchar j1); //1/2 step uchar b,num,n,num1,n1,h; void main() {     en0=1;     en1=1;     while(1)     {         xifen(10,100); //1/2 step subdivision delay 10mS 100 pulses if the step angle is 1.8 degrees, then turn 90 degrees         yanshi(4000);         zheng(15,50); //Full step delay 15mS 50 pulses if the step angle is 1.8 degrees, then turn 90 degrees         yanshi(4000);     } } //Full step, k is the delay time, j is the number of pulses void zheng(uchar k,uchar j) {     b=j/4; //One step requires 4 pulses     b=b+1;     num=0; //Counter cleared     for(b;b>0;b--)     {         if(num










































    






















































    h=h+1;

    num1=0;        //计数器清0

    for(h;h>0;h--)
    {
        if(num1         {
            a0=0;
            a1=1;
            b0=1;
            b1=0;
            yanshi(k1);
            num1++;
            n1=1;
        }

        if(num1         {
            a0=0;
            a1=1;
            b0=0;
            b1=0;
            yanshi(k1);
            num1++;
            n1=2;
        }

        if(num1         {
            a0=0;
            a1=1;
            b0=0;
            b1=1;
            yanshi(k1);
            num1++;
            n1=3;
        }

        if(num1         {
            a0=0;
            a1=0;
            b0=0;
            b1=1;
            yanshi(k1);
            num1++;
            n1=4;
        }

        if(num1         {
            a0=1;
            a1=0;
            b0=0;
            b1=1;
            yanshi(k1);
            num1++;
            n1=5;
        }

        if(num1         {
            a0=1;
            a1=0;
            b0=0;
            b1=0;
            yanshi(k1);
            num1++;
            n1=6;
        }

        if(num1         {
            a0=1;
            a1=0;
            b0=1;
            b1=0;
            yanshi(k1);
            num1++;
            n1=7;
        }

        if(num1         {
            a0=0;
            a1=0;
            b0=1;
            b1=0;
            yanshi(k1);
            num1++;
            n1=0;
        }
    }    


//延时函数
void yanshi(uint z)
{
    uint x,y;
    for(x=z;x>0;x--)
    for(y=114;y>0;y--);
}
Reference address:Four-wire two-phase stepper motor L298 driver

Previous article:Writing and simulating digital clock program based on 8051 and Proteus
Next article:Application of Password Access Device X76F100 in Single Chip Microcomputer System

Recommended ReadingLatest update time:2024-11-16 19:53

High-power LED driver without external switch
With the recent emergence of new, higher-power and more efficient LEDs, LEDs are rapidly being used in new applications, such as flashlights and automotive equipment. High-power LEDs are even being used in ambient lighting applications that have long been dominated by incandescent and fluorescent lamps. The best way
[Power Management]
High-power LED driver without external switch
ABB servo drive fault code analysis and maintenance methods
What are the fault code analysis and maintenance methods for ABB servo drives? Error number: 1 Error name: OVERCURRENT Error/alarm description: Output current is too high. Check and repair: Engine load is too large, acceleration time is insufficient (parameters 2202 ACCELERTIME 1 and 2205 ACCELERTIME 2), motor,
[Embedded]
HC595 drives digital tube
The 74HC595 is an 8-bit serial input, parallel output shift register. Pin Definition Q0~Q7: parallel output Q7': Serial output SH_CP: Shift register clock input ST_CP: Storage register clock input DS: Serial input Schematic Example Common cathode digital tube control #define uchar unsigned char void LED_Di
[Microcontroller]
HC595 drives digital tube
Servo drive control requirements for servo motor
The control requirements of servo drives for servo motors is a complex and in-depth topic. The following is an overview of the control requirements of servo drives for servo motors: Precision: Servo drives need to be able to precisely control the position, velocity, and acceleration of the motor to meet th
[Embedded]
Melexis' new pump/fan driver chip optimizes service life to a new level
Pump driver chips specifically for automobiles meet the needs of high temperature environments and long service life TESSENDLO, Belgium, October 29, 2021 - Melexis, a global microelectronics engineering company, has expanded its MLX90412 product family to meet the needs of more challenging customer de
[Industrial Control]
Melexis' new pump/fan driver chip optimizes service life to a new level
Tips for Improving Lighting Driver Power Efficiency
Tips for Improving Lighting Driver Power Efficiency 1. First of all, of course, choose a high-efficiency topology This is the beginning of solution selection. For example, for PWM and QR PFM, if soft switching can be used, try to use soft switching topology (soft switching has low loss). When customers put
[Power Management]
Linear adjustable differential transformer driver and demodulator circuit diagram
Linear adjustable differential transformer driver and demodulator circuit diagram
[Analog Electronics]
Linear adjustable differential transformer driver and demodulator circuit diagram
51 single chip microcomputer driving touch screen comprehensive experiment source program
Step 1: According to the development board MCU model, select "Experiment 28: Development board resource data download - 1. Development board resource data download" and download the program to the STC8A development board to run. When downloading the program, the ISP software settings are: IRC frequency 22.1184MHZ when
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号