Summary of the invention
The technical matters that the present invention will solve is, a kind of keyboard matrix analytical structure and method are provided, and analyzes column rule, alignment and the idle line of whole keyboard matrix efficiently, and is easy and simple to handle, and shortens analysis time greatly, reduces cost of development.
For solving the problems of the technologies described above, the present invention provides a kind of keyboard matrix analytical structure, comprising: main control chip, keyboard interface, LED display board, com port communication module and mode switch button.Wherein, the main control chip, the signal of reception keyboard interface and mode conversion switch is responsible for computing and control system and is scanned, analyzes and display result; Keyboard interface connects keyboard and main control chip; The LED display board, the output signal of reception main control chip, the result that the row at display button place and row and keyboard ranks are analyzed; Com port communication module, the output signal of reception main control chip, output analysis result are to computer, and the program of renewal main control chip; Mode conversion switch, the system of being responsible for is switched between scan pattern and analytical model.
When system works under scan pattern, press any button after, the LED display board shows the row and column at this button place, the com port communication module is sent to computer to ranks information; After pressing all buttons on the lower keyboard; The converting system mode of operation; Make system works in showing under the analytical model; According to column rule, alignment and the idle line of the ranks information analysis keyboard of all buttons that obtain under the scan pattern, and show, send to computer to the ranks information of keyboard through the com port communication module simultaneously through the LED display board.
Each LED lamp on the LED display board all connects a column rule or an alignment; And each keyboard all connects a column rule and an alignment, therefore when system works during in scan pattern, press any button after; There are 2 LED lamps to be lighted; One of them LED lamp connects a column rule, and another LED lamp connects an alignment, and the LED lamp that connects of a column rule or alignment more multilist show that the keyboard number that this column rule or alignment connect is many more.
Mode conversion switch uses the self-locking keyswitch, and when ejecting the self-locking keyswitch, the self-locking keyswitch connects high level, and system works is in scan pattern, when pressing the self-locking keyswitch, and self-locking keyswitch ground connection, system works is in analytical model.
Based on above keyboard matrix analytical structure, the invention allows for the analytical approach of keyboard matrix, specifically may further comprise the steps:
1, judge whether system is in scan pattern, if system works is in analytical model, Eject mode switch then;
2, press all buttons on the lower keyboard one by one,, represent the row at this button place to be lighted with the LED lamp of row whenever by next button, unclamp button after, this LED lamp extinguishes, the while positional information of button will be transferred to the com port communication module;
3, press mode conversion switch, make system works in analytical model;
4, analysis result to the LED display board and the com port communication module of output column rule and alignment, on behalf of the LED lamp of column rule, the column rule on the LED display board on the display keyboard and the distribution of alignment lighted, and represents the LED lamp of alignment to extinguish, and represents the LED lamp flicker of idle line; Simultaneously, through the com port communication module, the analysis result of column rule and alignment transfers to computer.
When system was in scan pattern, to all column rules and alignment label, and the pin that any column rule or alignment be set was low level, and the pin of other column rules or alignment is a high level; Calculate the level of the pin of all column rules and alignment, judge whether the button press is set on low level column rule or the alignment at pin, and detect and become low level pin by high level, the record pin is the label of low level two pins.
When system is in analytical model; Information bank L is used for writing down the column rule analyzed and the state of alignment; Temporary library T is used for the information among the L of backup information storehouse; Judge column rule, alignment and idle line according to the line that contains maximum buttons, and in information bank L, put 1 to the state of the line of analyzing, proceed following steps:
1) judges in the information bank whether be 1:, then export and display result if be 1 in the information bank; Otherwise carry out step 2);
2) the information back-up in the information bank to temporary library;
3) confirm column rule R and alignment C according to current column rule or alignment, and column rule R that has analyzed that record increases newly in information bank and the state of alignment C;
4) judge whether current information bank is consistent with information in the temporary library: if inconsistent, repeating step 3); If consistent, optional single line be made as column rule or alignment, and the state this line puts 1 in information bank L, proceeds step 1) in the line of never analyzing;
5) information with column rule, alignment and idle line exports the LED display board to; Show through the LED lamp; The LED lamp of being lighted representes that the line that this LED lamp connects is a column rule, and the LED lamp that extinguishes representes that the line that this LED lamp connects is an alignment, and the LED lamp of flicker representes that the line that this LED lamp connects is an idle line; Simultaneously, export ranks information to computer.
Technique effect of the present invention is: only need just can obtain by next button the positional information of this button, press the layout that just can obtain keyboard matrix behind all buttons, be specially and judge column rule, alignment and idle line.The The whole analytical process time is short, and efficient is high, and is easy and simple to handle.Secondly, utilize keyboard matrix analytical structure provided by the invention and method, PC manufacturer tested keyboard before assembling, and whether detect keyboard matrix can operate as normal, and whether detect keyboard consistent with the matrix diagram that provides.In addition, utilize keyboard matrix analytical structure provided by the invention and method, can also carry out the fault detect of keyboard, after keyboard connects notebook computer,, explained that the glutinous fault that connects takes place button if existing LED lamp is lighted when not pushing button; If after pressing any button, all LED lamps still are in and extinguish state, explained that button can't be closed.At last, according to a kind of keyboard matrix analytical structure provided by the invention and method, be applicable to and analyze any matrix keyboard that usable range is wide.
Embodiment
For making the object of the invention, technical scheme and advantage clearer, the present invention is made further detailed description below in conjunction with accompanying drawing.
Fig. 1 is the hardware system structure figure of keyboard matrix analytical structure provided by the invention
As shown in Figure 1, keyboard matrix analytical structure provided by the invention comprises following structure:
1, the main control chip 103; Receive the signal of keyboard interface 102 and mode conversion switch 105; Be responsible for scanning location, the ranks analysis of computing and control button, control LED display board 104 simultaneously and show the result of ranks analyses and send on analysis result to the computer 107.
2, keyboard interface 102, connect keyboard 101 and main control chip 103.
3, the LED display board 104, receive the output signal of main control chip 103, the row and the row at display button place, and the result of keyboard ranks analysis.
4, the com port communication module 106, receive the output signal of main control chip 103, and output ranks analysis result is to computer 107, and the program of renewal main control chip 103.
5, mode conversion switch 105, and the system of being responsible for changes between scan pattern and analytical model.
Fig. 2 is a keyboard matrix analytical structure circuit structure diagram provided by the invention.
As shown in Figure 2, as preferred embodiments, the keyboard matrix analytical structure comprises:
1, the main control chip 201, and its pin number is more than or equal to 40, and the growth data that the Flash that includes can deposit is more than or equal to 100 bytes, and code is more than or equal to 5000 bytes.P00 to the P07 mouth of the 32nd to the 39th pin of main control chip 201 is connected with 1 display unit 303, and is connected to keyboard and connects 302 the 1st to the 8th pin; P10 to the P17 mouth of the 1st to the 8th pin of main control chip 201 is connected with another display unit 303, and is connected to the 17th to the 24th pin of keyboard interface 302; P20 to the P27 mouth of the 21st to the 28th pin of main control chip 201 is connected with display unit 303, and is connected to the 9th to the 16th pin of keyboard interface 302.The 9th pin of main control chip 201 connects reset signal RESET; The 10th pin connects signal RXD; The 11st pin connects signal TXD; The 17th pin connection mode switching signal MODE_SW; 18th, 19 pins connect capacitor C 7, C8 and crystal Y2, form the clock circuit of system; The 20th pin ground connection; The 40th pin connects high level VCC.
2, display unit 303; It comprises 8 resistance R and 8 light emitting diode D, and each resistance R all is connected in series formation display element structure with a light emitting diode D; 8 display element structures are connected in parallel; And an end connects high level VCC, constitutes display unit 303, the other end then with the main control chip on P00 to P07 or P10 to P17 or P20 to P27 be connected.
3, mode conversion switch 304, and it adopts 1 self-locking keyswitch S4, when ejecting the self-locking keyswitch; The self-locking keyswitch connects high level, and system works is in scan pattern, when pressing the self-locking keyswitch; Self-locking keyswitch ground connection, system works is in analytical model.
4, com port transport module, it is made up of 9 core interfaces 305 and chip 306, and the 1st is connected with the 3rd pin through capacitor C 4 with the 2nd pin, and passes through capacitor C 6 and be connected with high level VCC; The 4th pin is connected with the 5th pin through capacitor C 2; The 6th pin is through capacitor C 5 ground connection; The 7th pin connects the 2nd pin of 9 core interfaces 305; The 8th pin connects the 3rd pin of 9 core interfaces 305; The 10th pin connects signal RXD, and the 11st pin connects signal TXD, the 15th pin ground connection; The 16th pin meets high level VCC.Wherein, the 2nd, 3 pins connect the 7th, 8 pins of chip 306 respectively in the 9 core interfaces 305, and the 5th pin ground connection.
5, reset circuit 307; Form with capacitor C 1 by switch S 2, resistance R 9, and switch S 2 is connected in parallel end connection high level with capacitor C 1; The other end connects resistance R 9 back ground connection, and the junction output signal with resistance R 9 after switch S 2 is connected in parallel with capacitor C 1 is reset signal RESET.
6, in the feed circuit 308; It comprises the power supply P1 that is connected in series, switch S 1, light emitting diode D25 and a resistance R 26; Wherein, The junction ground connection of power supply P1 and resistance R 26, switch S 1 is high level VCC with the junction output signal of light emitting diode D25, for total system provides WV.
As preferred forms, main control chip 301 is chip STC8958, and chip 306 is the MAX232 chip; And all resistances are 1000 ohm, and all light emitting diode D are withstand voltage to be 5 volts, and capacitor C 1 is 20 microfarads; Capacitor C 2 to C6 is 1 microfarad; Capacitor C 7, C8 are 30 microfarads, and the vibration frequency of crystal oscillator Y2 is 12M, and power supply P1 supply voltage is 5 volts.
The present invention also provides a kind of analytical approach based on above-mentioned keyboard matrix analytical structure.
Fig. 3 is a keyboard matrix analytical approach operational flowchart provided by the invention.
As shown in Figure 3, the keyboard matrix analytical approach that this embodiment provides may further comprise the steps:
Step S301 judges whether system works in scan pattern, if system works is in analytical model, and Eject mode switch then;
Step S302 presses all buttons on the lower keyboard one by one, whenever by next button; Represent the row at this button place and the LED lamp of row to be lighted; After unclamping button, this LED lamp extinguishes, and connects the column rule of this LED lamp and the label information of alignment simultaneously and will be transferred to the com port communication module;
Step S303 presses mode conversion switch, makes system works in analytical model;
Step S304; Analysis result to the LED display board and the com port communication module of output column rule and alignment, on behalf of the LED lamp of column rule, the column rule on the LED display board on the display keyboard and the distribution of alignment lighted; Represent the LED lamp of alignment to extinguish, represent the LED lamp flicker of idle line; Simultaneously, through the com port communication module, the analysis result of column rule and alignment transfers to computer.
When system works under scan pattern, press any keyboard after, the LED display board shows the row and column at this button place, the com port communication module is sent to computer to corresponding ranks information; After pressing all buttons on the lower keyboard; The converting system mode of operation; Make system works under analytical model; Analyze column rule, alignment and the idle line of keyboard according to the positional information of all buttons under the scan pattern, and, send to notebook computer to the ranks information of keyboard through the com port communication module simultaneously through the demonstration of LED display board.
Fig. 4 is in the operational flowchart under the scan pattern for system in the keyboard matrix analytical approach provided by the invention.
Comprise 24 LED lamps in the keyboard matrix analytical structure provided by the invention as shown in Figure 2, thus column rule and alignment add up to 24, all column rules and alignment label 1,2,3......24 carries out following steps successively, and is as shown in Figure 4:
Step S401, it is 1 that parameter i is set;
Step S402, the pin that label is set is i is a low level 0, the pin of other all column rules and alignment is a high level 1;
Step S403 is divided into three groups to 24 pins, and the level of per 8 pins is formed one 8 binary number, and then the level of 24 pins is formed 3 binary number SUM1, SUM2 and SUM3 successively;
Step S404, judge whether SUM1, SUM2 and SUM3 meet the following conditions:
(SUM1/SUM2/SUM3+1<<(i%8))%0xFF=0
If satisfy above-mentioned equality, expression does not have button to press this moment, and the level of all column rules and alignment does not all change, and makes parameter i add 1, and judges that whether parameter i if i be less than or equal to 24, then carries out S403 step less than 24 again at this moment; If i is greater than 24, rescan from the S401 step;
If do not satisfy above-mentioned equality, a button is pressed at this moment in expression, carries out step S405;
Step S405, the button of pressing and label are that the pin of i is connected, and cause other to become low level by the pin of single line; Detection becomes low level pin by high level, obtains the corresponding column rule of this pin or the label j of alignment, is among low level column rule and alignment i and the j at two; One is column rule; Another root is an alignment, and the two corresponding LED lamp lighted, and shows the position at this button place;
Step S406 writes down this button and the corresponding column rule and the label information of alignment.
When system was in scan pattern, 24 lines of scanning that system repeats after any time in scanning process presses any button, then can be judged column rule or the information of alignment of the correspondence of this button.
In the equality in S405 under above-mentioned scan pattern step, % representes modulo operation, and i%8 representes to get i divided by the remainder after 8; The shift left operation of<<expression binary number; And the low level zero padding, 1<<(i%8) expression is 1 move to left (i%8) and low level zero padding; 0xFF is a sexadecimal number, corresponding to 11111111 of binary number.
When by next button and after any pin is set is low level 0; Easy for calculating; Obtain 38 binary number SUM1, SUM2 and SUM3 according to the level of all pins,, then cause having another pin to become low level by high level if this button column rule or alignment corresponding with this low level pin is interconnective; Be that SUM1 or SUM2 or SUM3 can change; If this button column rule or alignment corresponding with this low level pin is not interconnective, then SUM1 or SUM2 or SUM3 remain unchanged, and therefore judge through the equality in S405 step whether SUM1, SUM2 and SUM3 change.If i=3 is set; Then obtain SUM1, SUM2 and SUM3,, judge whether the result after the addition can be divided exactly by binary number 11111111 with binary number 1000 additions; If aliquot; In the level of 24 pins of expression, having only label is that 3 pin is a low level, and column rule that the button of promptly pressing is corresponding with this low level pin or alignment are not interconnective; If it is aliquant; In the level of 24 pins of expression; Except that label is that 3 pin is the low level; It is low level that another pin is arranged, and column rule or alignment that the button of promptly pressing is corresponding with this low level pin are interconnective, can obtain another low level pin j through detecting all pin level.
When system is in scan pattern, utilize following form writing scan result:
In above table, first row are all represented the label of all column rules and alignment with first row, and as if after pressing certain button, label is that the 1 LED lamp that is connected with 3 is lighted, and record in form then is like x in the form; If after pressing certain button, label is that 2 and 23 LED lamp is lighted, and record in form then is like z in the form; After pressing all buttons one by one; Then obtain the form data that the corresponding LED lamp of all buttons is lighted; And can find out the key number on any column rule or the alignment, simultaneously, if having delegation to have no record in the form; Then the line of the corresponding label representative of this row as idle line, have no record like the row of the 24th in the form.Be label that 24 line is as idle line then.
When system is in analytical model; Information bank L is used for writing down the column rule analyzed and the state of alignment; Temporary library T is used for the information among the L of backup information storehouse; Judge column rule, alignment and idle line according to the line that contains maximum buttons, and in information bank L, put 1 to the state of the line of analyzing, proceed following steps:
1) judges in the information bank whether be 1:, then export and display result if be 1 in the information bank; Otherwise carry out step 2);
2) the information back-up in the information bank to temporary library;
3) confirm column rule R and alignment C according to current column rule or alignment, and column rule R that has analyzed that record increases newly in information bank and the state of alignment C;
4) judge whether current information bank is consistent with information in the temporary library: if inconsistent, repeating step 3); If consistent, optional single line be made as column rule or alignment, and the state this line puts 1 in information bank L, proceeds step 1) in the line of never analyzing;
5) information with column rule, alignment and idle line exports the LED display board to; Show through the LED lamp; The LED lamp of being lighted representes that the line that this LED lamp connects is a column rule, and the LED lamp that extinguishes representes that the line that this LED lamp connects is an alignment, and the LED lamp of flicker representes that the line that this LED lamp connects is an idle line; Simultaneously, export ranks information to computer.
Fig. 5 is in the process flow diagram under the analytical model for system in the keyboard matrix analytical approach provided by the invention.
As shown in Figure 5, press all buttons after, press mode conversion switch, make system be in analytical model, according to the corresponding column rule of all buttons of record or the label of alignment, carry out according to following steps successively:
Step S501 finds out and contains the maximum line of key number, the maximum line of promptly bright lamp number of times;
Step S502 as column rule R, as alignment C, and is made as 1 to the line that intersects with this line to the line that intersects with column rule R to column rule R and the corresponding state of alignment C in information bank L;
Step S503 finds out idle line K, and in information bank L, is made as 1 to the corresponding state of idle line K;
Step S504, judge among the information bank L wired state whether be 1, if be 1 among the information bank L, carry out step S509; Otherwise carry out step S505;
Step S505, the information back-up among the L of current information storehouse to temporary library T;
Step S506 records alignment C to all and the crossing line of column rule R, and the line that all and alignment C intersect records among the column rule R, and in information bank, is changed to 1 to the column rule R of the analysis that increases newly or the state of alignment C among the L;
Step S507 judges whether information bank L is consistent with information among the temporary library T, if inconsistent, carries out the S506 step again; If consistent, carry out the S508 step;
Step S508, an optional line be made as column rule, and the state this line is changed to 1 in information bank L in the line of never analyzing, and proceeds the S504 step;
Step S509; The information of output record exports the LED display board to, shows through the LED lamp, and the LED lamp of lighting representes that the line that this LED lamp connects is a column rule; The LED lamp that extinguishes representes that the line that this LED lamp connects is an alignment, and the LED lamp of flicker representes that the line that this LED lamp connects is an idle line.Simultaneously, the information of output record exports computer to.
In above-mentioned analytical model step, record analysis data as follows:
|
1 |
2 |
3 |
... |
?23 |
24 |
L |
1 |
1 |
|
... |
?1 |
1 |
T |
1 |
1 |
|
... |
?1 |
1 |
R |
1 |
1 |
|
... |
|
|
C |
|
|
|
... |
?1 |
|
K |
|
|
|
|
|
1 |
In above table, the label of all column rules of first line display and alignment, L are information bank, record column rule and the alignment analyzed, and T is a temporary library, is used for information among the L of backup information storehouse, and R is a column rule, and C is an alignment, and K is an idle line.According to above-mentioned analytical model, obtain following information:
(1) S501 to S503 that accomplishes first specific embodiments under the above-mentioned analytical model successively is after the step; Obtain the label of column rule R, alignment C and idle line K; In above table, using 1 record, is that 1 and 2 line is column rule R like label, and label is that 23 line is alignment C; Label is that 24 line is idle line K, and in information bank L, is label that the state of 1,2,3,23,24 line is changed to 1;
(2) according to the S504 step, judging among the information bank L is not 1 entirely, proceeds the S505 step;
(3) go on foot according to S505 to the S506; The information back-up among the information bank L to temporary library T; According to current column rule R and alignment C, seek the line of not analyzing that column rule R and alignment C intersect again, the line that intersects with alignment C just is referred to column rule R; Just be referred to alignment C with column rule R intersects, and in information bank L, be changed to 1 to the state of the line of the analysis that increases newly;
(4), judge that whether information bank L is consistent with information among the temporary library T, as if inconsistent, carry out S507 and goes on foot according to S507 to the S508 step; If consistent, optional single line is classified as column rule in the line of never analyzing; Repeat the S504 step again, in information bank L, be 1, then carry out the S509 step.
S501 to S503 under above-mentioned analytical model according to information recorded under the scan pattern, judges column rule R and alignment C earlier in the step, judges idle line again.In S508 step, optional line as column rule, the line that intersects with current column rule R as alignment C, with the crossing line of alignment C in the ban as column rule R.
As optional embodiment, in system is under the analytical model, and S508 goes on foot, can judge column rule R and alignment C again optional line as alignment.
As another optional embodiment, when system is under the analytical model, can judge idle line earlier according to information recorded under the scan pattern, judge column rule and alignment again.
According to keyboard matrix analytical structure provided by the invention and analytical approach; Only need just can obtain the positional information of this button by next button; Press the layout that just can obtain keyboard matrix behind all buttons, judge which is a column rule, which is alignment, which is idle line.The The whole analytical process time is short, and efficient is high, and is easy and simple to handle.Secondly, the keyboard matrix analytical structure and the analytical approach that propose according to the present invention, PC manufacturer tested keyboard before assembling, and whether detect keyboard matrix can operate as normal, and whether detect keyboard consistent with the matrix diagram that provides.In addition; A kind of keyboard matrix analytical structure and the analytical approach that propose according to the present invention can also be carried out the fault detect of keyboard, after keyboard connects notebook computer; If existing LED lamp is lighted when not pushing button, explained that the glutinous fault that connects takes place button; If after pressing any button, all LED lamps still are in and extinguish state, explained that button can't be closed.At last, according to a kind of keyboard matrix analytical structure provided by the invention and analytical approach, be applicable to and analyze any matrix keyboard that usable range is wide.
Under situation without departing from the spirit and scope of the present invention, can also constitute many very embodiment of big difference that have.Should be appreciated that except like enclosed claim limited, the invention is not restricted at the specific embodiment described in the instructions.