I inherited a physical product that needs to function like this using an 8051 in STOP mode. My user manual is a little light on STOP mode, but I can't get this to work, does someone who has used 8051s can weigh in on this?

Desired Actions

Note: Button A is an external interrupt.

1)Hold down Button A, for five seconds. Poll Button A every 5ms. After five seconds of polling, call the STOP(); macro. System shuts down.

2)While system is in STOP mode, press Button A and and system turns back on.

The problem I have is that when I hold down Button A for 5 seconds, it triggers the STOP mode. But instantly the system bounces out of STOP mode because Button A is still held down.

The datasheet (sketchball Asian 8051 MCU...) is not clear on the wake-up behavior. In one place it says any input from any from anything on port 1 or port 0 will wake up the MCU from STOP mode. That's not true.

It also suggests that the external interrupts can wake up the MCU. That seems to be true, and explains why STOP mode isn't "sticking" when I use Button A. If I switch the polling to Button B, a non-external interrupt button, the polling method works and the system goes to STOP mode.

What is strange with that behavior is that the Button A external interrupt is not enabled! Global interrupts are enabled, but not any external interrupts. The behavior is really odd.

Is there some way I could use Button A to trigger the STOP mode, but not have it immediately trigger an external interrupt and pull the system out of STOP mode?

(This was not a system issue with a PIC in an earlier design since it was polling buttons using some kind of deep-sleep watchdog type timer... sketchball Asian 8051 has no such feature).


Even though the datasheet does not state it, it looks like the watchdog timer and internal low power clock keep running in STOP mode. There may be a way to jigger some variables to keep the system in STOP even when it is being retriggered.


I could enter STOP mode, when the button is held for five seconds and then released. That would work, but requires a product manual rewrite.


Triggering the STOP mode on the button release works well. One thing that is not ideal is that you end up having to spoof that the unit is on/off, so the code logic is that you hold Button A for five seconds, at five seconds the display turns off BUT the unit is actually still running. It appears to be off, but when you release the button the unit actually goes off.

There ends up being a lot of code logic behind the scenes to handle all the edge cases. Like if someone taps the Button A, once it is off, but doesn't hold it down for 5 seconds. You need to capture that and shut the system down again.


1 Answer 1


You have a to do a little more work here. First off it would be needed to detect when the switch has been pressed for "at least 5 seconds". But before you trigger the STOP event you will need to poll for the switch being released. Make sure to poll for the released state properly so that you filter out any possible switch contact bounce that can occur as the switch is released. If you do not filter properly the switch bounce can come right back and trigger the WAKE back up interrupt trigger. You could even be rather conservative and filter for the switch release for as much as a quarter of a second.

One additional thing to consider is to investigate if the WAKE interrupt condition can be turned off most of the time and only armed when you have fully polled for the released switch state.

  • \$\begingroup\$ I've got the 5 second polling and debouncing completed. That's a good idea on the release, to trigger the STOP mode. It's a little different from how the old product works, but I think that would actually work with these 8051s! I have it on the 5 second poll occurring, not the release. One thing that is throwing me is that the external interrupts for Button A is not enabled, but it wakes the MCU from STOP. But if I turn off the global interrupt enable, than I can't wake the MCU from STOP with button A. I'm hoping the timer interrupts are running in STOP, to poll the button back on. \$\endgroup\$
    – Leroy105
    Commented Nov 6, 2017 at 0:08
  • \$\begingroup\$ @Leroy105 - Make sure to poll the button release before you go to the stop state. It should not be necessary to poll anything for the WAKE up condition because any first contact of the subsequent button press will effect the wake condition. Once the software restarts on the WAKE you can take whatever action is necessary to ignore/disable/use the switch. \$\endgroup\$ Commented Nov 6, 2017 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.