Home > other >  Control 4 x4 matrix keyboard with 51 assembly language implementation of the dynamic display of the
Control 4 x4 matrix keyboard with 51 assembly language implementation of the dynamic display of the

Time:11-03

Myself assembly language small white, 9 weeks learning assembly language, be want to excuse me everybody study 51 assembly language students, I want to achieve with 4 x4 matrix keyboard to achieve control of the eight digital tube dynamic, just like the kind of phone call plate at ordinary times, also can use a key to realize a reduction operation,
Below is I compiled a program to implement control matrix keyboard input, the eight dynamic digital input a number shows a number, enter the number two, shows two Numbers,
DAT EQU P2/mouth/digital tube data
ORG 0000 h
LJMP MAIN
ORG 0030 h
MAIN:
MOV SP, # 60 h//set up the stack address
MOV R4, # 00 h//R4 for input counter
MOV R0, # 50 h//R0 used to store data segment address

START:
LCALL KEYSCAN//call button scanning
LCALL STORAGE//STORAGE period of
SHOW: LCALL SCAN1
MOV DPTR, # JPTAB
MOV A, R4
DEC A
JMP @ A + DPTR
JPTAB: LJMP KP1
LJMP KP2




KP1: MOV DAT, 50 h
MOV P1, # 80 h
LCALL DELAY250MS
LJMP SHOW
KP2: MOV DAT, 51 h
MOV P1, # 80 h
LCALL DELAY250MS
MOV DAT, 50 h
MOV P1, # 40 h
LCALL DELAY250MS
LJMP SHOW


KEYSCAN://button scanning function
MOV P3, # 0 fh//key input state four high output low four input
MOV A, P3
ANL A, # 0 fh
CJNE A, # 0 fh, SCAN
SJMP KEYSCAN
RET
SCAN:
MOV R1, # 0 efh
MOV R2, # 4 h
MOV R3, # 00 h
KEY1: MOV A, R1
MOV P3, A
RL A
MOV R1, A
MOV A, P3
ANL A, # 0 fh
CJNE A, # 0 fh, DEG
INC R3
DJNZ R2, KEY1
EXIT: MOV A, # 0 FFH
SJMP DONE

DEG: JB ACC. 0, JH1
MOV. A, # 00 h
AJMP JH
JH1: JB ACC. 1, JH2
MOV. A, # 4 h
AJMP JH
JH2: JB ACC. 2, JH3
MOV A, # 8 h
AJMP JH
JH3: JB ACC. 3, the DONE
MOV A, # 0 ch
JH: ADD A, R3
MOV R2, A//R2 for storing keys
INC R4

STORAGE: # MOV DPTR, DUANMA//clock
MOV A, R2//store scan keys
MOVC A, @ A + DPTR
CPL A
MOV @ R0, A
INC R0
DONE: RET

SCAN1: MOV P3, # 0 fh//key input state four high output low four input
MOV A, P3
ANL A, # 0 fh
CJNE A, # 0 fh, Y1
RET
Y1: LCALL SCAN
LCALL STORAGE
RET


DELAY1MS://delay a millisecond
MOV R4, # 250//R4 used
D1: NOP
The NOP
DJNZ R4, D1
RET
DELAY250MS:
MOV R5, # 250
D2: MOV R4, # 250//R4 used
D3: NOP
The NOP
DJNZ R4, D3
DJNZ R5, D2
RET



DUANMA:
X5b x3f DB 0, 0 x06, 0, 0 x4f, 0 x66, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f, 0 x77, 0 x7c, 0 x39, 0 x5e, 0 x79, 0 x71; Yin segment code 0123456789 abcdef
END

Proteus circuit diagram
  • Related