当前位置 - 股票行情交易網 - 裝修設計 - 51單片機匯編語言編程獨立按鍵

51單片機匯編語言編程獨立按鍵

四個按鍵,定義如下:

KEY1 BIT P3.0

KEY2 BIT P3.1

KEY3 BIT P3.2

KEY4 BIT P3.3

按鍵處理程序:

;-----------------------------------

READ_KEY:

JB KEY1, K2

CALL DELAY

JB KEY1, K2

JNB KEY1, $

PUSH ACC

INC 75H

MOV A, 75H

CJNE A, #10, ZINT01

MOV 75H, #0

ZINT01:

POP ACC

JMP K_EXIT

;---------------

K2: JB KEY2, K3

CALL DELAY

JB KEY2, K3

JNB KEY2, $

PUSH ACC

INC 76H

MOV A, 76H

CJNE A, #10, ZINT01

MOV 76H, #0

ZINT01:

POP ACC

JMP K_EXIT

;---------------

K3: JB KEY3, K4

CALL DELAY

JB KEY3, K4

JNB KEY3, $

PUSH ACC

DEC 75H

MOV A, 75H

CJNE A, #255, ZINT03

MOV 75H, #9

ZINT03:

POP ACC

JMP K_EXIT

;---------------

K4: JB KEY4, K_EXIT

CALL DELAY

JB KEY4, 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

;-----------------------------------