Simple 4*4 matrix keyboard scanning program

Publisher:温暖的拥抱Latest update time:2012-11-15 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*
Program effect: Press any key, LED displays the data read back by P0, and the 4*4 matrix keyboard is connected to P0 port
*/
#include //header file
unsigned char key=0xff; //Define a variable to store the key value
void readkey(); //Read key sub-function, get key value
void main() //Main function
{
while(1)
{
readkey(); //Read key value
if(key!=0xff) //Judge whether any key is pressed
P2=~key; //Here is the inversion: because the LED is common cathode, it displays the pressed value
}
}
void readkey() //Read keyboard sub-function
{
P0=0xfe; //Pull the first column low and scan whether any key is pressed. The key values ​​of the first column are: 0, 4, 8, C
key=P0; //Read keyboard value
if(key!=0xfe) //If key! =0xfe, indicating that a key is pressed, then return
return; //Otherwise continue to scan the next column
P0=0xfd;
key=P0;
if(key!=0xfd)
return;
P0=0xfb;
key=P0;
if(key!=0xfb)
return;
P0=0xf7;
key=P0;
if(key!=0xf7)
return;
key=0xff;
}

Click to browse the next page

Reference address:Simple 4*4 matrix keyboard scanning program

Previous article:A simple example of counting with a timer
Next article:Button and digital tube assembly routine

Recommended ReadingLatest update time:2024-11-16 14:56

Technical Exploration: How to Choose an LED Driver Solution?
The massive market for LED lighting is ready for activation LED的经济性主要体现在其更好的节电效果,照度效率的优势。此外,由于LED具有超长寿命,其更换成本也显著优于其它光源。 The global light bulb market has an appetite of 20 billion pieces. After the incandescent bulb was banned in 2012, although the penetration rate of energy-saving fluorescent lamps (CFL) s
[Power Management]
Technical Exploration: How to Choose an LED Driver Solution?
High-efficiency PWM LED drive solution based on PS92010
PS92010 is a high-efficiency PWM controller from TI, integrating frequency foldback and low-power working mode to reduce the working frequency at light load and no load, thereby improving the efficiency of LED driving. It is mainly used in residential LED lighting driving and various LED lighting. This article intro
[Industrial Control]
High-efficiency PWM LED drive solution based on PS92010
Development and design of white light LED
In 1998, white light LED was successfully developed. This LED is made by packaging GaN chip and yttrium aluminum garnet (YAG) together. GaN chip emits blue light (λp=465nm, Wd=30nm), and the YAG phosphor containing Ce3+ made by high temperature sintering is excited by this blue light and emits yellow light with a pe
[Power Management]
[51 microcontroller] STC89C52 lights up the LED light, including C code (2)
1. Reference tutorial: Qingxiang 51 microcontroller tutorial 2. Basic principles: By controlling the high and low electric frequency of the right output terminal, the light can be turned on and off. The voltage on the left side of the lamp is 5V, and if the right side is given logic 0 (0V), there is a voltage differen
[Microcontroller]
[51 microcontroller] STC89C52 lights up the LED light, including C code (2)
Design of a new LED dot matrix display control system based on PIC32 microcontroller
  Background of the project:   LED dot matrix display is a large display system that integrates microelectronics technology, computer technology, and information processing technology. It has become an ideal choice for many display media and outdoor operation displays due to its bright colors, wide dynamic range, high
[Power Management]
A simple production process of LED lamp
In order to enable the majority of electronic enthusiasts and electronic DIY enthusiasts to make simple LED energy-saving lamps by themselves , the blogger now specially provides a LED energy-saving lamp production material and a simple production process of LED lamps for the majority of friends , including the LED en
[Power Management]
A simple production process of LED lamp
Editor's recommendation: Triode constant current solution in LED power supply design
The principle in the figure below is to control the current in the LED by changing the IB current of the transistor , which also has the disadvantage of high loss. Main advantages and disadvantages analysis: The circuit is simple and reliable, and the low cost is its biggest advantage; the constant current accurac
[Power Management]
Editor's recommendation: Triode constant current solution in LED power supply design
LED bulb technology development direction: irradiation range catches up with incandescent lamps
LED bulbs are bulbs that use LED chips as the light source and have the same appearance as incandescent bulbs. Like incandescent bulbs, they can be installed on E26, E17 and other lamp holders. However, compared with incandescent bulbs, they can significantly reduce power consumption. Some types of LED bulbs
[Power Management]
LED bulb technology development direction: irradiation range catches up with incandescent lamps
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号