51單片機(jī)驅(qū)動(dòng)步進(jìn)電機(jī)電路及程序
START:
MOV R0,#00H
START1:
MOV P2,#00H
MOV A,R0
MOV DPTR,#TABLE
MOVC A,@A+DPTR
JZ START 對(duì) A 的判斷,當(dāng) A = 0 時(shí)則轉(zhuǎn)到 START
MOV P2,A
LCALL DELAY
INC R0
DJNZ R3,START1
MOV P2,#00H
LCALL DELAY1
;-----------------------------反轉(zhuǎn)------------------------
MOV R3,#144 反轉(zhuǎn)一圈共 144 個(gè)脈沖
START2:
MOV P2,#00H
MOV R0,#05
START3:
MOV A,R0
MOV DPTR,#TABLE
MOVC A,@A+DPTR
JZ START2
MOV P2,A
CALL DELAY
INC R0
DJNZ R3,START3
MOV P2,#00H
LCALL DELAY1
LJMP MAIN
DELAY: MOV R7,#40 步進(jìn)電機(jī)的轉(zhuǎn)速
M3: MOV R6,#248
DJNZ R6,$
DJNZ R7,M3
RET
DELAY1: MOV R4,#20 2S 延時(shí)子程序
DEL2: MOV R3,#200
DEL3: MOV R2,#250
DJNZ R2,$
DJNZ R3,DEL3
DJNZ R4,DEL2
RET
TABLE:
DB 30H,60H,0C0H,90H 正轉(zhuǎn)表
DB 00 正轉(zhuǎn)結(jié)束
DB 30H,90H,0C0H,60H 反轉(zhuǎn)表
DB 00 反轉(zhuǎn)結(jié)束
END
DIY機(jī)械鍵盤相關(guān)社區(qū):機(jī)械鍵盤DIY
評(píng)論