How to pause and resume with one key in 51 MCU? Need a programming idea

Reported answer
How to pause and resume with one key in 51 MCU? Need a programming idea
Ask online customer service
Scan the code to ask online customer service
  • Number of answers

    five

  • Number of browses

    10,426

5 answers Default sorting
  • Default sorting
  • Sort by time

Adopted
There are the following situations:
1. Cycle query key. When you press the key for the first time, you will enter the first layer of circular query statement and execute recovery. Do not jump out of the layer cycle, continue to query the key. When the time is pressed for the second time, it will enter the second layer of loop query statement, and execution will be suspended. The cycle ends. If you want to pause and resume repeatedly, add another layer of while (1) like endless loop outside, and repeatedly execute its internal two-layer loop query statements.
2. Use a flag variable to remember the status of keys. Initialize to values, such as "Pause". After pressing the key, check the flag variable. If it is "Pause", execute "Resume", and then change it to "Resume", indicating that the resume has been executed. vice versa.
3. Power failure pause. In this way, you need to press the key to trigger the CPU. Therefore, you need to press the key to connect to the external interrupt. The CPU can be resumed after the interruption. During the interruption, judge whether to power down the CPU.
Don't know if you can accept this method? Or use external interrupt. After this key triggers an interrupt, turn off all other interrupts, that is, EA=0 (it is better to remember EA with a variable to facilitate recovery), and then wait for the second press of this key in the interrupt to recover EA, and finally exit the interrupt.
cancel comment
It is recommended to suspend the power down mode
cancel comment
What do you mean by pause, the program does not perform other operations? If so, please continue to see
Set a flag. When the program always stops at this position or does not execute other programs, and this flag is set to 1, empty statements will be executed at this time; When the key is pressed, an interrupt is triggered to clear the flag.
cancel comment
Just use the 51 interrupt!
Your other 12 keys can also be processed by using interrupt. Just set the pause key to the highest level. In any case, the subprogram of the key will run when you press it again (note that the interrupt function should be turned off at this time, just to judge whether the pause key is pressed for the second time). If you press it, you can jump to the original position before the pause and start the interrupt!
See what that means!
cancel comment
Refer to:

C language is also available, just look in the space.
cancel comment
ZOL Q&A > USB drive > other > How to pause and resume with one key in 51 MCU? Need a programming idea

Ranking of popular USB flash drives

See more rankings>

report

Thank you for contributing to the harmony of the community. Please select the type of report

Reported successfully

It will be handled after verification
Thank you for your contribution to community harmony

Scan the code to participate in the trial of new products at 0 yuan
You can get the sheets and grand gifts on the top floor

 Scan and pay attention to us
Tips

Are you sure you want to cancel this registration and exit this activity?