The content of the invention
Based on this, it is necessary to for existing key encoding circuit and matrix keyboard scanning circuit it is complicated the problem of there is provided one
Plant simple key encoding circuit and keyboard scanning circuit.
A kind of key encoding circuit, including N number of input/output port, 2NIndividual key switch and 2NIndividual coding module unit,
Wherein single encoded modular unit includes N number of coding module, and N is positive integer;
One end of each key switch is connected with external power source, and the other end of each key switch is respectively by single encoded
N number of coding module in modular unit connects one to one with N number of input/output port, and single encoded modular unit is loaded with 2N
Plant one kind in binary coding mode.
Above-mentioned key encoding circuit, including N number of input/output port, 2NIndividual key switch and 2NIndividual coding module unit,
Single encoded modular unit includes N number of coding module, and one end of each key switch is connected with external power source, each key switch
N number of coding module of the other end respectively in single encoded modular unit connected one to one with N number of input/output port, it is single
Coding module unit is loaded with 2NOne kind in binary coding mode is planted, passes through coding module unit and realizes and each key switch
Correspondence coding, so can simply realize the hardware encoding of button, can be realized by N number of input/output port to 2NIt is individual
The coding of key switch.
In one of the embodiments, the coding module of key encoding circuit includes the first coding mould for characterizing Binary Zero
Block and the second coding module for characterizing binary one, single encoded modular unit at least include the first coding module and the second coding
One kind in module.
In one of the embodiments, the first coding module of key encoding circuit includes the one or two pole being sequentially connected
Pipe, grounding resistance and the second diode, the second coding module include the 3rd diode and the 4th diode being sequentially connected.
In one of the embodiments, key encoding circuit also includes current-limiting resistance, and one end of each key switch passes through
Current-limiting resistance is connected with external power source.
A kind of keyboard scanning circuit, including down trigger circuit and key encoding circuit, down trigger circuit and button
Coding circuit is connected.
In one of the embodiments, the down trigger circuit in keyboard scanning circuit includes 2NIndividual parallel input signal
Single encoded modular unit in port, key encoding circuit exports an output signal, 2NA pair of individual input signal port 1
The 2 of coding module unit should be receivedNIndividual output signal.
In one of the embodiments, the down trigger circuit in keyboard scanning circuit also includes switching tube, input signal
The control end connection of port and switching tube, the first end of switching tube is connected with external power source respectively and the first end of switching tube is exported
Interrupt signal, the second end ground connection of switching tube.
In one of the embodiments, the down trigger circuit in keyboard scanning circuit also includes 2NIndividual diode, it is single
Input signal port is connected by the control end of single diode and switching tube respectively.
In one of the embodiments, the down trigger circuit in keyboard scanning circuit also includes pull-up resistor, switching tube
First end be connected by pull-up resistor with external power source.
In one of the embodiments, the down trigger circuit in keyboard scanning circuit also includes electric capacity, one end of electric capacity
It is connected with input signal port, the other end ground connection of electric capacity.
Embodiment
In one embodiment, as shown in figure 1, a kind of key encoding circuit, including N number of input/output port 100,2NIt is individual
Key switch 200 and 2NIndividual coding module unit 300, wherein, single encoded modular unit 300 includes N number of coding module, N
For positive integer;
One end of each key switch 200 is connected with external power source, and the other end of each key switch 200 passes through list respectively
N number of coding module in individual coding module unit 300 connects one to one with N number of input/output port 100, single encoded module
Unit 300 is loaded with 2NPlant one kind in binary coding mode.
In general, the input/output port amount of control chip is limited, on the basis of expectation function is realized, as far as possible
Input/output port is saved on ground, gives over to other functional developments, significant for System Programming.Specifically, keyboard-coding
Coding module in the coding module unit 300 of circuit includes the first coding module for characterizing Binary Zero and characterizes binary one
Second coding module, single encoded modular unit at least includes one kind in the first coding module and the second coding module.Such as,
Key encoding circuit include 2 input/output ports (such as IO1 and IO2), 4 key switches (such as S1, S2, S3 and S4) with
And 8 coding modules (C1, C2, C3, C4, C5, C6, C7 and C8), one end of each key switch is connected with external power source, each
The other end of key switch passes through 2 coding modules (1 coding module unit includes 2 coding modules) and 2 inputs respectively
Output port is connected one by one, and one in 1 coding module unit 4 kinds of binary coding mode (i.e. 00,01,10 and 11) of correspondence
Kind, 4 kinds of binary coding modes correspond to 4 key switches respectively, specifically, can be key switch S1 (correspondence binary systems
Coding 01) respectively by coding module C1 and C2 (first coding module and second coding module) accordingly with input
Output port IO1 and IO2 connection, key switch S2 (correspondence binary coding 10) is respectively by coding module C3 and C4 (one
Second coding module and first coding module) accordingly it is connected with input/output port IO1 and IO2, key switch S3 is (right
Answer binary coding 11) respectively by coding module C5 and C6 (two the second coding modules) accordingly with input/output port
IO1 and IO2 connections, key switch S4 (correspondence binary coding 00) passes through coding module C7 and C8 (two first codings respectively
Module) accordingly it is connected with input/output port IO1 and IO2.
Above-mentioned key encoding circuit, including N number of input/output port 100,2NIndividual key switch 200 and 2NIndividual coding mould
Module unit 300, single encoded modular unit includes N number of coding module, and one end of each key switch is connected with external power source, respectively
The other end of individual key switch passes through N number of coding module in single encoded modular unit and N number of input/output port one respectively
One correspondence connection, single encoded modular unit is loaded with 2NOne kind in binary coding mode is planted, passes through coding module unit
Coding corresponding with each key switch is realized, the hardware encoding of button so can be simply realized, N number of input and output can be passed through
Port, is realized to 2NThe coding of individual key switch.Meanwhile, this key encoding circuit comes compared to stand-alone keypad coding circuit
Say, save input/output port resource.
In one embodiment, the first coding module of key encoding circuit include be sequentially connected the first diode, connect
Ground resistance and the second diode, the second coding module include the 3rd diode and the 4th diode being sequentially connected;First
Diode, the second diode, the 3rd diode and the 4th diode are isolating diode, make electronics only toward a direction stream
It is dynamic, prevent from disturbing other key switches;Grounding resistance provides trigger voltage, and the first coding module for characterizing Binary Zero is required to
Grounding resistance.In another embodiment, key encoding circuit also includes current-limiting resistance, and one end of each key switch passes through limit
Leakage resistance is connected with external power source, can so be made by current-limiting resistance by level signal clamper in high level while playing current limliting
With.
In one embodiment, as shown in Fig. 2 a kind of keyboard scanning circuit, including down trigger circuit and button are compiled
Code circuit, down trigger circuit is connected with key encoding circuit.Specifically, the down trigger circuit in keyboard scanning circuit includes
2NSingle encoded modular unit in individual parallel input signal port, key encoding circuit exports an output signal, 2NIt is individual defeated
Enter signal port corresponds reception coding module unit 2NIndividual output signal.Such as, key encoding circuit includes 2 inputs
Output port (such as IO1 and IO2), 4 key switches (such as S1, S2, S3 and S4) and 8 coding modules (C1, C2, C3,
C4, C5, C6, C7 and C8), one end of each key switch is connected with external power source, and the other end of each key switch leads to respectively
Cross 2 coding modules to be connected one by one with 2 input/output ports, 2 coding module 4 kinds of binary coding modes of correspondence, 4 kind two
Scale coding mode corresponds to 4 key switches respectively, specifically, can be key switch S1 (correspondence binary coding 01) point
Not by coding module C1 and C2 (first coding module and second coding module) accordingly with input/output port
IO1 and IO2 connections, key switch S2 (correspondence binary coding 10) passes through coding module C3 and C4 (one second coding respectively
Module and first coding module) accordingly it is connected with input/output port IO1 and IO2, key switch S3 (correspondence binary systems
11) coding is accordingly connected by coding module C5 and C6 (two the second coding modules) with input/output port IO1 and IO2 respectively
Connect, key switch S4 (correspondence binary coding 00) respectively by coding module C7 and C8 (two the first coding modules) accordingly
It is connected with input/output port IO1 and IO2, key encoding circuit draws an output letter from coding module C1 and C2 respectively
Number, draw an output signal in C3 and C4, drawn in C5 and C6 in an output signal, C7 and C8 and draw output letter one by one
Number, more specifically, 4 output signals can be drawn from coding module C1, C4, C6 and C8,4 of down trigger circuit are simultaneously
Capable input signal port accordingly receives this 4 output signals.
In one embodiment, the down trigger circuit in keyboard scanning circuit also includes switching tube, input signal port
It is connected with the control end of switching tube, the first end of switching tube is connected with external power source respectively and the first end output of switching tube is interrupted
Signal, the second end ground connection of switching tube, switching tube can be the switching devices such as triode, CMOS tube, and the first end of switching tube is defeated
Go out interrupt signal, triggering peripheral control unit carries out interrupt processing, realizes monitoring button switch for keyboard state, peripheral control unit in real time
Such as single-chip microcomputer, DSP (Digital Signal Processing, digital signal processor) etc. are by down trigger, to input
The state of output port is inquired about, so as to obtain the hardware encoding of button, this processing mode is simply direct, compared to matrix
Faster, program processing is simpler, more efficient for formula keyboard response.In another embodiment, the interruption in keyboard scanning circuit
Triggers circuit also includes 2NIndividual diode, single input signal port is connected by the control end of single diode and switching tube respectively
Connect, the effect of diode is to prevent crosstalk between key switch, isolate each key switch level signal, prevent loop upset by
The coding of key switch.In another embodiment, the down trigger circuit in keyboard scanning circuit also includes pull-up resistor, switch
The first end of pipe is connected by pull-up resistor with external power source, and pull-up resistor plays metering function.Further, keyboard scanning circuit
In down trigger circuit also include electric capacity, one end of electric capacity is connected with input signal port, and the other end of electric capacity is grounded, electric capacity
Effect be stabilization, that is, smooth and occur level shake when pushing button switch, it is to avoid false triggering interrupt.
In one embodiment, a kind of circuit theory diagrams of keyboard Designing complete four as shown in figure 3, being one by 2 IO
The circuit theory diagrams of individual keyboard-coding, it includes two piths:Low level down trigger circuit and button hardware encoding electricity
Road.Low level down trigger circuit includes triode K1, diode D1, diode D2, diode D11, diode D12, electric capacity
C1 and resistance R2, it is that triggering single-chip microcomputer carries out interrupt processing, realizes the key point of monitoring keyboard button in real time.Triode
K1 effect is that after having button to press, the B pole tensions of triode reach thresholding V, so that the voltage at C poles drops from high level
For low level, so as to provide triggering level for single-chip microcomputer;When being pressed without button, level keeps high level at triode C poles;
D1, D2, D11, D12 effect are to prevent crosstalk between button, keep apart each button level signal, prevent loop from upsetting button
Coding;R2 is pull-up resistor, and it plays metering function;And it is stabilization that C1, which is effect, that is, smooths and occur when a key is pressed
Level is shaken, it is to avoid false triggering is interrupted.
Button hardware encoding circuit includes pull-up resistor R1, button S1, S2, S3, S4, diode and resistance, its circuit
Principle is specifically described by button S1 parts, and D3, D4, D13, D14 are isolating diode, and they make electronics only toward a direction stream
It is dynamic, prevent from disturbing other buttons;R3 is grounding resistance, and it provides trigger voltage, every binary coding for down trigger circuit
Grounding resistance is required for for 0 path, and R4 is then not essential.Button S1 binary coding is 01, when this button is pressed,
Button connects upper and lower ends, and trigger voltage is provided by INIT1 after D3, and is grounded after resistance R3, makes its voltage be
0, at this moment IO_1 voltage is 0 (IO of single-chip microcomputer is set to drop-down ground connection), and it is high level to pass through D4, R4, D14 electricity, at this moment IO_
2 voltage is 1, so simply realizes the hardware encoding 01 of button.S2, S3, S4 coding principle are consistent with S1.
Based on above-mentioned principle, the n powers to 2 can be realized by n IO (Input/Output, input/output port)
The coding of individual button, this design presses next button suitable for the same time, need to such as recognize that two buttons are pressed simultaneously,
Synthesize, or completed using two this programme principles with other keyboard Designing schemes using this programme.In foregoing circuit principle
Other identical function devices can be used to replace for device, such as triode is changed to COMS pipes, and low level triggering is changed to high electricity
Flat triggering etc..Single-chip microcomputer utilizes down trigger, and the state to I/O pin is inquired about, so that the hardware encoding of button is obtained, this
Kind of processing mode is simply direct, compared with matrix form keyboard response faster, program processing is simpler, more efficient, and design is former
Reason is easily understood, and the mode of button unique encodings simplifies the processing procedure of software, improves the resource profit of single-chip microcomputer or system
With rate, make system faster response keypress function;On the other hand, circuit composition device cost is low, so that production cost is effectively reduced,
Profit can be improved, button design saves the I/O resource of single-chip microcomputer, especially significant in pin embedded system in short supply.
In low level triggers circuit, IO_INIT is connected to the pin in single-chip microcomputer with interrupt function, to respond key
Disk event;Resistance R2 resistance is generally 10K or so, and electric capacity C capacity is generally PF grades, if electric capacity is excessive, influenced whether
The integrality of signal, causes triggering unsuccessful, keyboard scan can not be completed when button duration is shorter.Button hardware encoding circuit
In, the resistance ratio of the resistance such as pull-up resistor R1 and R3, R4 needs to meet some requirements, i.e., INIT1, INIT2, INIT3 with
, may if the resistance value of two-way path in parallel formation is smaller and the voltage at INIT4 is more than magnitude of voltage needed for triggering is interrupted
Have influence on the identification of button.In circuit, INIT1, INIT2, INIT3 and INIT4 level can also be connected to another path, example
Such as, the INIT1 in figure can also be connected to R4 upper end, and D3, D4 play influencing each other between isolation IO_1 and IO_2, and D13,
D14 then isolates the influence with other buttons, and other three key circuits are also based on same principle.
Each technical characteristic of embodiment described above can be combined arbitrarily, to make description succinct, not to above-mentioned reality
Apply all possible combination of each technical characteristic in example to be all described, as long as however, the combination of these technical characteristics is not deposited
In contradiction, the scope of this specification record is all considered to be.
Embodiment described above only expresses the several embodiments of the present invention, and it describes more specific and detailed, but simultaneously
Can not therefore it be construed as limiting the scope of the patent.It should be pointed out that coming for one of ordinary skill in the art
Say, without departing from the inventive concept of the premise, various modifications and improvements can be made, these belong to the protection of the present invention
Scope.Therefore, the protection domain of patent of the present invention should be determined by the appended claims.