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).
UPDATE
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.
SUGGESTED SOLUTION
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.
FINAL CODE
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.