PIC microcontroller's 4 & 215; 4 determinant keyboard works

Single chip microcomputer STM32L151CCU6
>

PIC microcontroller's 4×4 determinant keyboard works:

(1) The principle of the keyboard system of the single chip microcomputer

The connection of the determinant keyboard is more complicated than that of the stand-alone keyboard, and the programming implementation is more complicated. However, in the case of occupying the same I/O port, the connection of the determinant keyboard will be more than the number of keys allowed by the independent connection, and the schematic diagram is shown in FIG.

Figure 1 Schematic diagram of a 4×4 determinant keyboard

In practical engineering, the PIC16C5X, a universal programmable keyboard and display interface device, can be used to perform both keyboard input and display control functions using the PIC16C5X single-chip device.

The determinant keyboard works by first sending the scan word with the column line, then reading the status of the line line to see if there is a button press. The keyboard section provides a scanning mode of operation that can be connected to a matrix keyboard with 64 buttons, which can continuously scan the keyboard, automatically debounce, automatically recognize the pressed key, and give the code, which can be used for double keys or n The protection is carried out when the keys are pressed at the same time.

In the display section, it provides a scan-enabled display interface for LEDs, fluorescent tubes, and other displays, and provides a multiplexed signal to the display that can display up to 16 characters or numbers.

Whether the button press in the keyboard is judged by the column line feeding into the full scan word and the line line reading the line state, the method is to set all the I/O lines of the column line to a low level, and then the line The line level state is read into accumulator A. If a key is pressed, there will always be a row line pulled low, so that the line input is not all ones.

Which key in the keyboard can be pressed by the column line to be low level by column, check the input state of the line to judge, the method is to send the low level to the column line in turn, and then check all the line state, if all is 1, then The key pressed is not in this column. If not all 1, the pressed key must be in this column, and it is the key at the intersection with the 0 level line.

(2) single-chip keyboard scanning method

The scanning method is to perform a non-all-one state in the state of the column-by-column row (or column) after determining that a key is pressed, and if the state of the (or column) is in a non-all-one state, then the key of the row-state and the column-intersection of the 0-state is It is the key pressed.

The scanning method is characterized by a row-by-row (or column-by-column) scan query, in which case the corresponding row (or column) should have a pull-up resistor connected to a high level. The determinant keyboard scanning program uses the scanning method to determine which key is pressed. In Figure 1, the row and line pull resistors are connected to +5V, and the column lines are scanned column by column.

1 progressive (or column) scan query method.

To determine which key on the matrix keyboard is pressed, the scanning method, also known as the progressive (or column) scanning query method, is one of the most commonly used key recognition methods. The process is as follows.

· Determine whether there is a key press in the keyboard, set all the row lines Y0 to Y3 low, and then check the status of the column lines. As long as the level of one column is low, it means that there are keys pressed in the keyboard, and the closed keys are among the four keys that cross the low level line and the four line lines. If all the column lines are high, no key is pressed in the keyboard.

· Determine the position of the close button. After confirming that the button is pressed, you can enter the process of determining the specific close button. The method is: sequentially setting the row line to a low level, that is, when a certain row line is at a low level, the other lines are at a high level, and after determining that a certain line line is at a low level, and then detecting line by line The level state of each column line. If a column is low, the button at the intersection of the column line and the row line set to the low level is the closed button.

2 inversion method.

The scan method scans the query column by column (row). When the pressed key is in the last row (column), multiple scans are required to obtain the key/key number. The inversion method only takes two steps to obtain the key value. The principle is shown in Figure 2.

Figure 2 Principle of line inversion

The hardware in the figure works in interrupt mode, and an 8-bit I/O port is used to form a 4×4 keyboard. Assuming that the broken line in the figure is the pressed key, the steps of the inversion method are as follows.

• Set D3 to D0 as column input lines, D7 to D4 as line output lines, and make I/O output signals D7 to D4 0000. If a key is pressed, the output of the AND gate goes low, requesting an interrupt to the CPU, indicating that there is a key press in the keyboard. At the same time, the data of D3~D0 is input into a certain unit in the memory, wherein the 0 bit corresponds to the column position of the pressed key.

· Reverse the transfer direction in the first step, that is, D7 to D4 are set as input lines, and D3 to D0 are set as output lines. The I/O port output data is the number in the N unit (that is, D3 to D0 are the column positions of the pressed key), and then the I/O port data is read and sent to the memory N+1 unit for storage, and the data is D7~ The bit corresponding to the 0 level in the D4 bit is the row position of the pressed key. Finally, splicing D3~D0 in the N unit with D7~D4 in the N+1 unit is the key value of the pressed key.

Conclusion: In the MCU application system, any I/O port or extended I/O port can constitute a determinant keyboard. Since the display system with the determinant keyboard usually has a display, in order to save the I/O line, the display circuit and the determinant keyboard are often used in one interface circuit.

All In One Energy Storage



Off-grid, home energy storage, back-up, UPS,Home Series,Home battery series,HomeKit, renewable energy, hybrid system,household

Shenzhen Enershare Technology Co.,Ltd , https://www.enersharepower.com