一、实验目的
掌握查询式键盘的接口和编程方法。
二、实验内容
本实验提供了4个按键的小键盘,如果有键按下,则相应输出为低电平,否则输出为高电平。MCU判断有键按下后,要有一定的延时,防止由于键盘抖动而引起误操作。
编写一个程序,能读出键盘操作的编号,并在数码显示器上显示。
三、实验电路
本实验所需电路请参见系统原理图的第一部分和独立式键盘电路。
四、实验程序参考框图
- LJMP MAIN
- ORG 0100H
- MAIN: MOV 30H,#0aH
- MOV 31H,#0aH
- MOV 32H,#0aH
- MOV 33H,#0aH
- MOV 34H,#0aH
- MOV 35H,#0aH
- MOV 36H,#0aH
- MOV 37H,#0aH
- MOV 50h,#0H
- Loop: CALL DISPLAY
- CALL KEY
- MOV 50h,A
- AJMP Loop
- KEY: MOV P3,#0FFH
- MOV A,P3
- Orl a,#0f0h
- CJNE A, #0FFH, K00
- ret
- K00: ACALL DELAY
- ACALL DELAY
- ACALL DELAY
- ACALL DELAY
- MOV A,P3
- Orl a,#0f0h
- CJNE A,#0FFH,K01
- ret
- K01: cjne a,#0feh,k02
- MOV 50h,#0bh
- Sjmp k05
- K02: cjne a,#0fdh,k03
- MOV 50h,#0ch
- Sjmp k05
- K03: cjne a,#0fbh,k04
- MOV 50h,#0dh
- Sjmp k05
- K04: cjne a,#0f7h,k05
- MOV 50h,#0eh
- Sjmp k05
- K05: MOV 30H,50h
- MOV 31H, 50h
- MOV 32H, 50h
- MOV 33H,50H
- MOV 34H,50H
- MOV 35H,50H
- MOV 36H,50H
- MOV 37H,50h
- MOV A,P3
- Orl a,#0f0h
- CJNE A,#0FFH,K05
- ACALL DELAY
- RET
- DISPLAY:MOV R0,#30H
- MOV R2,#08H
- MOV R3,#00H
- NEXT:MOV A,@R0
- MOV DPTR,#TAB
- MOVC A,@A+DPTR
- MOV P0,A
- INC R0
- MOV A,R3
- RL A
- RL A
- MOV P2,A
- INC R3
- ACALL DELAY
- MOV P0,#00H
- ACALL DELAY
- DJNZ R2,NEXT
- RET
- DELAY: MOV 7FH,#2
- DELAY1: MOV 7EH,#250
- DJNZ 7EH,$
- DJNZ 7FH,DELAY1
- RET
- TAB: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH
- DB 6fH,40H,76H,73H,71H,79H,38H,5eh,31H
- END
复制代码
完整的word格式文档51黑下载地址:
查询式键盘实验.doc
(1.9 MB, 下载次数: 7)
|