L297, L298 drive stepper motor schematic diagram proteus simulation + program LCD display speed

Publisher:JoyfulHeartedLatest update time:2019-11-16 Source: 51heiKeywords:L297 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Schematic diagram of L297, L298 driving stepper motor, tested and available

The 51 single-chip microcomputer program for L297 and L298 to drive the stepper motor is as follows:

#include "AT89X51.h"


int delay();

void inti_lcd();

void show_lcd(int);

void cmd_wr();

void ShowState();

void clock(unsigned int Delay) ;

void DoSpeed(); //Calculate speed

//Positive rotation value

#define RIGHT_RUN 1

//Reverse value

#define LEFT_RUN 0

sbit RS=0xA0;

sbit RW=0xA1;

sbit E=0xA2;


char SpeedChar[]="SPEED(n/min):";

char StateChar[]="RUN STATE:";

char STATE_CW[]="CW";

char STATE_CCW[]="CCW";

char SPEED[3]="050";

unsigned int RunSpeed=50; //speed

unsigned char RunState=RIGHT_RUN; //Running status

main()

{

        

        /*Timer settings*/

        TMOD=0x66; //Timer 0, 1 are both in counting mode; mode 2;

        EA=1; //Enable interrupt

        

        TH0=0xff; //Timer 0 initial value FFH;

        TL0=0xff;

        ET0=1;

        TR0=1;        

        

        TH1=0xff; //Timer 1 initial value FFH;

        TL1=0xff;

        ET1=1;

        TR1=1;

           

        IT0=1; //Pulse mode

        EX0=1; //Open external interrupt 0: speed up

        IT1=1; //Pulse mode

        EX1=1; //Open external interrupt 1: deceleration

    

    inti_lcd();

    DoSpeed();       

    ShowState();

    while(1)

    { 

      clock(RunSpeed);

      P0_1=P0_1^0x01;

    }

    

}


//Timer 0 interrupt program: forward

void t_0(void) interrupt 1

{

        RunState=RIGHT_RUN;        

    P0_0=1;

    P1=0x01;

    cmd_wr();

    ShowState();



//Timer 1 interrupt: reverse

void t_1(void) interrupt 3

{

        RunState=LEFT_RUN;

    P0_0=0;

    P1=0x01;

    cmd_wr();

    ShowState();

   


//Interrupt 0: speed up the program

void SpeedUp() interrupt 0

{   

       if(RunSpeed>=12)

          RunSpeed=RunSpeed-2; 

       DoSpeed();

       P1=0x01;

       cmd_wr();

       ShowState();

              

}


//Interrupt 1: deceleration program

void SpeedDowm() interrupt 2

{   

    

    if(RunSpeed<=100)

        RunSpeed=RunSpeed+2; 

    DoSpeed();

    P1=0x01;

    cmd_wr();

    ShowState();

        


}


int delay() //Judge whether LCD is busy

{   

    int a;

start:

    

    RS=0;

    RW=1;

    E=0;

    for(a=0;a<2;a++);

    E=1;

    P1=0xff;

    if(P1_7==0)

       return 0;

    else        

       goto start;


}


void inti_lcd() //Set LCD mode

{


   P1=0x38;

   cmd_wr();

   delay();


   P1=0x01; //Clear

   cmd_wr();

   delay();


   P1=0x0f;

   cmd_wr();

   delay();


   P1=0x06;

   cmd_wr();

   delay(); 


   P1=0x0c;

   cmd_wr();

   delay();

}


void cmd_wr() //write control word

{

   RS=0;

   RW=0;

   E=0;

   E=1;

}


void show_lcd(int i) //LCD display subroutine

{  

   P1=i;

   RS=1;

   RW=0;

   E=0;

   E=1;


}


void ShowState() //Display status and speed

{

    int i=0;

    while(SpeedChar[i]!='')

    {

       delay();

       show_lcd(SpeedChar[i]);

       i++;

    }

    

    delay();

    P1=0x80 | 0x0d;

    cmd_wr();


    i=0;

    while(SPEED[i]!='')

    {

       delay();

       show_lcd(SPEED[i]);

       i++;

    }


    delay();

    P1=0xC0;

    cmd_wr();


    i=0;

    while(StateChar[i]!='')

    {

       delay();

       show_lcd(StateChar[i]);

       i++;

    }


    delay();

    P1=0xC0 | 0x0A;

    cmd_wr();


    i=0;

    if(RunState==RIGHT_RUN)

        while(STATE_CW[i]!='')

        {

          delay();

          show_lcd(STATE_CW[i]);

          i++;

        }

    else

       while(STATE_CCW[i]!='')

        {

          delay();

          show_lcd(STATE_CCW[i]);

          i++;

        }


}

void clock(unsigned int Delay) //1ms delay program

{ unsigned int i; 

   for(;Delay>0;Delay--) 

    for(i=0;i<124;i++); 

     

}


void DoSpeed()

{

    SPEED[0]=(1000*6/RunSpeed/100)+48;

    SPEED[1]=1000*6/RunSpeed%100/10+48;

    SPEED[2]=1000*6/RunSpeed%10+48;

}



Keywords:L297 Reference address:L297, L298 drive stepper motor schematic diagram proteus simulation + program LCD display speed

Previous article:Based on the internal EEPROM read and write interface function of STC15W408AS microcontroller
Next article:51 MCU driver for proximity switch

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号