控制步進(jìn)電機(jī)正反轉(zhuǎn)的實(shí)際應(yīng)用程序
calldog;
calltime(200);
calldog;
callwrenable;/*置存儲器寫使能*/
addrl=00h;/*置存儲器地址*/
dat=l(1);
callwbyte;/*將變量L(1)的值寫入存儲器00h位置*/
callwrenable;
addrl=01h;
dat=l(2);
callwbyte;/*將變量L(2)的值寫入存儲器01h位置*/
end;
endincdata;
decdata:PROCEDURE;/*參數(shù)修改---"減"鍵處理子程序-*/
IFp11=0THEN/*k8鍵處理子程序*/
do;
dowhilep11=0;
calldog;
end;
DATA=DATA-1;/*設(shè)定值-1*/
ifdata=0thendata=99;
L(1)=dataMOD10;
L(2)=data/10;
calldisplay(l(1),l(2));
calldog;
calltime(200);
calldog;
calltime(200);
calldog;
callwrenable;
addrl=00h;
dat=l(1);
callwbyte;
callwrenable;
addrl=01h;
dat=l(2);
callwbyte;
end;
ENDdecdata;
starton:PROCEDURE;/*start*/
declaresdbyte;
ifp12=0THEN/*K9鍵處理子程序*/
do;
dowhilep12=0;
calldog;
end;
ifp17=0thenok=0;/*如果p17口線上有信號輸入,則運(yùn)行標(biāo)志置0(停止運(yùn)行)*/
p13=1;/*置步進(jìn)電機(jī)正向運(yùn)轉(zhuǎn)*/
calltime(200);
calldog;
dowhileok=1;/*當(dāng)運(yùn)行標(biāo)志為1時(shí),執(zhí)行速度延時(shí)操作*/
dosd=0todata;/*根據(jù)設(shè)定值data的數(shù)值延時(shí)來確定步進(jìn)電機(jī)運(yùn)行時(shí)的脈沖給定速度*/
calldog;
end;
end;
ENDstarton;
step:PROCEDURE;/*step*/
declaresdbyte;
p13=1;/*置步進(jìn)電機(jī)正向運(yùn)轉(zhuǎn)*/
calltime(200);
calldog;
IFp33=0THEN/*k11鍵處理子程序*/
do;
ifp17=0thenok=0;/*如果p17上有信號輸入,則停止運(yùn)行*/
dowhilep33=0;
dosd=0todata;/*調(diào)用延時(shí),調(diào)整步進(jìn)電機(jī)的運(yùn)行速度*/
calldog;
calltime(2);
end;
callrun;
calldog;
end;
end;
ok=0;
ENDstep;
back:PROCEDURE;/*反向運(yùn)行處理子程序*/
declaresdbyte;
IFp34=0THEN
do;
dowhilep34=0;
calldog;
end;
ifp15=0thenok=0;/*反向運(yùn)行時(shí),如果遇到p15上有信號輸入,則停止步進(jìn)電機(jī)運(yùn)行*/
p13=0;/*置步進(jìn)電機(jī)反向運(yùn)行*/
calltime(200);
calldog;
dowhileok=1;
dosd=0todata;/*根據(jù)設(shè)定值調(diào)節(jié)步進(jìn)電機(jī)的運(yùn)行速度*/
calldog;
calltime(2);
end;
callrun;
if(p15=0orp32=0)thenok=0;/*p15或p32口線任意一個(gè)有信號輸入,停止運(yùn)行*/
end;
end;
ENDback;
MAIN$PROGRAM:/*初始化主程序*/
ea=0;/*關(guān)中斷*/
SCON=00h;/*置串口方式0,串行數(shù)據(jù)輸出模式*/
PCON=00h;
tmod=11h;
et0=1;
enable;/*開中斷(ea=1)*/
SCK=0;cs=1;/*定義存儲器口線初始狀態(tài)*/
callwrenable;
callwrregister;/*看門狗存儲器初始化*/
callwrenable;
calldog;
p2=0ffh;/*初始化各個(gè)口線的狀態(tài)*/
p1=0ffh;ok=0;
p14=1;p32=1;p33=1;p34=1;
p13=1;
ADDRL=00h;/*上電復(fù)位后從存儲器中讀出設(shè)定的速度值*/
CALLrbyte;
l(1)=dat;
addrl=01h;
callrbyte;
l(2)=dat;
DATA=L(1)+L(2)*10;/*將讀出的值合并成十進(jìn)制,存入變量data中*/
/*以下是主循環(huán)程序*/
LOOP:
IFp10=0THENCALLincdata;/*檢測各個(gè)按鍵是否有按下*/
IFp11=0THENCALLdecdata;
ifp12=0then
do;
ok=1;
callstarton;
end;
ifp34=0then
do;
ok=1;
callback;
end;
ifp33=0then
do;
ok=1;
callstep;
end;
calldog;
CALLDISPLAY(L(1),L(2));/*將設(shè)定值送164顯示*/
calldog;
CALLTIME(100);
calldog;
GOTOLOOP;
ENDSTART;
光耦相關(guān)文章:光耦原理
存儲器相關(guān)文章:存儲器原理
脈沖點(diǎn)火器相關(guān)文章:脈沖點(diǎn)火器原理
評論