One of the key recognition methods
1. Each time switch SP1 is pressed in the experimental task
, the count value increases by 1, and its binary count value is displayed through P1.0 to P1.3 of the P1 port of the AT89S51 microcontroller.
2. Circuit schematic
Figure 4.8.1
3. Hardware connection on the system board
(1. Connect the P3.7/RD port in the "Single-chip Computer System" area to the SP1 port in the "Independent Keyboard" area;
(2. Connect the P1. The 0-P1.4 port is connected to the "L1-L8" port in the "Eight-way LED Indicator Module" area with an 8-core cable; the requirements are that P1.0 is connected to L1, P1.1 is connected to L2, and P1.2 Connected to L3, P1.3 is connected to L4.
4. Programming method
(1. In fact, it is a complete process from not pressing to pressing and releasing, that is, when we press a button Sometimes, we always hope that a certain command will be executed only once, and there should be no interference during the process of pressing the button, because if there is interference during the pressing process, it may cause a false trigger process. This is not what we want. wanted. So when the button is pressed,
Figure 4.8.2
needs to filter out the interference signals on our hands and the mechanical contact of the keys. Generally, we can use capacitors to filter out these interference signals, but in fact, it will increase the hardware cost and We don’t want the size of the hardware circuit. There must be a way to solve this problem. Therefore, we can use software filtering to remove these interference
signals. Generally speaking, when a button is pressed, it is always at the moment when it is pressed. There is a certain interference signal, and it basically enters a stable state after pressing it. The specific signal diagram of the whole process from pressing to releasing a button is shown in the figure above:
As can be seen from the figure, when we program the design, there is a delay of more than 5ms after the button is recognized and pressed, thus avoiding the problem of In the interference signal area, let's check again to see if the button has really been pressed. If it has been pressed, the output will definitely be low level. If the high level is detected at this time, it proves that it was caused by the interference signal. If there is a false trigger, the CPU will think it is a false trigger signal and abandon the key recognition process this time. Thereby improving the reliability of the system.
Since the command is required to be executed once every time it is pressed, the command will be executed again when the button is pressed again. Therefore, after the button is recognized, we can execute the command this time, so there must be a waiting button to release. The process, obviously the release process, is to restore it to a high level state.
(1. For the instruction of key recognition, we still choose the following instruction JB BIT. The REL instruction is used to detect whether BIT is high level. If BIT = 1, the program will turn to REL to execute the program, otherwise it will continue to execute the program downwards. . Or JNB BIT, the REL instruction is used to detect whether BIT is low level. If BIT = 0, the program will move to REL for execution, otherwise it will continue to execute the program
(2. But the key is pressed during the programming process. The block diagram of the recognition process is shown on the right:
Figure 4.8.3
5. Block diagram
Figure 4.8.4
6. Assembly source program
ORG 0
START: MOV R1, #00H; Initialize R1 to 0, indicating that counting starts from 0
MOV A, R1;
CPL A; Negate the instruction
MOV P1, A; Send the P1 port and display it on the LED
REL: JNB P3 .7, REL; Determine whether SP1 is pressed.
LCALL DELAY10MS; If pressed, delay about 10ms.
JNB P3.7, REL; Determine whether SP1 is really pressed.
INC R1; If pressed, proceed with key processing.
MOV A,R1; Add 1 to the count content and send it out to the P1 port by
CPL A; LED display
MOV P1,A;
JNB P3.7,$; Wait for SP1 to release
SJMP REL; Continue to scan the K1 button
DELAY10MS: MOV R6,# 20 ;Delay 10ms subroutine
L1: MOV R7,#248
DJNZ R7,$
DJNZ R6,L1
RET
END
7. C language source program
#include
unsigned char count;
void delay10ms(void)
{
unsigned char i,j;
for(i=20;i>0;i--)
for(j=248;j>0;j--);
}
void main(void)
{
while(1)
{
if(P3_7==0)
{
delay10ms();
if(P3_7==0)
{
count++;
if(count==16)
{
count=0;
}
P1=~count ;
while(P3_7==0);
}
}
}
}
Previous article:"Ding Dong" doorbell circuit design
Next article:STC microcontroller uses IAP technology to implement EEPROM design
- 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
- Made a progressive volume control circuit
- "Wanli" Raspberry Pi car open source sharing summary——lb8820265
- How to filter square waves into round ones?
- AutoChips AC7801x motor demo board review (Part 2): Development environment setup + lighting
- Two questions about single chip microcomputer
- SD boot and burning
- 6 protection functions of power amplifiers and common troubleshooting methods
- Design of single chip keyboard debounce
- Wireless secure communication terminal based on FPGA system on chip
- After cashing out 1.5 billion yuan, Mobike's post-80s founder left behind two unspoken rules for life