Copyright: 2013-07-27.version1.0
File name: key.c
Description: Self-made single key recognition to achieve repeated key function
Author:
Version: version1.0
Date: 2013.7.27
History: None
**************************************************************/
#include
sbit key=P0^0;
int num=0;
/****************************************************
Function: delay_press()
Description: The delay function when the key is pressed
Calls: None
Called By: key_test()
Table Accessed: None
Table Updated: None
Input: void
Output: None
Return: 1->press
0->release
Others: None
******************************************************/
int delay_press(void)
{
int press=1;
int i,j;
for(i=0;i<255;i++)
for(j=0;j<255;j++)
press=1;
press=0;
return press;
}
/****************************************************
Function: delay()
Description: Delay function
Calls: None
Called By: key_test()
Table Accessed: None
Table Updated: None
Input: void
Output: None
Return: void
Others: None
******************************************************/
void delay(void)
{
int i,j;
for(j=0;j<25;j++)
for(i=0;i<25;i++);
}
/********************************************************
Function: key_test()
Description: Single key recognition function
Calls: delay()
Called By: main()
Table Accessed: None
Table Updated: None
Input: void
Output: num, press the key once and num will increase by one
Return: void
Others: None
******************************************************/
void key_test(void)
{
if(!key)
{
delay();
if(!key)
{
num++;
if(num>255)
num=0;
}
}while(delay_press());
}
/*****************************************************
Function: main()
Description: The main function of the program
Calls: key_test()
Called By: None
Table Accessed: None
Table Updated: None
Input: void
Output: None
Return: void
Others: None
******************************************************/
void main(void)
{
//int i;
while(1)
{
key_test();
P2=~num;
}
}
Previous article:51 MCU simple control program for wireless module nRF24L01
Next article:Use 51 MCU buttons to set ZTW ESC
- 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
- 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
- Getting started with BIT_BAND (bit segment/bit band) and alias area in STM32
- [Xianji HPM6750 Review] RT-Thread SPI Driver and WiFi Networking
- In-depth analysis of the design of a dental chair control system based on ARM embedded technology
- Lithium battery charging and charging protection circuit
- Temperature transmitter hardware framework and schematic diagram
- Testing solutions for redundant link networks
- Key wireless technologies for 5G systems
- [NXP Rapid IoT Review] + Rapid IoT App Running Error
- What is the principle of touch switch?
- What is jitter and phase noise?