Proteus C51 simulation learning board 8 - matrix keyboard

Publisher:HarmonySpiritLatest update time:2022-01-06 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Matrix keyboard, Proteus provides a variety of matrix keyboards, including calculators, telephones, and custom layouts. Encapsulating multiple keys is more vivid. In order to clarify the internal wiring diagram, it is still built using keys.

picture

Before talking about the principle of matrix keyboard, let’s talk about why we use matrix keyboard?


When there are a large number of keys, in order to save IO resources, the keys are usually arranged in a matrix form, and each key is identified by rows and columns. For example, 8 IOs can identify 4*4=16 keys, which is twice as many as directly driving 8 keys.


Principle 1-Reversal scanning method:

In the default state, P10-7 all output high level 1;


First, P1=0x0F, the row line output is 0. If key 7 is pressed, P10=P14=0, then read the row value & 0x0F=0x0E; then read the column value & 0xF0=0xE0, the sum of the two values ​​= 0xEE, and it can be detected that one of the 16 keys is pressed.


  KeyPort=0x0f; //Line output is all 0

  cord_h=KeyPort&0x0f; //Read column line value

  if(cord_h!=0x0f) //First check if any button is pressed

  {

    DelayMs(10); //debounce

    if((KeyPort&0x0f)!=0x0f)

    {

      cord_h=KeyPort&0x0f; //Read column line value

      KeyPort=cord_h|0xf0; //Output current column line value

      cord_l=KeyPort&0xf0; //Read line value

      while((KeyPort&0xf0)!=0xf0);//Wait for release and output

      return(cord_h+cord_l); //Last combination code value of keyboard

    }

  }

  return(0xff); //Return the value


Principle 2 - Line-by-line scanning method:


In the default state, P10-7 all output high level 1;


Then rows P10-P17 output 0xFE=1111 1110, that is, P10=0. So after key 7 is pressed, P14=0, and continue to detect P10-P17=1110 1110=0xEE, so key 7 is pressed.


Then output 0xFD=1111 1101...


 KeyPort=0xf0; //The upper four bits are high, and the lower four bits are low

 if(KeyPort!=0xf0) // indicates a key is pressed

 {

    DelayMs(10); //debounce

    if(KeyPort!=0xf0)

    { //Indicates that a key is pressed

      KeyPort=0xfe; //Detect the first line

      if(KeyPort!=0xfe)

      {

        Val=KeyPort&0xf0;

        Val+=0x0e;

        while(KeyPort!=0xfe);

        DelayMs(10); //debounce

        while(KeyPort!=0xfe);

        return Val;

      }

      KeyPort=0xfd; //Detect the second line

      if(KeyPort!=0xfd)

      {

        Val=KeyPort&0xf0;

        Val+=0x0d;

        while(KeyPort!=0xfd);

        DelayMs(10); //debounce

        while(KeyPort!=0xfd);

        return Val;

      }

      KeyPort=0xfb; //Detect the third line

      if(KeyPort!=0xfb)

      {

        Val=KeyPort&0xf0;

        Val+=0x0b;

        while(KeyPort!=0xfb);

        DelayMs(10); //debounce

        while(KeyPort!=0xfb);

        return Val;

      }

      KeyPort=0xf7; //Detect the fourth line

      if(KeyPort!=0xf7)

      {

        Val=KeyPort&0xf0;

        Val+=0x07;

        while(KeyPort!=0xf7);

        DelayMs(10); //debounce

        while(KeyPort!=0xf7);

        return Val;

      }

     }

   }


The two principles are actually very similar, one is round-robin training, and the other is direct row and column reversal detection, which is easy to understand. If you are doing a physical object, it is best to add pull-up resistors and capacitors, so that the hardware can play a certain anti-shake function, and coupled with the software's anti-shake function, the detection will be more reliable.

Keywords:C51 Reference address:Proteus C51 simulation learning board 8 - matrix keyboard

Previous article:Proteus C51 simulation learning board 9——IIC
Next article:Proteus C51 simulation learning board 7——LCD1602

Recommended ReadingLatest update time:2024-11-16 20:59

C51 programming 9-digital tube (display)
According to the project requirements, you can use I/O external pull-up to drive the digital tube; you can also use 74HC138 (38 decoder) + 74HC245 (8-way signal transceiver) to drive the digital tube. This article will use the latter as the digital tube driving circuit to realize the display of the digital tube in the
[Microcontroller]
C51 programming 9-digital tube (display)
Data types of single chip microcomputer C language C51
The data types of C51 are divided into basic data types and combined data types, which are basically the same as the data types in standard C, but the char type is the same as the short type, and the float type is the same as the double type. In addition, C51 also has special function register types and bit types spec
[Microcontroller]
Data types of single chip microcomputer C language C51
C51 MCU timer T2 countdown program + circuit diagram
  Circuit diagram of digital tube part    51 single chip microcomputer program: #include reg52.h #define UCHAR unsigned char #define UINT unsigned int //sbit KEY=P3^2; UCHAR table = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; UINT context; UCHAR timer;  
[Microcontroller]
C51 MCU timer T2 countdown program + circuit diagram
Summary of C51 keyboard detection related issues
Notes: The connection relationship of each interface in the schematic diagram can refer to the port definition in the code; The data latch of port P0 is two 74HC573 chips; 1. Detection of independent keyboard /*-------------------------- Function: Use digital tube to realize 60s timer When powered on, the digital tu
[Microcontroller]
C51/C52 serial port principle and reference code
1. What is a serial port (RS232 9-pin serial port)       The serial port is a basic external interface that most of our microcontroller units (MCUs) have. Generally, the most basic function of the serial port is debugging, and it can also be used as a data communication interface (with a smaller amount of data). -
[Microcontroller]
C51/C52 serial port principle and reference code
Microcontroller C Language Tutorial Chapter 13--C51 Loop Statement
Loop statements are used in almost every program, and their function is to implement operations that need to be repeated multiple times. For example, if a 12M 51 chip application circuit requires a delay of 1 millisecond, then 1000 empty statements must be executed to achieve the purpose of delay (of course it can be
[Microcontroller]
A multi-tasking mechanism and application based on C51
Introduction   Traditional microcontroller programs generally use a single-task mechanism. Single-task systems have the advantages of being simple, intuitive, and easy to control. However, since the program can only be executed in sequence and lacks flexibility, interrupt functions can only be used to process some sh
[Microcontroller]
Keil c51 common error warning prompt information
1. Warning 280:'i':unreferenced local variable This indicates that no access operation is performed on the local variable i in the function. Solution: Eliminate the declaration of the i variable in the function. 2. Warning 206:'Music3':missing function-prototype This means that the Music3() function has not been
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号