本帖最后由 xyyujn 于 2013-8-18 13:22 编辑
原理图如下:
C:\Documents and Settings\Administrator\桌面 C:\Documents and Settings\Administrator\桌面
程序是利用扫描法实现当按下0~15号键时,在数码管上显示出0~15
本来是个求助帖,后来,我自己改好了。现在把代码贴出来,欢迎高手批评指教,由于调试的原因,行号有点乱,多多包涵。
ORG 0000H
DULA EQU P2.6
WELA EQU P2.7
TEMP EQU R2
KEY EQU R3
MAIN: SETB DULA
MOV P0,#00H
CLR DULA
MOV P0,#0FFH
SETB WELA
MOV P0,#0C0H
CLR WELA
L0: ACALL KEYSCAN
LJMP L0
DELAY: MOV R0,#100
D1: MOV R1,#50
D2: DJNZ R1,D2
DJNZ R0,D1
RET
DISPLAY:MOV A,KEY
MOV DPTR,#TAB
MOVC A,@A+DPTR
SETB DULA
MOV P0,A
CLR DULA
RET
KEYSCAN:MOV P3,#0FEH
L1: MOV P3,#0FEH
L2: MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
CJNE TEMP,#0F0H,L3
LJMP L11
L3: ACALL DELAY
MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
CJNE TEMP,#0F0H,L4
SJMP L2
L4: MOV TEMP,P3
CJNE TEMP,#0EEH,L8
MOV KEY,#0
SJMP L7
L8: CJNE TEMP,#0DEH,L9
MOV KEY,#1
SJMP L7
L9: CJNE TEMP,#0BEH,L10
MOV KEY,#2
SJMP L7
L10: CJNE TEMP,#7EH,L5
MOV KEY,#3
SJMP L7
L5: CJNE TEMP,#0F0H,L6
L7: ACALL DISPLAY
L6: MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
L11: MOV P3,#0FDH
L12: MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
CJNE TEMP,#0F0H,L13
LJMP L21
L13: ACALL DELAY
MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
CJNE TEMP,#0F0H,L14
SJMP L12
L14: MOV TEMP,P3
CJNE TEMP,#0EDH,L18
MOV KEY,#4
SJMP L17
L18: CJNE TEMP,#0DDH,L19
MOV KEY,#5
SJMP L17
L19: CJNE TEMP,#0BDH,L20
MOV KEY,#6
SJMP L17
L20: CJNE TEMP,#7DH,L14
MOV KEY,#7
SJMP L17
CJNE TEMP,#0F0H,L16
L17: ACALL DISPLAY
L16: MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
L21: MOV P3,#0FBH
L22: MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
CJNE TEMP,#0F0H,L23
LJMP L31
L23: ACALL DELAY
MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
CJNE TEMP,#0F0H,L24
SJMP L22
L24: MOV TEMP,P3
CJNE TEMP,#0EBH,L28
MOV KEY,#8
SJMP L27
L28: CJNE TEMP,#0DBH,L29
MOV KEY,#9
SJMP L27
L29: CJNE TEMP,#0BBH,L30
MOV KEY,#10
SJMP L27
L30: CJNE TEMP,#7BH,LL1
MOV KEY,#11
SJMP L27
LL1: CJNE TEMP,#0F0H,L26
L27: ACALL DISPLAY
L26: MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
L31: MOV P3,#0F7H
L32: MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
CJNE TEMP,#0F0H,L33
LJMP L1
L33: ACALL DELAY
MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
CJNE TEMP,#0F0H,L34
SJMP L32
L34: MOV TEMP,P3
CJNE TEMP,#0E7H,L38
MOV KEY,#12
SJMP L37
L38: CJNE TEMP,#0D7H,L39
MOV KEY,#13
SJMP L37
L39: CJNE TEMP,#0B7H,L40
MOV KEY,#14
SJMP L37
L40: CJNE TEMP,#77H,LL3
MOV KEY,#15
SJMP L37
LL3: CJNE TEMP,#0F0H,L36
L37: ACALL DISPLAY
L36: MOV TEMP,P3
MOV A,TEMP
ANL A,#0F0H
MOV TEMP,A
RET
TAB: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79H,71H
END
|