Stepper motor forward and reverse adjustable speed

Publisher:科技先锋Latest update time:2016-09-08 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
//Stepper motor forward and reverse adjustable speed

//=================================
//P3^0; forward and reverse
//P3^1; speed increase
//P3^2;
deceleration //P3^3; stop

#include
#define uint unsigned int 
#define uchar unsigned char
sbit rl=P3^0;//forward and reverse
sbit add=P3^1;//speed increase
sbit sub=P3^2;//deceleration
sbit stop=P3^3;//stop
uchar num1,num2,flag1,flag2,flag3,n;
uchar code table1[]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};//forward table
uchar code table2[]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};//reversal table
  //motor rotation table
void delay(uint z);
void keyscan();
void main()
{ uchar i;
     n=50;
    TMOD=0x01;
      TH0=(65536-10000)/256;
     TL0=(65536-10000)%256;
     ET0=1;
     EA=1;
     TR0=1;
 while(1)
     {
       keyscan();
      if(!flag3)
      { if(flag1==1)
  {flag1=0;
          if(flag2==0)
         P1=table1[i];
           else
           {P1=0;
           P1=table2[i];}
     i++;
         if(i>8)
           i=0;
        }
    }
 }
   

}
//========================
void delay(uint z)
{
   uint x;
   uchar y;
 for(x=0;x  for(y=0;y<100;y++);
}
//====================
void timer0() interrupt 1
{   
  TH0=(65536- 10000)/256;
     TL0=(65536-10000)%256;
        num1++;
       if(num1==n)
       {num1=0;flag1=1;}
     
}

//================
void keyscan()
{
 if(rl==0)
     delay(10);
 if(rl==0)
      {
  while(!rl);
       flag2++ ;
        flag3=0;
        if(flag2>1)
   flag2=0;
   }
   if(add==0)
      delay(10);
    if(add==0)
      {
  while(!add);
        n=n++;
  if(n> 80)
  n=80;
   }
 if(sub==0)
      delay(10);
    if(sub==0)
      {
  while(!sub);
        n=n--;
  if(n<10)
  n=10;
   }
 if(stop==0)
      delay(10);
    if(stop==0)
      {
  while(!stop);
        P1=0;
        flag3=1;
   }
}

Reference address:Stepper motor forward and reverse adjustable speed

Previous article:DC motor forward and reverse rotation and speed control
Next article:Digital clock program for 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号