MCS-51單片機(jī)驅(qū)動(dòng)步進(jìn)電機(jī)的程序設(shè)計(jì)
掃描二維碼
隨時(shí)隨地手機(jī)看文章
1.實(shí)驗(yàn)設(shè)計(jì)
定時(shí)器1于方式1,16位,10ms中斷一次
40H10ms計(jì)數(shù)單元
41H秒計(jì)數(shù)單元
42H分計(jì)數(shù)單元
43H時(shí)計(jì)數(shù)單元
定時(shí)方式1為10MS:THX=0ECH,TLX=78H
方式0為10MS: THX=63H,TLX=18H
步進(jìn)電機(jī)驅(qū)動(dòng)實(shí)驗(yàn)定時(shí)中斷程序
正轉(zhuǎn)后反轉(zhuǎn),顯示計(jì)數(shù)值
步進(jìn)電機(jī)按三相六拍的工作方式運(yùn)動(dòng)
X軸
CBA
P1.2 P1.1 P1.0
用鍵盤上方的發(fā)光二極管(3FH)對(duì)應(yīng)指示:
D2D1D0
正轉(zhuǎn):A-AB-B-BC-C-CA-A
反轉(zhuǎn):A-CA-C-BC-B-AB-A
2.參考程序
; 42H,41H為BCD碼計(jì)數(shù)單元
;內(nèi)存分配
TCTEREQU40H;10ms計(jì)數(shù)單元
CTCLEQU44H;進(jìn)給步數(shù)
CTCHEQU45H;最大9999步
STATEQU52H
SMOUTEQU55H
;位地址,工作標(biāo)志
XPEQU02H;X軸正反轉(zhuǎn)
XWEQU04H;工作標(biāo)志
;
DISPEQU0DE00H;顯示子程序入口
;
ORG0000H
START:AJMPMAIN
;
ORG000BH;定時(shí)器0中斷服
AJMPT0INT;務(wù)程序入口
;
ORG0030H
MAIN:MOVR0,#39H ;顯示緩沖區(qū)初始化
MAIN_0: MOV@R0,#0
INCR0
CJNER0,#44H,MAIN_0
MOVSTAT,#01
MOVSMOUT,#01H
MOVCTCL,#50H;150步
MOVCTCH,#01H
SETBXW
CLRXP
MOVTMOD,#01H
MOVIE,#10000010B
MOVTH0,#0ECH;10ms:EC78H
MOVTL0,#78H
SETBTR0
MAIN_1: JNBXW,MAIN_2
ACALLCONT;主程序循環(huán)
SJMPMAIN_1
MAIN_2: CLRTR0;關(guān)定時(shí)器
MAIN_3: LCALLDISP
SJMPMAIN_3
;
CONT:MOV3FH,SMOUT
LCALLDISP;控制程序
;MOVP1,SMOUT
RET
;
;定時(shí)器0中斷服務(wù)程序
T0INT:MOVTH0,#0ECH
MOVTL0,#78H
PUSHACC;保護(hù)現(xiàn)場(chǎng)
PUSHPSW
PUSH01H
INCTCTER
MOVA,TCTER
CJNEA,#50,T0INTR
MOVTCTER,#0
ACALLXPD0
ACALLCOUNT
T0INTR: POP01H
POPPSW;恢復(fù)現(xiàn)場(chǎng)
POPACC
RETI
COUNT:JBXP,COUNT0
MOVA,41H;個(gè)十單元
INCA
DAA
MOV41H,A
JNZCOUNT1
CLRC
MOVA,42H;百千單元
INCA
DAA
MOV42H,A
SJMPCOUNT1
COUNT0: MOVA,41H;個(gè)十單元
ADDA,#99H
DAA
MOV41H,A
CJNEA,#99H,COUNT2
MOVA,42H;百千單元
ADDA,#99H
DAA
MOV42H,A
SJMPCOUNT2
COUNT1: MOVA,42H
XRLA,CTCH
JNZTINT0
MOVA,41H
XRLA,CTCL
JNZTINT0
SETBXP
SJMPTINT0
COUNT2: MOVA,42H
JNZTINT0
MOVA,41H
JNZTINT0
CLRXW
;
TINT0:MOVA,41H;第一拆字
ANLA,#0FH
MOV39H,A
MOVA,41H
ANLA,#0F0H
SWAPA
MOV3AH,A
MOVA,42H;第二拆字
ANLA,#0FH
MOV3BH,A
MOVA,42H
ANLA,#0F0H
SWAPA
MOV3CH,A
MOV3DH,#10H;空格
JBXP,TINT1
MOV3EH,#0AH;正轉(zhuǎn)
RET
TINT1:MOV3EH,#0BH;反轉(zhuǎn)
RET
;步進(jìn)電機(jī)驅(qū)動(dòng)處理
XPD0:MOVR1,#STAT
JBXP,XPD1
INC@R1;正轉(zhuǎn)
CJNE@R1,#07H,XPD2
MOV@R1,#1
SJMPXPD2
XPD1:DEC@R1;反轉(zhuǎn)
CJNE@R1,#00H,XPD2
MOV@R1,#06
XPD2:MOVA,@R1
ADDA,#2
MOVCA,@A+PC
MOVSMOUT,A
RET
SM_TAB: DB03H,01H,05H
DB04H,06H,02H