uchar code KEY_TABLE[] =
{
0x77,0xB7,0xD7,0xE7
0x7B,0xBB,0xDB,0xEB
0x7D,0xBD,0xDD,0xED
0x7E,0xBE,0xDE,0xEE
}; //The upper four bits are the columns, the lower four bits are the rows
uchar code TABLE[] =
{
'1', '2', '3',
'4', '5', '6',
'7', '8', '9',
'C', '0', 'A',
};
char key_scan()
{
uchar temp, key, i;
P1 = 0xf0; //1111 0000
//First scan the column and determine the column
//Set the high four bits of the column pins to high level, and the low four bits of the row pins to low level. When the button is pressed, it will be pulled low.
if (P1 != 0xf0)
{
delay_ms(10);
if (P1!= 0xf0)
{
temp = P1; //temp exists after pressing
P1 = 0x0f;
// Scan the line later to determine which line
//Set the row pin, the lower four bits, to high level, and the column pin, the upper four bits, to low level. When the button is pressed, it will be pulled low.
key = temp | P1;
//Or the rows and columns, the position where the upper four bits are 0 is the column, and the position where the lower four bits are 0 is the row
for (i = 0; i < 12; ++i) //Find the corresponding key and assign the corresponding character
if (key == KEY_TABLE[i])
break;
return TABLE[i];
}
}
else
return 0x00;
}
Previous article:Use 51 single chip microcomputer to output PWM to control the servo
Next article:51 MCU nrf24l01 transceiver
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- How to tell how many layers a PCB has
- Showing off the LTC3588 Energy Harvesting Development Board
- [LSM6DSOX finite state machine routine learning 2]--How to use finite state machine programming
- FPGA Implementation of DMA Transfer Mode of PCI Interface
- The relationship between capacitance and frequency
- 【MYS-8MMX】Part 4: Bluetooth speaker plays music
- RS485 chip SN75LBC184 burned out
- Simple smart home system design based on Arduino and OneNET cloud platform
- Programmable Power Supply Technology and Application Guide (6) - Reducing Noise from Power Supply to DUT
- 【GD32L233C-START Review】- Summary of the initial review