- KEY EQU P1 ;
- SQ EQU P0 ;
- FLAG BIT 2AH.0 ;走动标志
- DLY BIT 2AH.1 ;延时5秒起动标志
- FLAG_DLY BIT 2AH.2 ;延时5秒标志
- FLAG_STOP BIT 2AH.3 ;急停标志
- FLAG_PRO BIT 2AH.4 ;禁止按键标志
- FLAG_DANBU BIT 2AH.5 ;单步操作标志
- ORG 0000H
- AJMP INIT
- ORG 000BH
- AJMP TIME0
- ORG 0030H
- INIT:
- MOV SP,#30H
- MOV SCON,#0H
- MOV TMOD,#01H
- MOV TH0,#03CH
- MOV TL0,#0B0H
- MOV R4,#0
- MOV R5,#2 ;上下循环两次
- MOV R7,#2 ;
- MOV 50H,#0 ;
- MOV 52H,#0 ;
- //SETB FLAG
- SETB EA
- SETB ET0
- SETB TR0
- ACALL DISPLAY ;
- CLR P2.0
- ////////////////////////////////////
- MAIN:
- JB FLAG,GO1SET ;启动转,否则下一步
- MOV R5,#1
- CLR FLAG_PRO ;取消按键禁止
- CJNE R4,#1,GOA ;对比跳转相应工序
- AJMP GO1
- GOA:
- CJNE R4,#2,GOB
- AJMP GO2
- GOB:
- CJNE R4,#3,GOC
- AJMP GO3
- GOC:
- CJNE R4,#4,GOD
- AJMP GO4
- GOD:
- SJMP MAIN
- GO1SET:
- MOV P2,#0FEH ;启动前清除指示
- MOV R5,#2 ;两次上下
- GO1:
- MOV R4,#0 ;清0防止指标混乱
- ACALL DELYS
- //ACALL DELYS
- CLR P2.0 ;下降
- JB FLAG_STOP,$ ;急停
- ACALL DELYS
- //ACALL DELYS
- CLR P2.4
- JB FLAG_STOP,$
- ACALL DELYS
- //ACALL DELYS
- CLR P2.5
- JB FLAG_STOP,$
- ACALL DELYS
- //ACALL DELYS
- CLR P2.6
- JB FLAG_STOP,$
- JB FLAG_DANBU,MAIN;单步停止
- JB SQ.2,$ ;限位
- GO2:
- MOV R4,#0
- ACALL DELYS
- ACALL DELYS
- SETB P2.6 ;上升
- JB FLAG_STOP,$
- ACALL DELYS
- //ACALL DELYS
- SETB P2.5
- JB FLAG_STOP,$
- ACALL DELYS
- //ACALL DELYS
- SETB P2.4
- JB FLAG_STOP,$
- ACALL DELYS
- //ACALL DELYS
- //SETB P2.0
- JB FLAG_STOP,$
- JB FLAG_DANBU,MAIN
- JB SQ.1,$
- DJNZ R5,GO1
- GO3:
- MOV R4,#0
- CLR P2.0 ;右移
- JB FLAG_STOP,$
- ACALL DELYS
- //ACALL DELYS
- CLR P2.1
- JB FLAG_STOP,$
- ACALL DELYS
- //ACALL DELYS
- CLR P2.2
- JB FLAG_STOP,$
- ACALL DELYS
- //ACALL DELYS
- CLR P2.3
- JB FLAG_STOP,$
- JB FLAG_DANBU,NEXT
- JB SQ.3,$
- SETB DLY ;延时5S
- JNB FLAG_DLY,$
- CLR FLAG_DLY
- CLR DLY
- GO4:
- MOV R4,#0
- ACALL DELYS
- //ACALL DELYS
- SETB P2.3 ;左移
- JB FLAG_STOP,$
- ACALL DELYS
- //ACALL DELYS
- SETB P2.2
- JB FLAG_STOP,$
- ACALL DELYS
- //ACALL DELYS
- SETB P2.1
- JB FLAG_STOP,$
- ACALL DELYS
- //ACALL DELYS
- //SETB P2.0
- JB FLAG_STOP,$
- JB FLAG_DANBU,NEXT
- JB SQ.4,$
- INC R3 ;计步器
- ACALL DISPLAY ;显示
- NEXT:
- AJMP MAIN
- /////////////////////////////////////////
- K1: ;
- JNB KEY.0,K1A;检测P0.0口
- AJMP K2
- K1A:
- ACALL DELY ;延时去抖
- JNB KEY.0,K1B;检测P0.0口
- AJMP K2
- K1B:
- JNB KEY.0,K1B;等待按键
- JB FLAG,K2
- JB FLAG_PRO,K2
- MOV P2,#0EH
- MOV R4,#2
- MOV R5,#1
- SETB FLAG_DANBU
- RET
- K2: ;
- JNB KEY.1,K2A
- AJMP K3
- K2A:
- ACALL DELY
- JNB KEY.1,K2B
- AJMP K3
- K2B:
- JNB KEY.1,K2B
- JB FLAG,K3
- JB FLAG_PRO,K3
- MOV P2,#0FEH
- MOV R4,#1
- MOV R5,#1
- SETB FLAG_DANBU
- RET
- K3: ;
- JNB KEY.2,K3A
- AJMP K4
- K3A:
- ACALL DELY
- JNB KEY.2,K3B
- AJMP K4
- K3B:
- JNB KEY.2,K3B
- JB FLAG,K4
- JB FLAG_PRO,K4
- MOV P2,#0F0H
- MOV R4,#4
- MOV R5,#1
- SETB FLAG_DANBU
- RET
- K4:
- JNB KEY.3,K4A
- AJMP K5
- K4A:
- ACALL DELY
- JNB KEY.3,K4B
- AJMP K5
- K4B:
- JNB KEY.3,K4B
- JB FLAG,K5
- JB FLAG_PRO,K5
- MOV P2,#0FEH
- MOV R4,#3
- MOV R5,#1
- SETB FLAG_DANBU
- RET
- K5:
- JNB KEY.4,K5A
- AJMP K6
- K5A:
- ACALL DELY
- JNB KEY.4,K5B
- AJMP K6
- K5B:
- JNB KEY.4,K5B
- SETB FLAG ;启动
- SETB FLAG_PRO ;禁止按键作用
- CLR FLAG_STOP ;取消急停
- CLR FLAG_DANBU;取消单步
- RET
- K6:
- JNB KEY.5,K6A
- AJMP K7
- K6A:
- ACALL DELY
- JNB KEY.5,K6B
- AJMP K7
- K6B:
- JNB KEY.5,K6B
- CLR FLAG ;停止运行
- //SETB FLAG_PRO
- RET
- K7:
- JNB KEY.6,K7A
- RET
- K7A:
- ACALL DELY
- JNB KEY.6,K7B
- RET
- K7B:
- JNB KEY.6,K7B
- SETB FLAG_STOP ;急停
- RET
- DELY:MOV R7,#10 ;延时0.5ms
- DLY0:MOV R6,#50
- DLY1:DJNZ R6,DLY1
- DJNZ R7,DLY0
- RET
- DELYS:MOV R7,#255 ;延时
- DLY2:MOV R6,#255
- DLY3:DJNZ R6,DLY3
- DJNZ R7,DLY2
- RET
- DISPLAY: ;显示
- MOV R7,#2 ;数码管位数
- MOV A,R3
- MOV B,#10
- DIV AB
- MOV 51H,A
- MOV 50H,B
- MOV DPTR,#TABLE
- MOV R0,#50H
- LED1:
- MOV A,@R0
- MOVC A,@A+DPTR //查表得段码
- MOV SBUF,A
- STOP:JNB TI,STOP
- CLR TI
- INC R0
- DJNZ R7,LED1
- RET
- TIME0: ;延时2S
- MOV TH0,#03CH
- MOV TL0,#0B0H
- ACALL K1
- JNB DLY,EXIT
- INC R2
- CJNE R2,#75,EXIT ;5秒
- SETB FLAG_DLY
- MOV R2,#0
- EXIT:
- RETI
- TABLE:
- DB 3fh,06h,5bh,4fh
- DB 66h,6dh,7dh,07h
- DB 7fh,6fh,77h,7ch
- DB 39h,5eh,79h,71h
- END
复制代码
|