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.
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.
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!