基于51单片机的两相四线步进电机程序编制
- 格式:doc
- 大小:46.50 KB
- 文档页数:3
org 0000h
mov r5,#30
mov r0,#00h
MOV R1,#05H
main: jnb P1.0,right
jnb p1.1,left
jnb p1.2,up
jnb p1.3,down
mov a,r0
mov dptr,#table
movc A,@A+DPTR
jz tttt
mov P3,a
lcall delay
inc r0
LCALL SHOW
Ljmp main
SHOW: MOV P0,#0FFH
MOV P2,#0FFH
MOV P2,#02H
MOV A,R1
movc A,@A+DPTR
MOV P0,A
LCALL DELAY
INC R1
MOV P0,#0FFH
MOV P2,#0FFH
MOV P2,#01H
MOV A,R1
movc A,@A+DPTR
MOV P0,A
DEC R1
RET
tttt :dec r0
dec r0
dec r0
dec r0
ljmp main
delay:mov a,r5
mov r4,a
d0: mov r7,#1
del: mov r6,#250
djnz r6,$
djnz r7,del
djnz r4,d0
ret
right:mov r5,#30
mov r0,#00h
MOV R1,#05H
MOV R2,#00H
JNB P1.0,$
Ljmp main
left: mov r5,#30
mov r0,#0Bh
MOV R1,#10H
MOV R2,#0BH
JNB P1.1,$
Ljmp main
up: mov r5,#20
MOV A,R2
ADD A,#07H
MOV R1,A
JNB P1.2,$
Ljmp main
down: mov r5,#50
MOV A,R2
ADD A,#09H
MOV R1,A
JNB P1.3,$
Ljmp main
table:db 03h,09h,0ch,06h ;正转表1100 1001 0011 0110 db 00h ;正转结束
DB 88H,0C0H
DB 88H,0C1H
DB 88H,0C8H
db 06h,0ch,09h,03h ;反转
db 00h ;反转结束
DB 0C7H,0C0H
DB 0C7H,0C1H
DB 0C7H,0C8H
end