#define scan_key_port P3
uchar key_scan()
{
uchar sccode,recode;
uchar key_value;
scan_key_port=0xf0; /* Send all "0" row scan code, column line input*/
if((scan_key_port&0xf0)!=0xf0) /* If a key is pressed*/
{
delay_1ms(1); /* Delay to de-bounce*/
if((scan_key_port&0xf0)!=0xf0) /* If a key is pressed*/
{
sccode=0xfe; /* Scan the initial value line by line*/
while((sccode&0x10)!=0)
{
scan_key_port=sccode; /* Output row scan code*/
if((scan_key_port&0xf0)!=0xf0) /* A key is pressed in this line*/
{
recode=(scan_key_port&0xf0)|0x0f;
key_value=(~sccode)+(~recode);/* return the signature*/
}
else sccode=(sccode<<1)|0x01; /* shift the row scan one position to the left*/
}
}
}
else { //if no key is pressed
scan_key_port = 0xff;
return (0);
}
scan_key_port = 0xff; /*release the key scan port*/
switch(key_value){ /*display the silk screen corresponding to the key
*/
case 0x11:
return('0');
case 0x12:
return('1');
case 0x14:
return('2');
case 0x21:
return('3');
case 0x22:
return('4');
case 0x24:
return('5');
case 0x41:
return('6');
case 0x42:
return('7');
case 0x44:
return('8');
case 0x81:
return('9');
case 0x82:
return('A');
case 0x84:
return('B');
case 0x18:
return('C');
case 0x28:
return('D');
case 0x48:
return('E');
case 0x88:
return('F');
}
}
Previous article:LCD1602 four-bit bus attempt successful
Next article:1602 LCD perpetual calendar source program - with temperature, backlight, grayscale digital
- Popular Resources
- Popular amplifiers
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Experience in using HGI MCU - Avoid pitfalls
- How to choose between different chips in TI's Sub-1GHz product line?
- Power consumption test method for low power consumption devices
- EEWORLD University ---- Motor Control
- Using WS2812 on ESP32-S2-Saola-1
- Can the LF356 op amp amplify current without any peripheral devices?
- How to connect the freewheeling diode
- Online programming tool SplootCode Editor
- Detailed explanation of ADC of MSP430 microcontroller
- Component packaging,