astep.c

来自「3000TB51配套实验例程 1八段数码管显示实验 等」· C语言 代码 · 共 102 行

C
102
字号
/*“验证式”   实验十九??步进电控制机   */

#include <reg51.h>
#define Astep 0x01
#define Bstep 0x02
#define Cstep 0x04
#define Dstep 0x08

unsigned char dly_c;

void delay()
{
   unsigned char tt,cc;

   cc = dly_c;
   tt = 0x0;
   do{
     do {
     }while(--tt);
   }while(--cc);
}

void main()
{
   unsigned char state=1,count=0;
   int n=0;



   dly_c = 170;

   /* 单/双八拍工作方式 */



   /* 双四拍工作方式 */
   while(n++!=75)
   {
      P1 = Astep+Bstep;
      delay();
      P1 = Bstep+Cstep;
      delay();
      P1 = Cstep+Dstep;
      delay();
      P1 = Dstep+Astep;
      delay();
      if(dly_c>20&&state==1)
        dly_c-=6;
      if(dly_c==20&&count<25)
         {
          state=2;
          count++;
         }
      if(state==2&&count==25)
          {
           state=3;
           count=0;
          }
      if(state==3&&dly_c<170)
           dly_c+=6;
      if(state==3&&dly_c==170)
          state=1;

   }
   //for(k=0;k<40;k++)
 //  delay();
/* 单四拍工作方式 */
   while(n--!=0)
   {  P1 = Dstep+Astep;
      P1=P1|0x80;
      delay();
      P1 = Cstep+Dstep;
      P1=P1|0x80;
      delay();
      P1 = Bstep+Cstep;
      P1=P1|0x80;
      delay();
      P1 = Astep+Bstep;
      P1=P1|0x80;
      delay();
      if(dly_c>20&&state==1)
        dly_c-=6;
      if(dly_c==20&&count<25)
         {
          state=2;
          count++;
         }
      if(state==2&&count==25)
          {
           state=3;
           count=0;
          }
      if(state==3&&dly_c<170)
           dly_c+=6;
      if(state==3&&dly_c==170)
          state=1;
   }


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?