KEY1 BIT P3.0
KEY2 BIT P3.1
KEY3 BIT P3.2
KEY4 BIT P3.3
按键处理程轿简序:薯帆春
-----------------------------------
READ_KEY:
JBKEY1, K2
CALL DELAY
JBKEY1, K2
JNB KEY1, $
PUSH ACC
INC 75H
MOV A, 75H
CJNE A, #10, ZINT01
MOV 75H, #0
ZINT01:
POP ACC
JMP K_EXIT
---------------
K2: JBKEY2, K3
CALL DELAY
JBKEY2, K3
JNB KEY2, $
PUSH ACC
INC 76H
MOV A, 76H
CJNE A, #10, ZINT01
MOV 76H, #0
ZINT01:
POP ACC
JMP K_EXIT
---------------
K3: JBKEY3, K4
CALL DELAY
JBKEY3, K4
JNB KEY3, $
PUSH ACC
DEC 75H
MOV A, 75H
CJNE A, #255, ZINT03
MOV 75H, #9
ZINT03:
POP ACC
JMP K_EXIT
---------------
K4: JBKEY4, K_EXIT
CALL DELAY
JBKEY4, K_EXIT
JNB KEY4, $
PUSH ACC
DEC 76H
MOV A, 76H
CJNE A, #255, ZINT04
MOV 76H, #9
ZINT04:
POP ACC
K_EXIT:
RET
---------------
DELAY:
DJNZ R7, $
DJNZ R7, $
RET
-----------------------------------
这个图无法编程的,以下以51单片机为例编程给你参考:LED BIT P1.0
KEY BIT P1.4
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0ISR
ORG 0030H
MAIN:
MOV TMOD,#01H
MOV TH0,#HIGH(65536-50000)
MOV TL0,#LOW(65536-50000)
SETB ET0
SETB EA
CLR A
LOOP:
JB KEY,LOOP
JNB KEY,$
INC A
CJNE A,#1,LOOP1
CLR LED
SJMP LOOP
LOOP1:
CJNE A,#2,LOOP2
SETB TR0
MOV 清销R2,#10
SJMP LOOP
LOOP3:
CJNE A,#3,LOOP
CLR A
CLR TR0
袭孙 SETB LED
SJMP LOOP
T0ISR:
CLR TR0
MOV TH0,#HIGH(65536-50000)
MOV TL0,#LOW(65536-50000)
拍正链 SETB TR0
DJNZ R2,T0E
MOV R2,#10
CPL LED
T0E:
RETI
END
第一次按者并下,LED亮,抬起后再次按下,LED灭,旅贺依次循环?约定拆嫌派低有效
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0ISR
ORG 0030H
MAIN:
MOV SP,#5FH
MOV TMOD,#01H
MOV TH0,#HIGH(65536-50000)
MOV TL0,#LOW(65536-50000)
SETB ET0
SETB EA
MOV 20H,#0
LOOP:
MOV A,P2
JB ACC.0,LP1
JB 00H,LP01
CLR P1.0
SETB 00H
SJMP LOOP
LP01:
SETB P1.0
CLR 00H
SJMP LOOP
LP1:
JB ACC.1,LP2
JB 01H,LP11
CLR P1.1
SETB 01H
SJMP LOOP
LP11:
SETB P1.1
CLR 01H
SJMP LOOP
LP2:
JB ACC.2,LP3
JB 02H,LP21
CLR P1.2
SETB 02H
SJMP LOOP
LP21:
SETB P1.2
CLR 02H
SJMP LOOP
LP3:
JB ACC.3,LP3
JB 03H,LP31
CLR P1.3
SETB 03H
SJMP LOOP
LP31:
SETB P1.3
CLR 03H
SJMP LOOP
LP4:
JB ACC.4,LP3
JB 04H,LP41
CLR P1.4
SETB 04H
SJMP LOOP
LP41:
SETB P1.4
CLR 04H
SJMP LOOP
LP5:
JB ACC.5,LP3
JB 05H,LP51
CLR P1.5
SETB 05H
SJMP LOOP
LP51:
SETB P1.5
CLR 05H
SJMP LOOP
LP6:
JB ACC.6,LP3
JB 06H,LP61
MOV R2,#0
SETB TR0
SETB 06H
SJMP LOOP
LP61:
SETB P1.6
CLR 06H
CLR TR0
SJMP LOOP
LP7:
JB ACC.7,LOOP
JB 07H,LP71
MOV R2,#0
SETB TR0
SETB 07H
LJMP LOOP
LP71:
SETB P1.7
CLR TR0
CLR 07H
LJMP LOOP
T0ISR:
CLR TR0
MOV TH0,#HIGH(65536-50000)
MOV TL0,#LOW(65536-50000)
SETB TR0
INC R2
MOV A,R2
CJNE A,#20,T01
T01:
JC T0E
MOV R2,#0
JNB 06H,T02
CPL P1.6
SJMP T0E
T02: JNB 07H,T0E
CPL P1.7
T0E:
RETI
END
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)