Principle and implementation of the key sheet extended GPIO

   GPIO port at a limited number of systems are available case another option is to realize a key sheet: extended GPIO port. There are many methods GPIO expansion, there have been many types of GPIO port expansion devices on the market, but from cost considerations, but they always seemed expensive. For the realization of the key sheet, using a method based on a shift register, because of its low cost, it is widely used to facilitate stability, here we will discuss implementation of a method based on a typical keypad extension of IO 74LS164.

1: hardware principle

    Embedded development engineers must be able to read HW, to understand the circuit, only to understand how the circuit works, it is possible to write a proper control procedures. So, we first look at the 74LS164 (8bit shift register latch) works. Let's use 74LS164 achieve given the key board schematics, and do the necessary analysis and interpretation for this schematic.

 

     For 74LS164, in addition to the power supply, two-way input ports A, B, a the CLK, a CLR and eight unidirectional outputs Q0-Q7. We only care about: the particular input will be what kind of output that we should give GPIO_1 & GPIO_2 what kind of signal, you can get the output we want. O status table below 74LS164

 

 

    That is: the actual input "A & B", assuming a time A & B = 1 (high level) Q0 = 0, in (the state of the original A & B) is after the rising edge of CLK Q0 = 1 Q1 = 0 state (original Q0 of ), is shifted back one. In fact, it can be considered: A & B-> Q0-> Q1-> ... -> Q7, each rising edge of CLK, the order will move back one. If the CLK signal has been low, then Q0-Q7 will remain one of its current state. This is the so-called shift register latches.

    According to the principle of 74LS164, we analyze schematics:

1: a GPIO_1 (Input A & B) high, to give GPIO_2 (CLK) pulse signal 8 sent, then the state Q0-Q7 are high.

2: GPIO_1 to low, followed by a pulse signal to GPIO_2, the low Q0, Q1-Q7 is high; read this time GPIO_3 (KS_DET0), if low, it indicates that the press is KEY_0 next, if high, indicates that no action KEY_0. Similarly, read status GPIO_4 (KS_DET1), you can determine the status of KEY_8.

3: GPIO_1 to high and then to GPIO_2 a pulse signal, the Q0 high, low Ql, Q2-Q7 is high, can determine the state of KEY_1 & KEY_9

4: After just a pulse signal each time a GPIO_2, other keys can be sequentially Analyzing the.

2: software

    Based on the above analysis, we have been very clear determination of the key principles, we know how to control 74LS164 to implement key detection. Before you start the software program, be sure to find out every step we realize that, in order to ensure that the correct code to write. Here is one of my realization:

 

 

  The code provides a determination of 74LS164 switch output connected to the signal state of standard functions, function buttons detection becomes a very brief. Noting achieve Key_Scan () function determines the priority no key operation, the key sheet because in reality at 99% of the cases there is no key operation, thus significantly improving the code efficiency. Good programmers write code at the time, not only will separate from language characteristics to efficient code, still understand the characteristics of the project to improve performance.

3: Discussion and summary

1: Using extension of 74LS164, strictly speaking, it can not be called an extended GPIO, but in our implementation, it replaces the role of GPIO. The working example 4 GPIO achieved using 16 keys. Theoretically reasoning continues, N GPIO lines may be implemented (N-2) * 8 keys.

2: keystrokes, in fact, a switch. As long as it relates to the detection of a switch, we can realize the application. The programming requires only a simple package, you can think of other IO as its detection

 

 

 

Original link: https: //blog.csdn.net/NutriYang/article/details/4374706

Guess you like

Origin www.cnblogs.com/yuanqiangfei/p/11479407.html