Scan button display

Source: Internet
Author: User

; **************************************** ****************************************
This program implements the scan button display function .*
Display the numbers 123a456b789c * 0 # D * by pressing 16 keyboards respectively *
; Keyboard port P1, the first p21. The P0 port of the digital tube segment *
; **************************************** ****************************************
The IO port of the single chip microcomputer connected by the line is used as the output end, while the IO port connected by the line is used as the input. In this way, when the key is not pressed, all output ends are high, which means that the key is not pressed.
The line output is low. Once a key is pressed, the input line is pulled down. In this way, you can check whether a key is pressed by reading the status of the input line.
Determine which keys are pressed on the matrix button, line scan method, or line reversal method.
The row scan method is also known as the row-by-row (or column) scan query method. It is the most common key recognition method.
To determine whether the keyboard has a key or not: set all the rows to a low level, and then check the column line status. If the level of one column is low, a key in the keyboard is pressed and the closed key is located in
Among the four buttons that are low-level and cross the four lines. If all columns are high, no key is pressed on the keyboard.
Determine the location of the closed key: After confirming that a key is pressed, you can identify the fault of the specific closed key. The method is to set the line to low at a time, that is, when a line is set to low, other lines are high.
After determining that the position of a root line is low, the level status of each line is checked row by row. If a column is low, the keys at the intersection of the column line and the row line that is set to low are closed keys.
The P1 port of the single-chip microcomputer is used as the keyboard I/O port. The column line of the keyboard is connected to the four low bits of the P1 port, and the line of the keyboard is connected to the four high bits of the P1 port, line P1.0-P1.3 is set to input line, line P1.4-P1.7 is set to output line,
4 and 4 columns Form 16 intersection points.
; 1. check whether the current key is pressed, the detection method is P1.4-P1.7 output all "0", read the status of the P1.0-P1.3, if the P1.0-P1.3 is all "1", then no key closed, otherwise, a key is closed;
2. Remove the key jitter. When a key is detected, wait for a period of time before performing the next detection.
3. If a key is pressed, identify which key is closed. Scan the line of the keyboard. The P1.4-P1.7 is output in four combinations:
; P1.7 1110 p1.6 1101 p1.5 1011 p1.4 0111
; Read the P1.0-P1.3 when each group of row outputs, if all is "1", it is expressed as "0" this line has no key closed. Otherwise, the row and column values of the closed key are obtained, as shown in the following figure.
Then, the row and column values of the closed key can be converted into the defined key using the calculation method and the table look-up method;
4. To ensure that the key is not closed once and the CPU is only processed once, the jitter during key release must be removed;
Org 0000 h
Ajmp main
Org 0030 H
Main:
MoV dptr, # tab; Add the header to dptr
Lcall key; call the keyboard Scanner
Movc A, @ A + dptr; send the key value to ACC after checking the table
MoV P0, A; send ACC value to P0 Port
CLR p2.1; on-Display
Ljmp main; returns the display of calling subprograms repeatedly and cyclically
Key: lcall KS; call the detection key subroutine
Jnz K1; press the key to continue
Lcall delay2; call DeLay dejitters without pressing keys
Ajmp key; return to continue detection with or without pressing the buttons
K1: lcall delay2
Lcall delay2; press the key to continue the jitter
Lcall KS; call the detection key program again
Jnz K2; Confirm that you have pressed for the next step
Ajmp key; no key press to return to continue detection
K2: mov R2, # 0efh; send the scan value to R2 for temporary storage
MoV R4, #00 h; send the column value of the first column to R4 for temporary storage. R4 is used to store the column value.
K3: mov P1, R2; send the value of R2 to the P1 Port
L6: JB p1.0, L1; p1.0 equals 1 to jump to L1
MoV A, #00 h; send the row value of the first line 00h to ACC
Ajmp LK; jump to the key-value processing program
L1: JB p1.1, L2; p1.1 equals 1 to L2
MoV A, #04 H; send the row value of the second row to ACC
Ajmp LK; jump to the key-Value Management Program for key-value processing
L2: JB p1.2, L3; p1.2 equals 1 to jump to L3
MoV A, #08 h; send the row value of the third row to ACC
Ajmp LK; jump to the key-value processing program
L3: JB p1.3, next; p1.3 equal to 1 jump to next
MoV A, # 0ch; send the row value of the fourth row to ACC
Lk: Add a, R4; the key value after adding the row value and column value is sent to
Push ACC; send the value in a to the stack for temporary storage
K4: lcall delay2; call the latency dejitter Program
Lcall KS; call the key detection program
Jnz K4; the buttons are not released. Continue to return to Detection
Pop ACC; send the stack value to ACC
RET

Next:
INC R4; add one column Value
MoV A, R2; send the value of R2 to
JNB acc.7, key; scan completed jump to key for next round Scan
Rl a; the scan is incomplete. Move the value in a to the Right to scan the next column.
MoV R2, A; send the ACC value to R2 for temporary storage
Ajmp K3; jump to K3 to continue
KS: mov P1, # 0fh; set the four-digit P1 port height to 0 and the four-digit value to 1
MoV A, P1; read P1 Port
Xrl a, # 0fh; the value in a is different from the value in a or
RET; subprogram return
Delay2:; 40 ms latency dejitter subroutine 8 * Fa * 2 = 40 ms
MoV R5, #08 h
L7: mov R6, # 0fah
L8: djnz R6, l8
Djnz R5, L7
RET

Tab:
DB 28 h, 34 h, 28 h, 34 h, 0a9h, 60 h, 20 h, 7ah, 20 h, 21 h, 61 H, 74 h, 30 h, 62 h, 0a2h, 7eh
0h0hc9878654a321 displays the keyboard in turn because it cannot be expressed * # It is represented by H, and B is represented by 8.
End

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.