?? astep.c
字號:
/*“驗證式” 實驗十九??步進電控制機 */
#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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -