Welcome to hificat.com ---- HANGZHOU KinCony ELECTRONICS CO.,LTD.
About Us Contact Us          Our Patents Our Articles        Forum      SiteMap    Chinese Version

Chapter 1. Overview Chapter 2. Emulation Guide Chapter 3. Build Your First Project Chapter 4. In System Programming
Chapter 5. USB Interface Installation Chapter 6. LED Display Application Chapter 9. FAQ Chapter 10. System Configuration and Service
 
Chapter 7. Basic Experiments
7.1. Experiment with LED 7.2. Experiment with Flowing LEDs 7.3. Experiment with Keys 7.4. Experiment with Beeper
7.5. Experiment with Relay 7.6. Experiment with LED Display 7.7. Experiment with Serial Port  
 
8.1. Experiment with Matrix Key 8.2. Experiment with Stepping Motor 8.3. Experiment with 1-Wire Digital Thermometer DS18B20
8.4. Experiment with 24C01 EEPROM 8.5. Experiment with 93C46 Serial EEPROM 8.6. Experiment with DS1302 Real-time Clock
8.7. Experiment with 8-bit Serial AD Converter ADC0832 8.8. Experiment with 1602 Character LCD Module 8.9. Experiment with 12864 Graphic LCD
8.10. Experiment with Infra-red Remote Controller 8.11. Experiment with Wireless Encoding Module Chapter 11. User Feedback

Chapter 8. Advanced Experiments

8.1. Experiment with Matrix Key

Introduction

The 4*4 matrix key, also called key array, consists of 4 I/O rows and 4 I/O columns. Every key cross over a junction of row and column. In this way, I/O port can be used effectively.

Principle of Matrix Key

The most common matrix key is like the below picture. Composed by 16 keys, 1 I/O port can be used to implement the matrix.

The circuit of matrix key.

When no key is depressed, P1.0 ~ P1.3 and P1.4 ~ P1.7 are open-circuit. When any key is depressed, those I/O lines which are connected with the key will be short-cut.

Method to recognize the status of keys:

Step 1, set column P1.4 ~ P1.7 to be input, and set row P1.0 ~ P1.3 to be low level. Then read the status of column P1.4 ~ P1.7, if there is one column low level, there must be a key depressed. Now move on to Step 2 to locate the key.

Step 2, set row P1.0 ~ P1.3 to be low level in turn, and read from column P1.4 ~ P1.7. If a column is low level, the depressed key is then located.

By the result of 2 steps, the depressed key is found. Remember, one pressing of the key only causes one action which calls a key processing function, therefore, key processing function must be invoked after the key is released.

Example on Matrix Key Design

The example illustrates how to program the matrix key in the K8MDP. When 1 key is pressed, the key number will be displayed on the LED display, from 0 to F.

Below is the schematic diagram.

Row P1.0 ~ P1.3 are output lines. Column P1.4 ~ P1.7 are input lines. At the beginning, row P1.0 ~ P1.3 output low level. Then read the column P1.4 ~ P1.7. If they are all high level, there must be no key depressed. If one of the columns is low level, a certain period of time delay is needed to get rid of the impact from key pressing noise. After the delay, if that column is still low level. Then it is certain that there is one key depressed.

To know which key is depressed, we can scan the whole matrix. Set row P1.0 ~ P1.3 to be 0111, 1011, 1101, 1110 in turn, at the same time, read the column P1.4 ~ P1.7. If the value read from P1.4 ~ P1.7 is the 1111, then there is no key depressed, otherwise, the value is the key number.

Now let’s take the S5 key for example. When we pressed S5, and scan row P1.0 ~ P1.3, we can read 1011 from P1.4 ~ P1.7. 1011 is 0x0B in octal. So, jumper to S5 key processing subroutine to react the S5 key action.

 



COPYRIGHT2003--2008 HANGZHOU KinCony ELECTRONICS CO.,LTD. All Rights Reserved

Add:Rm 11-3-702, Pujing Jiayuan, Gongshu District, Hangzhou, Zhejiang, China.
Tel:+86-0571-85956028,Fax:+86-0571-88230070 E-mail: hificat@163.com  ICQ:164806453  Webmaster:Hificat