;*************************************************************
; 步进电机长度切割控制程序汇编语言清单
;*************************************************************
;主要硬件:2相六线/24V/3A步进、电磁阀1个,传感器2个。BCD拨盘1位
;Create by : Sidney http://www.mcusy.cn
;*************************************************************
Counter EQU 30H ;计数器
RELAY EQU P0.7 ;电磁阀
BELL EQU P0.4 ;蜂鸣器
GOTO EQU P0.0 ;启动开关
REST EQU P0.1 ;停止开关
ORG 0000H
;----------------------开机设置/运行准备---------------------
MIAN:
MOV SP,#60H
MOV P0,#6FH
MOV P2,#0FFH
MOV P1,#0FH
MOV R3,#250
TT1:
ACALL DEBOUNCE ;防抖动
DJNZ R3,TT1 ;稍作延时
SETB BELL ;蜂鸣器响一声
MOV R3,#30
TT2:
ACALL DEBOUNCE
DJNZ R3,TT2
CLR BELL ;蜂鸣器关
;---------------------------读取BCD码-------------------------
LOOP:
MOV Counter,#00H ;计数器清零
MOV A,#0H ;累加器清零
NOP
NOP
MOV A,P1 ;累加器读取P1(BCD码)
ANL A,#0FH ;
DA A ;十进制调整
MOV DPTR,#DISPTAB
MOVC A,@A+DPTR
MOV Counter,A
jnb GOTO,x1
NOP
NOP
NOP
Ljmp LOOP
;------------------步进电机控制/功能开关检测------------------
X1:
ACALL DEBOUNCE
JNB GOTO,X1
ACALL DEBOUNCE
JB P0.3,Warning
X2:
mov r3,Counter
start:mov r0,#00h
start1:
mov p2,#0ffh
mov a,r0
mov dptr,#table
movc a,@a+dptr
jz start
cpl a
mov p2,a
call delay
inc r0
JNB REST,OFF
djnz r3,start1
mov p2,#0ffh
LOOP2:
MOV R3,#30
YY2:
ACALL DEBOUNCE
DJNZ R3,YY2
SETB RELAY
GRTT:
ACALL DEBOUNCE
JNB P0.2,WER
ACALL DEBOUNCE
JNB REST,OFF
NOP
NOP
NOP
AJMP GRTT
WER:
ACALL DEBOUNCE
JB P0.2,$
ACALL Del300MS
CLR RELAY
YYH:
ACALL DEBOUNCE
JNB REST,OFF
JNB P0.3,LOOP3
NOP
NOP
NOP
AJMP YYH
LOOP3:
NOP
NOP
NOP
AJMP X2
;--------------------------异常处理程序-----------------------
OFF:
ACALL DEBOUNCE
JB REST,OFF
NOP
NOP
NOP
AJMP MIAN
Warning:
SETB BELL
JB REST,$
NOP
NOP
NOP
AJMP MIAN
;-------------------------10MS的防抖动------------------------
DEBOUNCE:
MOV R7,#25
F1: MOV R6,#200
DJNZ R6,$
DJNZ R7,F1
RET
;----------------------------速度值---------------------------
delay:mov r5,#40
d1: mov r6,#10
d2: mov r7,#10
djnz r7,$
djnz r6,d2
djnz r5,d1
ret
;------------------------电磁阀延迟(切刀)----------------------
Del300MS:
mov r5,#15
del0: mov r6,#60
del1: mov r7,#60
djnz r7,$
djnz r6,del1
djnz r5,del0
RET
;---------------------------步进数值表--------------------------
DISPTAB:
DB 84,85,86,87,88,89,90,91,92,93 ;15.1mm
;DB 72,73,75,76,77,78,79,80,81,82 ;12.9MM
table:
db 03h,09h,0ch,06h ;+ (一步)
DB 00
END