#include
#include "../delay/delay.h"
#include "matrix.h"
/*=====================================================
Key scanning function, returns the scanned key value
======================================================*/
unsigned char key_scan(void)
{
unsigned char keyvalue;
KEYPORT = 0xf0; //The upper four bits are high, and the lower four bits are low
if(0xf0 != keyvalue)
{
delay_ms(10); //debounce
if(0xf0 != keyvalue) //A key is pressed
{
KEYPORT = 0xfe; //Detect the first line
if(0xfe != KEYPORT)
{
keyvalue = KEYPORT;
keyvalue &= 0xf0; //Filter interference
keyvalue += 0x0e; //Filter interference
while(0xfe != KEYPORT);
delay_ms(10); //debounce
while(0xfe != KEYPORT);
return keyvalue;
}
KEYPORT = 0xfd; //Detect the second line
if(0xfd != KEYPORT)
{
keyvalue = KEYPORT;
keyvalue &= 0xf0; //Filter interference
keyvalue += 0x0d; //Filter interference
while(0xfd != KEYPORT);
delay_ms(10); //debounce
while(0xfd != KEYPORT);
return keyvalue;
}
KEYPORT = 0xfb; //Detect the third line
if(0xfb != KEYPORT)
{
keyvalue = KEYPORT;
keyvalue &= 0xf0; //Filter interference
keyvalue += 0x0b; //Filter interference
while(0xfb != KEYPORT);
delay_ms(10); //debounce
while(0xfb != KEYPORT);
return keyvalue;
}
KEYPORT = 0xf7; //Detect the fourth line
if(0xf7 != KEYPORT)
{
keyvalue = KEYPORT;
keyvalue &= 0xf0; //Filter interference
keyvalue += 0x07; //Filter interference
while(0xf7 != KEYPORT);
delay_ms(10); //debounce
while(0xf7 != KEYPORT);
return keyvalue;
}
}
}
return 0xff;
}
/*=====================================================
Key value processing function, returns the scan key value
======================================================*/
unsigned char key_pro(void)
{
unsigned char keynum;
keynum = key_scan();
/*Press the corresponding key to display the corresponding code value*/
switch(keynum)
{
case 0x7e:
{
return 0; //0
break;
}
case 0xbe:
{
return 1; //1
break;
}
case 0xde:
{
return 2; //2
break;
}
case 0xee:
{
return 3; //3
break;
}
case 0x7d:
{
return 4; //4
break;
}
case 0xbd:
{
return 5; //5
break;
}
case 0xdd:
{
return 6; //6
break;
}
case 0xed:
{
return 7; //7
break;
}
case 0x7b:
{
return 8; //8
break;
}
case 0xbb:
{
return 9; //9
break;
}
case 0xdb:
{
return 10; //10
break;
}
case 0xeb:
{
return 11; //11
break;
}
case 0x77:
{
return 12; //12
break;
}
case 0xb7:
{
return 13; //13
break;
}
case 0xd7:
{
return 14; //14
break;
}
case 0xe7:
{
return 15; //15
break;
}
default:
{
return 0xff;
break;
}
}
}
Previous article:MCU - Serial Port - Code
Next article:51 single chip microcomputer LCD code
- Popular Resources
- Popular amplifiers
- Enter the Matrix MS-DOS screensaver.Sample of using bios functions (by int 10h) for text data out
- Multi-channel pressure measuring instrument based on C8051F020 single chip microcomputer
- Design of automatic player for work and rest signal based on 51 single chip microcomputer
- AVR243 Matrix Keyboard Decoder
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EEWORLD University Hall----Texas Instruments field transmitter output interface/fieldbus solution
- Design of Portable Weather Instrument Based on MSP430 Microcontroller
- EEWORLD University ---- Top 5 Simple Electronic projects
- Thank you for being here, thank you EEWORLD Admin-okhxyyo and Orange Kai
- FPGA Design 5 Basic Skills.pdf
- What information do I need to provide for FCC certification of Bluetooth headsets?
- Recommended solutions to reduce Wi-Fi interference
- The MCU cannot run in DC-DC mode of BLUENRG-1
- micropython update: 2020.7
- Disassembling AirTags: The coil, magnet and diaphragm in the ring-shaped motherboard work together, and the body is the speaker