Hi, without going into a lot of details, I'm trying to figure out how to write a routine that resembles the flow chart below.
I have one button connected to my circuit board that is used to turn-on and/or turn-off the power.
After the button is held down for 2 seconds I would like the routine to read EEPROM and determine if the value is "0". This would indicated the unit was previously off, as a result, write a "1" to eeprom. Conversely, if the value is "1", the unit was previously on, write a "0" to eeprom.
Note, the circuitry is configured in such a way that when the button is pressed it will energize the uC immediately so this routine can be carried out. (If the uC is already on, the routine will be triggered). I do have an "power enable pin" on the LDO that I will set depending on the reading from EEPROM (I believe with the K22F uC, this is called NVM?)