[go: up one dir, main page]

CN104898853A - Novel three-terminal tact switch - Google Patents

Novel three-terminal tact switch Download PDF

Info

Publication number
CN104898853A
CN104898853A CN201510259467.2A CN201510259467A CN104898853A CN 104898853 A CN104898853 A CN 104898853A CN 201510259467 A CN201510259467 A CN 201510259467A CN 104898853 A CN104898853 A CN 104898853A
Authority
CN
China
Prior art keywords
line
row
alignment
matrix keyboard
chip microcomputer
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201510259467.2A
Other languages
Chinese (zh)
Other versions
CN104898853B (en
Inventor
陶帅
兰毅
申航
胡再国
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Sichuan University
Original Assignee
Sichuan University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Sichuan University filed Critical Sichuan University
Priority to CN201510259467.2A priority Critical patent/CN104898853B/en
Priority to CN201710421374.4A priority patent/CN107204765A/en
Priority to CN201710421412.6A priority patent/CN107204766A/en
Publication of CN104898853A publication Critical patent/CN104898853A/en
Application granted granted Critical
Publication of CN104898853B publication Critical patent/CN104898853B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H03ELECTRONIC CIRCUITRY
    • H03KPULSE TECHNIQUE
    • H03K17/00Electronic switching or gating, i.e. not by contact-making and –breaking
    • H03K17/94Electronic switching or gating, i.e. not by contact-making and –breaking characterised by the way in which the control signals are generated
    • H03K17/96Touch switches
    • H03K17/9618Touch switches using a plurality of detectors, e.g. keyboard

Landscapes

  • Input From Keyboards Or The Like (AREA)

Abstract

一种新型三端轻触开关替代传统的两端式,按键多的场合常采用矩阵键盘,传统的轻触开关组成的矩阵键盘的检测复杂并且不方便用中断的方式完成键盘检测。本发明设计一种新型三端轻触开关并给出了一种4*4矩阵键盘的连接方法和检测方法,对于m行n列的矩阵键盘的连接方法和检测方法也在权利要求书中有详细说明,用这种轻触开关构成的矩阵键盘的检测变得非常简单,可以直接通过读取行线列线的电平状态得出被按下的按键,并且单片机只需要通过一个中断源和若干个普通IO口与矩阵键盘相连就可以以中断的方式完成矩阵键盘检测,由于单片机以中断的方式检测矩阵键盘,单片机可以工作在低功耗休眠模式,在有按键按下时才将其唤醒,这有利于减少系统功耗。

A new type of three-terminal tact switch replaces the traditional two-terminal type. A matrix keyboard is often used when there are many buttons. The detection of the matrix keyboard composed of traditional tact switches is complicated and it is inconvenient to complete the keyboard detection by means of interruption. The present invention designs a novel three-terminal tact switch and provides a connection method and a detection method of a 4*4 matrix keyboard, and the connection method and detection method of a matrix keyboard with m rows and n columns are also included in the claims In detail, the detection of the matrix keyboard composed of this kind of tact switch becomes very simple, and the pressed key can be obtained directly by reading the level state of the row line and column line, and the single-chip microcomputer only needs to pass an interrupt source and Several ordinary IO ports are connected to the matrix keyboard to complete the detection of the matrix keyboard in an interrupted manner. Since the single-chip microcomputer detects the matrix keyboard in an interrupted manner, the single-chip microcomputer can work in a low-power sleep mode and wake it up when a key is pressed. , which helps reduce system power consumption.

Description

一种新型三端轻触开关A new type of three-terminal tact switch

技术领域 technical field

本发明涉及到一种电路轻触开关,用这种轻触开关构成的矩阵键盘的检测变得非常简单,另外,单片机只需要通过一个中断源和若干个普通IO口与矩阵键盘相连就可以以中断的方式完成矩阵键盘检测。 The invention relates to a circuit tact switch. The detection of the matrix keyboard formed by the tact switch becomes very simple. In addition, the single-chip microcomputer only needs to be connected to the matrix keyboard through an interrupt source and several common IO ports. The method of interruption completes the detection of the matrix keyboard.

背景技术 Background technique

键盘是微型计算机系统最基本最常见的输入设备,一般键盘由多个轻触开关构成。根据轻触开关的排列方式,键盘可以分为线性键盘和矩阵键盘。在按键多的场合,我们常采用矩阵键盘,矩阵键盘将轻触开关排成n行m列,每个按键占据行列的一个交点,这样需要连线的数目就是n+m,这样便可检测n*m个轻触开关。而传统的轻触开关为两端式,当我们摁住开关时,这两端导通,自然状态下两端为开路,不导通。这种两端轻触开关构成的矩阵键盘的译键方法常有行扫描法和线反转法,以行扫描法来说,行扫描法需要依次置低矩阵键盘行线上的电平,再读取端口的值以得到被按下按键的编码,这种检测方法在程序上较为繁琐,不够简单,需要经过几个步骤才能识别出被按下的轻触开关。另外,这些方法需要处理器以查询的方式对按键扫描检测,这就要求处理器不断读取IO的电平状态,这种按键检测的方式在实时系统中往往是不适宜的,而且以查询的工作方式检测按键就导致CPU无法工作在低功耗模式,会提高整个系统的功耗。如果要用中断的方式检测矩阵键盘,则需要将行(列)线连接到具有中断能力的IO口,而对于某些低端的处理器外部中断资源是很少的,无法提供足够的具有中断能力的IO口。由传统两端轻触开关构成的矩阵键盘有这两大缺点:检测不够简单和无法工作以中断的工作方式完成检测。而这两大缺点是由传统两端轻触开关的特性所决定的,为了解决克服这些缺点,本发明从轻触开关的结构上提出了一种新的思路。 The keyboard is the most basic and common input device of the microcomputer system, and the general keyboard is composed of a plurality of tact switches. According to the arrangement of tact switches, keyboards can be divided into linear keyboards and matrix keyboards. In the case of many buttons, we often use a matrix keyboard. The matrix keyboard arranges the tact switches into n rows and m columns. *m tactile switches. The traditional tact switch is a two-terminal type. When we press the switch, the two ends are turned on. In the natural state, the two ends are open and non-conductive. The key translation method of the matrix keyboard composed of light touch switches at both ends often includes the row scanning method and the line inversion method. In the row scanning method, the row scanning method needs to set the level on the row line of the matrix keyboard in sequence, and then Read the value of the port to get the code of the pressed button. This detection method is cumbersome in program and not simple enough. It takes several steps to identify the pressed tact switch. In addition, these methods require the processor to scan and detect the keys in an inquiring manner, which requires the processor to continuously read the level status of the IO. The working mode detection button will cause the CPU to fail to work in the low power mode, which will increase the power consumption of the entire system. If you want to detect the matrix keyboard by means of interrupt, you need to connect the row (column) line to the IO port with interrupt capability, and for some low-end processors, there are few external interrupt resources, which cannot provide enough interrupt capability. Capable IO port. The matrix keyboard composed of traditional two-end tact switches has these two major disadvantages: the detection is not simple enough and cannot work to complete the detection in an interrupted working mode. These two shortcomings are determined by the characteristics of the traditional two-terminal tact switch. In order to overcome these shortcomings, the present invention proposes a new idea from the structure of the tact switch.

发明内容 Contents of the invention

为了简化矩阵键盘的检测,并使单片机只需要通过一个中断源和若干个普通IO口与矩阵键盘相连就可以以中断的方式完成矩阵键盘检测。 In order to simplify the detection of the matrix keyboard, and make the single-chip microcomputer only need to connect with the matrix keyboard through an interrupt source and several common IO ports, the detection of the matrix keyboard can be completed in an interrupt mode.

本发明采用的技术方案是:一种新型三端轻触开关,其特征是:由三个接触端构成,自然状态下,这三个端两两开路,摁住开关时,这三个端两两短路。 The technical solution adopted in the present invention is: a new type of three-terminal tact switch, which is characterized in that: it is composed of three contact terminals. In the natural state, two of these three terminals are open. Two short circuits.

键盘连接方式:三端轻触开关的三个端是相同的,为便于表述,将三端轻触开关的三个端分别编号为0、1、2,对于m*n个轻触开关,将其排列成m行n列,每一行n个三端轻触开关的1端由行线相连,各行分别记为ROW_1~ROW_m,每一列的m个三端轻触开关的0端由列线相连,各列分别记为LINE_1~LINE_n,所有m*n个轻触开关的2端连接到一起记为COM端,所有三端轻触开关构成了m行n列的矩阵键盘。 Keyboard connection method: the three terminals of the three-terminal tact switch are the same, for the convenience of expression, the three terminals of the three-terminal tact switch are respectively numbered as 0, 1, 2, and for m*n tact switches, the It is arranged in m rows and n columns, and the 1 terminals of n three-terminal tact switches in each row are connected by row lines, each row is respectively marked as ROW_1~ROW_m, and the 0 terminals of m three-terminal tact switches in each column are connected by column lines , each column is marked as LINE_1~LINE_n, all m*n tact switches are connected together and marked as COM terminal, and all three-terminal tact switches constitute a matrix keyboard with m rows and n columns.

查询工作方式:行线ROW_1~ROW_m分别与单片机IO口相连相连,列线LINE_1~LINE_n分别与单片机IO口相连,COM端接地;单片机通过读取矩阵键盘相连的IO口的值得到行线和列线上的电平状态,每一个按键被按下都对应唯一的行线和列线上的一个电平状态,所以就可以通过单片机读取行线和列线上的电平状态来识别出被按下的按键,这就实现了单片机以查询的工作方式检测整个矩阵键盘。 Query working mode: the row lines ROW_1~ROW_m are respectively connected to the IO ports of the MCU, the column lines LINE_1~LINE_n are respectively connected to the IO ports of the MCU, and the COM terminal is grounded; the MCU obtains the row line and column by reading the value of the IO port connected to the matrix keyboard The level state on the line, each button is pressed corresponds to a level state on the unique row line and column line, so the single-chip microcomputer can read the level state on the row line and column line to identify the Press the button, which realizes the detection of the entire matrix keyboard by the single-chip microcomputer in the working mode of query.

中断工作方式1:行线ROW_1~ROW_m分别与单片机IO口相连相连,列线LINE_1~LINE_n分别与单片机IO口相连,将COM端接到单片机的外部中断引脚,接下来以中断的方式检测整个矩阵键盘,将外部中断设置为下降沿触发,与行线列线相连的IO口设置为推挽输出模式并全部输出低电平,这样,只要有任意一个按键被按下,COM端电平便会被拉低,中断触发,进入中断服务程序,在中断服务程序中,首先将中断引脚设置为输出模式并输出低电平,再将与行线列线相连的IO口设置为上拉输入模式,单片机再读取行线列线的值,通过读取行线列线的电平状态便可以识别出被按下的按键,等待按键释放,识别完成后再将外部中断设置为下降沿触发,与行线列线相连的IO口设置为推挽输出模式并全部输出低电平,单片机继续等待中断的来临,这就实现了单片机以中断的工作方式检测整个矩阵键盘。 Interrupt working mode 1: Row lines ROW_1~ROW_m are respectively connected to the IO port of the microcontroller, column lines LINE_1~LINE_n are respectively connected to the IO port of the microcontroller, and the COM terminal is connected to the external interrupt pin of the microcontroller, and then the entire Matrix keyboard, set the external interrupt as falling edge trigger, set the IO port connected to the row line and column line as push-pull output mode and output low level, so that as long as any key is pressed, the COM terminal level will be It will be pulled low, the interrupt is triggered, and it enters the interrupt service program. In the interrupt service program, first set the interrupt pin to output mode and output low level, and then set the IO port connected to the row line and column line as a pull-up input mode, the MCU reads the value of the row line and column line, and can identify the pressed button by reading the level state of the row line and column line, wait for the button to be released, and then set the external interrupt as a falling edge trigger after the identification is completed , the IO ports connected to the row line and column line are set to push-pull output mode and all output low level, the single-chip microcomputer continues to wait for the interrupt, which realizes the detection of the entire matrix keyboard by the single-chip microcomputer in the interrupt working mode.

中断工作方式2:行线ROW_1~ROW_m分别与单片机IO口相连相连,列线LINE_1~LINE_n分别与单片机IO口相连,每根行线和每根列线都分别连接一个电阻,所有电阻的另一端连接到高电平;所有行线或者所有列线或者所有行线和列线连接到一个与门电路的输入端,与门电路的输出端连接到单片机的外部中断引脚,将外部中断设置为下降沿触发;将COM端接到低电平;任意一个按键被按下,其中一根行线和一根列线的电平被拉低,与门电路输出端输出一个低电平,中断触发,进入中断服务程序,在中断服务程序中,利用中断服务程序读取输入的键的位置。 Interrupt working mode 2: the row lines ROW_1~ROW_m are respectively connected to the IO ports of the microcontroller, the column lines LINE_1~LINE_n are respectively connected to the IO ports of the microcontroller, each row line and each column line are respectively connected to a resistor, and the other ends of all resistors Connect to high level; all row lines or all column lines or all row lines and column lines are connected to the input terminal of an AND gate circuit, and the output terminal of the AND gate circuit is connected to the external interrupt pin of the microcontroller, and the external interrupt is set to Falling edge trigger; connect the COM terminal to low level; when any button is pressed, the level of one of the row lines and one of the column lines is pulled low, and the output terminal of the AND gate circuit outputs a low level, and the interrupt triggers , enter the interrupt service program, in the interrupt service program, utilize the interrupt service program to read the position of the key input.

本发明的有益效果是:这种结构的轻触开关构成的矩阵键盘的检测变得和线性键盘一样简单,并单片机只需要通过一个中断源和若干个普通IO口与矩阵键盘相连就可以以中断的方式完成矩阵键盘检测。用中断的方式检测矩阵键盘不仅提高了整个单片机系统的实时性,提高了效率,还允许系统在休眠模式下工作,有按键按下时才触发中断唤醒CPU,这样做也降低了系统的功耗,节约能源,同时能够键盘的使用寿命。 The beneficial effects of the present invention are: the detection of the matrix keyboard formed by the light touch switch of this structure becomes as simple as the linear keyboard, and the single-chip microcomputer only needs to be connected with the matrix keyboard through an interrupt source and several common IO ports to interrupt The way to complete the matrix keyboard detection. Detecting the matrix keyboard with an interrupt not only improves the real-time performance of the entire microcontroller system, improves efficiency, but also allows the system to work in sleep mode, triggering an interrupt to wake up the CPU when a button is pressed, which also reduces the power consumption of the system , save energy, and at the same time extend the life of the keyboard.

附图说明 Description of drawings

原理图1是三端轻触开关的基本结构,有0,1,2三个端,每个端引出引脚; Schematic diagram 1 is the basic structure of the three-terminal tact switch, which has three terminals 0, 1, and 2, and each terminal leads to a pin;

原理图2给出了一种由传统两端轻触开关构成的4*4矩阵键盘的连接方法; Schematic diagram 2 shows a connection method of a 4*4 matrix keyboard composed of traditional tact switches at both ends;

原理图3给出了一种由新型三端轻触开关构成的4*4矩阵键盘以查询方式工作的连接方法; Schematic Figure 3 shows a connection method for a 4*4 matrix keyboard composed of a new type of three-terminal tact switch to work in query mode;

原理图4给出了一种由新型三端轻触开关构成的4*4矩阵键盘以中断方式工作的连接方法。 Schematic Figure 4 shows a connection method in which a 4*4 matrix keyboard composed of a new type of three-terminal tact switch works in an interrupt mode.

具体实施方式 Detailed ways

原理图2给出了一种由传统两端轻触开关构成的4*4矩阵键盘的连接方法和实现键盘检测的方法,根据原理图2,行线ROW_1~ROW_4分别与单片机P1^0~P1^3(表示P1端口的0~3位,有的教材或者编程语言表示为P1.0~P1.3,本处的表示方法也是常见的标示符号之一,下同;同时,在单片机中有的端口是双向口,或者称为准双向口,即能够输出信息、也能输入信息,此处的P1具有双向口功能)相连并将P1^0~P1^3设置为推挽输出模式,列线LINE_1~LINE_4分别与单片机P1^4~P1^7相连并将P1^4~P1^7设置为上拉输入模式(悬空时引脚为高电平),采用行扫描法检测矩阵键盘,依次将P1^0~P1^3单独置为低电平,每设置一次低电平、都要读取P1^4~P1^7检测各列线的状态,来判断是哪个按键按下(由于单片机的扫描速度远远快于人的输入速度,现在单片机的频率能够达到300MHz,假定扫描需要100个周期,大约在微秒数量级,而人的输入速度在0.1秒的数量级,因此,相对于人的输入速度,扫描所需的时间能够忽略)。具体实现方案:首先将P1^0输出低电平,其余三条行线(P1^1、 P1^2、 P1^3)置为高电平,此时可以检测第一行按键的状态,若key1被按下则LINE_4线电平被拉低,其余列线为高电平,若key2被按下则LINE_3线电平被拉低,其余列线为高电平,依此类推key3、key4,这样通过读取列线的电平的状态就可以得到第一行按键的状态。接着检测第二行的按键,将P1^1输出低电平,其余三条行线(P1^0、 P1^2、 P1^3)置为高电平,此时可以检测第二行按键的状态,若key5被按下则LINE_4线电平被拉低,其余列线为高电平,若key6被按下则LINE_3线电平被拉低,其余列线为高电平,依此类推key7、key8,这样通过读取列线的电平的状态就可以得到第二行按键的状态。同理,再依次置低P1^2和P1^3的电平,其余列线为高电平,便可以分别检测第三行和第四行按键的状态。这样就通过行扫描法检测出了整个矩阵键盘。由于本身有由传统两端轻触开关构成,这种4*4矩阵键盘绝大多少通过查询方式(单片机需要不断读取行线和列线的电平)检测,而且可以看出检测过程也较为复杂繁琐。 Schematic diagram 2 shows a connection method of a 4*4 matrix keyboard composed of traditional tact switches at both ends and a method for realizing keyboard detection. ^3 (indicates the 0~3 bits of the P1 port, and some textbooks or programming languages express it as P1.0~P1.3, and the representation method here is also one of the common marking symbols, the same below; at the same time, there are The port is a bidirectional port, or called a quasi-bidirectional port, which can output information and input information. Here, P1 has the function of a bidirectional port) to connect and set P1^0~P1^3 to push-pull output mode. Lines LINE_1~LINE_4 are respectively connected to P1^4~P1^7 of the single chip microcomputer and set P1^4~P1^7 to the pull-up input mode (the pin is high level when it is suspended), and the line scanning method is used to detect the matrix keyboard. Set P1^0~P1^3 separately to low level, every time the low level is set, P1^4~P1^7 must be read to detect the state of each column line to determine which button is pressed (because the single chip microcomputer The scanning speed is far faster than the human input speed. Now the frequency of the single-chip microcomputer can reach 300MHz. Assuming that the scanning needs 100 cycles, it is about the order of microseconds, and the human input speed is on the order of 0.1 seconds. Therefore, compared to the human input speed, the time required for scanning can be ignored). Specific implementation plan: firstly, P1^0 outputs low level, and the remaining three lines (P1^1, P1^2, P1^3) are set to high level. At this time, the state of the first row of buttons can be detected. If key1 If key2 is pressed, the level of LINE_3 will be pulled down, and the other lines will be high, and so on for key3 and key4. The state of the first row of keys can be obtained by reading the state of the level of the column line. Then detect the buttons on the second row, output P1^1 to low level, and set the remaining three rows (P1^0, P1^2, P1^3) to high level, then you can detect the status of the second row of buttons , if key5 is pressed, the level of LINE_4 is pulled low, and the rest of the column lines are high. If key6 is pressed, the level of LINE_3 is pulled low, and the rest of the column lines are high, and so on key8, so that the state of the second row of keys can be obtained by reading the state of the level of the column line. In the same way, the levels of P1^2 and P1^3 are set low in turn, and the remaining column lines are high, so that the states of the buttons in the third row and the fourth row can be detected respectively. In this way, the entire matrix keyboard is detected by the row scanning method. Since it is composed of traditional tact switches at both ends, this 4*4 matrix keyboard is mostly detected through the query method (the single-chip microcomputer needs to continuously read the levels of the row lines and column lines), and it can be seen that the detection process is relatively Complex and cumbersome.

接下来再给出了一种由本发明所描述的三端轻触开关构成的4*4矩阵键盘的连接方法和实现键盘检测的方法。 Next, a connection method of a 4*4 matrix keyboard composed of the three-terminal tact switch described in the present invention and a method for realizing keyboard detection are given.

首先给出以查询方式实现键盘检测的方法:根据原理图3,行线ROW_1~ROW_4分别与单片机P1^0~P1^3相连,列线LINE_1~LINE_4分别与单片机P1^4~P1^7相连,COM端接电源地(低电平)。P1^0~P1^7都设置为上拉输入模式。单片机只需不断读取P1^0~P1^7即P1整个端口的值,便可得到整个矩阵键盘的状态。当按键S1被按下时,与S1相连的行线与列线都与COM端导通,被拉为低电平即P1^0和P1^7电平都为0,此时读出P1端口的值为0x7e(0x标示16进制,十六进制0x7e表示二进制的01111110),P1^0~P1^7依次对应一个字节的低位到高位,若S16被按下,与S16相连的行线与列线都与COM端导通,被拉为低电平即P1^3和P1^4电平都为0,此时读出P1端口的值为0xe7(二进制的11100111),同理按键S1~S16被按下时,依次对应的P1端口的值为{0x7e,0xbe,0xde,0xee,0x7d,0xbd,0xdd,0xed,0x7b,0xbb,0xdb,0xeb,0x77,0xb7,0xd7,0xe7},这样只需要不断读取P1端口的值便可以得到按下按键的编码进而得到被按下按键的编号。相比于前面叙述的传统二段轻触开关构成的矩阵键盘的检测需要依次置低行线再读取P1^4~P1^7的值来扫描检测每一行的按键,这种由三端轻触开关构成的4*4矩阵键盘的检测大大简化,直接通过读取P1端口的值便可以检测整个矩阵键盘。 Firstly, the method of keyboard detection by query is given: according to the schematic diagram 3, the row lines ROW_1~ROW_4 are respectively connected to the single-chip microcomputer P1^0~P1^3, and the column lines LINE_1~LINE_4 are respectively connected to the single-chip microcomputer P1^4~P1^7 , the COM terminal is connected to the power ground (low level). P1^0~P1^7 are all set to pull-up input mode. The single-chip microcomputer only needs to continuously read the value of P1^0~P1^7, that is, the entire port of P1, to obtain the status of the entire matrix keyboard. When the button S1 is pressed, the row line and column line connected to S1 are connected to the COM terminal, and are pulled to a low level, that is, the levels of P1^0 and P1^7 are both 0, and the P1 port is read at this time The value is 0x7e (0x indicates hexadecimal, 0x7e in hexadecimal indicates binary 01111110), P1^0~P1^7 correspond to the low to high bits of a byte in turn, if S16 is pressed, the line connected to S16 The line and column lines are both connected to the COM terminal, and are pulled to a low level, that is, the levels of P1^3 and P1^4 are both 0. At this time, the value of the P1 port is read as 0xe7 (binary 11100111), and the button is pressed in the same way. When S1~S16 is pressed, the corresponding P1 port values are {0x7e, 0xbe, 0xde, 0xee, 0x7d, 0xbd, 0xdd, 0xed, 0x7b, 0xbb, 0xdb, 0xeb, 0x77, 0xb7, 0xd7, 0xe7}, In this way, it is only necessary to continuously read the value of the P1 port to obtain the code of the pressed button and then obtain the number of the pressed button. Compared with the detection of the traditional two-stage tact switch matrix keyboard described above, it is necessary to lower the row lines in turn and then read the value of P1^4~P1^7 to scan and detect the keys of each row. The detection of the 4*4 matrix keyboard composed of touch switches is greatly simplified, and the entire matrix keyboard can be detected directly by reading the value of the P1 port.

除了简化了矩阵键盘的检测,这种由三端轻触开关构成的矩阵键盘还可以很容易地以中断的工作方式完成其检测。接下来给出以中断方式实现键盘检测的方法:根据原理图4,行线ROW_1~ROW_4分别与单片机P1^0~P1^3相连,列线LINE_1~LINE_4分别与单片机P1^4~P1^7相连,将COM端接到单片机的外部中断引脚,将外部中断设置为下降沿触发,P1口设置为推挽输出模式并全部输出低电平,这样,只要有任意一个按键被按下,COM端电平便会被拉低,中断触发,进入中断服务程序,在中断服务程序中,首先将中断引脚设置为输出模式并输出低电平,P1口设置为上拉输入模式,单片机再读取P1端口的值,通过读取P1端口的值便可以得到被按下按键的编码进而得到被按下按键的编号,按键S1~S16被按下时,依次对应的P1端口的值为{0x7e,0xbe,0xde,0xee,0x7d,0xbd,0xdd,0xed,0x7b,0xbb,  In addition to simplifying the detection of the matrix keyboard, the matrix keyboard composed of three-terminal tact switches can also easily complete its detection in an interrupted working mode. Next, the method of realizing keyboard detection by means of interrupt is given: According to the schematic diagram 4, the row lines ROW_1~ROW_4 are respectively connected to the single-chip microcomputer P1^0~P1^3, and the column lines LINE_1~LINE_4 are respectively connected to the single-chip microcomputer P1^4~P1^7 Connect the COM terminal to the external interrupt pin of the microcontroller, set the external interrupt to be triggered by the falling edge, set the P1 port to the push-pull output mode and output all low levels, so that as long as any button is pressed, the COM The terminal level will be pulled low, the interrupt is triggered, and the interrupt service program is entered. In the interrupt service program, first set the interrupt pin to output mode and output low level, set the P1 port to pull-up input mode, and the microcontroller reads again. Take the value of the P1 port, and by reading the value of the P1 port, you can get the code of the pressed button and then the number of the pressed button. When the buttons S1~S16 are pressed, the corresponding P1 port value is {0x7e ,0xbe,0xde,0xee,0x7d,0xbd,0xdd,0xed,0x7b,0xbb,

0xdb,0xeb,0x77,0xb7,0xd7,0xe7},得到被按下按键的编号后,再将P1口设置为输出模式并输出低电平,将外部中断设置为输入模式,退出中断,这样,单片机可以工作在低功耗休眠模式,在有按键按下时才将其唤醒。 0xdb, 0xeb, 0x77, 0xb7, 0xd7, 0xe7}, after getting the number of the pressed button, set the P1 port to the output mode and output a low level, set the external interrupt to the input mode, and exit the interrupt. In this way, the microcontroller It can work in low-power sleep mode and wake it up when a key is pressed.

Claims (5)

1. novel three end touch-switchs, is characterized in that: be made up of three contact jaws, and under state of nature, these three ends are opened a way between two, when pressing switch, hold short circuit between two for these three.
2. the novel three end touch-switchs of one according to claim 1, it is characterized in that: three ends of three end touch-switchs are identical, for ease of statement, three of three end touch-switchs ends are numbered 0 respectively, 1, 2, for m*n touch-switch, be arranged in the capable n row of m, 1 end of every a line n three end touch-switchs is connected by line, each row is designated as ROW_1 ~ ROW_m respectively, 0 end of m three end touch-switchs of each row is connected by alignment, each row are designated as LINE_1 ~ LINE_n respectively, 2 ends of all m*n touch-switch connect together and are designated as COM end, all three end touch-switchs constitute the matrix keyboard of the capable n row of m.
3. the novel three end touch-switchs of one according to claim 2, is characterized in that: line ROW_1 ~ ROW_m is connected with single-chip I/O mouth respectively, and alignment LINE_1 ~ LINE_n is connected with single-chip I/O mouth respectively, and COM holds ground connection; The value of the I/O port that single-chip microcomputer is connected by reading matrix keyboard obtains the level state on line and alignment, each button is pressed a level state on corresponding unique line and alignment, so the level state that just can be read on line and alignment by single-chip microcomputer identifies the button be pressed, which achieves single-chip microcomputer and detect whole matrix keyboard with the working method of inquiry.
4. the novel three end touch-switchs of one according to claim 2, it is characterized in that: line ROW_1 ~ ROW_m is connected with single-chip I/O mouth respectively, alignment LINE_1 ~ LINE_n is connected with single-chip I/O mouth respectively, COM end is received the external interrupt pin of single-chip microcomputer, next whole matrix keyboard is detected in the mode of interrupting, external interrupt is set to negative edge trigger, the I/O port be connected with line alignment is set to recommend output mode and whole output low level, like this, as long as there is any one button to be pressed, COM holds level just to be dragged down, down trigger, enter interrupt service routine, in interrupt service routine, first interrupt pin is set to output mode and output low level, again the I/O port be connected with line alignment is set to pull-up input pattern, the value of single-chip microcomputer read line alignment line again, just the button be pressed can be identified by the level state of read line alignment line, wait button discharges, again external interrupt is set to negative edge after identification completes trigger, the I/O port be connected with line alignment is set to recommend output mode and whole output low level, the arriving that single-chip microcomputer continuation etc. are to be interrupted, which achieves single-chip microcomputer and detect whole matrix keyboard with the working method of interrupting.
5. the novel three end touch-switchs of one according to claim 2, it is characterized in that: line ROW_1 ~ ROW_m is connected with single-chip I/O mouth respectively, alignment LINE_1 ~ LINE_n is connected with single-chip I/O mouth respectively, every root line is connected a resistance all respectively with every root alignment, and the other end of all resistance is connected to high level; All lines or all alignments or all lines and alignment are connected to the input end of an AND circuit, and the output terminal of AND circuit is connected to the external interrupt pin of single-chip microcomputer, external interrupt is set to negative edge and triggers; COM end is received low level; Any one button is pressed, and wherein the level of a line and an alignment is dragged down, and AND circuit output terminal exports a low level, down trigger, enter interrupt service routine, in interrupt service routine, utilize interrupt service routine to read the position of the key of input.
CN201510259467.2A 2015-05-21 2015-05-21 A kind of three end touch-switch Expired - Fee Related CN104898853B (en)

Priority Applications (3)

Application Number Priority Date Filing Date Title
CN201510259467.2A CN104898853B (en) 2015-05-21 2015-05-21 A kind of three end touch-switch
CN201710421374.4A CN107204765A (en) 2015-05-21 2015-05-21 A kind of three end touch-switch
CN201710421412.6A CN107204766A (en) 2015-05-21 2015-05-21 A kind of three end touch-switch

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510259467.2A CN104898853B (en) 2015-05-21 2015-05-21 A kind of three end touch-switch

Related Child Applications (2)

Application Number Title Priority Date Filing Date
CN201710421374.4A Division CN107204765A (en) 2015-05-21 2015-05-21 A kind of three end touch-switch
CN201710421412.6A Division CN107204766A (en) 2015-05-21 2015-05-21 A kind of three end touch-switch

Publications (2)

Publication Number Publication Date
CN104898853A true CN104898853A (en) 2015-09-09
CN104898853B CN104898853B (en) 2017-08-25

Family

ID=54031557

Family Applications (3)

Application Number Title Priority Date Filing Date
CN201710421374.4A Pending CN107204765A (en) 2015-05-21 2015-05-21 A kind of three end touch-switch
CN201510259467.2A Expired - Fee Related CN104898853B (en) 2015-05-21 2015-05-21 A kind of three end touch-switch
CN201710421412.6A Pending CN107204766A (en) 2015-05-21 2015-05-21 A kind of three end touch-switch

Family Applications Before (1)

Application Number Title Priority Date Filing Date
CN201710421374.4A Pending CN107204765A (en) 2015-05-21 2015-05-21 A kind of three end touch-switch

Family Applications After (1)

Application Number Title Priority Date Filing Date
CN201710421412.6A Pending CN107204766A (en) 2015-05-21 2015-05-21 A kind of three end touch-switch

Country Status (1)

Country Link
CN (3) CN107204765A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108768406A (en) * 2018-07-03 2018-11-06 珠海进田电子科技有限公司 A kind of New Type of Chip Microcomputer key scanning circuit
CN109361400A (en) * 2018-12-03 2019-02-19 天津七二移动通信有限公司 A kind of intelligence key module and its implementation
CN111426370A (en) * 2020-05-08 2020-07-17 西安计量技术研究院 A digital electronic scale matrix keyboard simulator and method

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109298331B (en) * 2018-11-29 2021-09-24 郭玉森 Low-cost detection circuit capable of detecting multiple keys combined arbitrarily and processing method
CN110716135A (en) * 2019-10-28 2020-01-21 中国兵器工业集团第二一四研究所苏州研发中心 Effective capturing circuit and capturing method for impact type mechanical switch signal
CN116047962A (en) * 2022-12-29 2023-05-02 广东省威汇智能科技有限公司 A general multi-channel relay system
CN119248116A (en) * 2023-07-03 2025-01-03 荣耀终端有限公司 Level setting method and electronic equipment
CN119758850B (en) * 2025-03-05 2025-07-18 赛卓电子科技(上海)股份有限公司 Row and column scanning control system based on sleep and wake-up function chip

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US3720938A (en) * 1971-04-19 1973-03-13 Lematex Inc System for preventing erroneous data output signals from an electrical keyboard
US3761944A (en) * 1971-01-22 1973-09-25 Alps Electric Co Ltd Binary code generator
CN1296208A (en) * 1999-11-10 2001-05-23 日本电气株式会社 Keyboard having multiple key switch
CN201345086Y (en) * 2008-12-16 2009-11-11 苏州市华芯微电子有限公司 Low-cost keying signal collection circuit
CN204631788U (en) * 2015-05-21 2015-09-09 四川大学 A new type of three-terminal tact switch

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100562862C (en) * 2006-12-29 2009-11-25 金宝电子工业股份有限公司 Input system
CN101551410B (en) * 2009-05-19 2012-01-11 武汉科技大学 Electrical source for detecting electromagnetic valve quality of automobile
CN102289291B (en) * 2011-05-20 2013-04-24 西北工业大学 Keyboard circuit capable of improving key-press scanning speed
CN103257716B (en) * 2013-05-14 2015-11-18 湖南工业大学 A kind of low-power consumption keyboard and Scan orientation method thereof

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US3761944A (en) * 1971-01-22 1973-09-25 Alps Electric Co Ltd Binary code generator
US3720938A (en) * 1971-04-19 1973-03-13 Lematex Inc System for preventing erroneous data output signals from an electrical keyboard
CN1296208A (en) * 1999-11-10 2001-05-23 日本电气株式会社 Keyboard having multiple key switch
CN201345086Y (en) * 2008-12-16 2009-11-11 苏州市华芯微电子有限公司 Low-cost keying signal collection circuit
CN204631788U (en) * 2015-05-21 2015-09-09 四川大学 A new type of three-terminal tact switch

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108768406A (en) * 2018-07-03 2018-11-06 珠海进田电子科技有限公司 A kind of New Type of Chip Microcomputer key scanning circuit
CN109361400A (en) * 2018-12-03 2019-02-19 天津七二移动通信有限公司 A kind of intelligence key module and its implementation
CN111426370A (en) * 2020-05-08 2020-07-17 西安计量技术研究院 A digital electronic scale matrix keyboard simulator and method

Also Published As

Publication number Publication date
CN107204766A (en) 2017-09-26
CN107204765A (en) 2017-09-26
CN104898853B (en) 2017-08-25

Similar Documents

Publication Publication Date Title
CN104898853B (en) A kind of three end touch-switch
CN104598134B (en) Fingerprint operation method and system of mobile terminal
CN105183232A (en) A mobile terminal control method and mobile terminal without physical buttons
CN101951263B (en) Key scanning method and system
CN109298331A (en) Low cost can detect the detection circuit and processing method of multiple any combination keys
US20110050465A1 (en) Scanning circuit and scanning method for keyboard
CN102594362A (en) Key circuit based on analog-digital conversion
CN204631788U (en) A new type of three-terminal tact switch
CN101521568A (en) Device for network isolation fast switching by one key and controlling method thereof
CN103324296A (en) Detection method of keyboard module and keyboard matrix
CN100562862C (en) Input system
CN101498971B (en) Remote control network physical isolation device and control method thereof
CN101697096A (en) Wireless input terminal worn on fingers
CN204463420U (en) A kind of telepilot
CN204731580U (en) A kind of non-touch gesture control
CN206863542U (en) Key press detecting circuit
CN105227188A (en) A kind of many key press detecting circuits
CN201741107U (en) Keyboard
CN204989896U (en) Intelligence secondary meter
CN204442388U (en) A kind of photon acceptor terminal and power control circuit thereof
CN114578939A (en) Single-line awakening and key detection circuit
CN203151472U (en) Keying circuit capable of scanning a plurality of key codes
CN111628781A (en) A Matrix Keyboard Based on RS232 Serial Communication
TWI796143B (en) Computer system and wake-up method
CN206179204U (en) Real time sensor's teaching intelligence laser pen

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20170825

Termination date: 20180521