Startup and shutdown implementation method based on single-chip microcomputer
By using a microcontroller-based power-on/off control module and intelligent adjustment module, the problems of misoperation and hardware damage during the power-on/off process of electronic devices are solved. This enables the safe shutdown and low-energy operation of the equipment according to the user's intention, improving the ease of operation and the adaptability of the equipment.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NAGASOFT
- Filing Date
- 2025-12-18
- Publication Date
- 2026-04-21
AI Technical Summary
In the existing technology, the power-on and power-off process of electronic devices is prone to misoperation, and there is a lack of effective hardware reset methods in the event of software failure or system crash, which leads to hardware damage and system instability.
A microcontroller-based power-on/off control module is adopted, combined with a low-power module, a user identification module, and an environmental perception module. The button signals are processed by a timer to achieve a deep sleep mode. The environmental sensor and wireless communication module are used for intelligent adjustment, and the operating mode is optimized by combining machine learning algorithms.
It effectively avoids accidental operation, ensures that the device is turned on and off according to the user's clear intention, reduces energy consumption, improves operational convenience and comfort, adjusts button habits through machine learning, optimizes operating modes to adapt to user needs, and ensures that the device can quickly recover when needed.
Smart Images

Figure CN121900822A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of power on / off technology, and more specifically to a power on / off implementation method based on a microcontroller. Background Technology
[0002] In today's digital age, electronic devices have become an indispensable part of our lives and work. Properly shutting down electronic devices is crucial for their safety. Firstly, it reduces accidental operation; secondly, it helps protect the hardware; and thirdly, it contributes to the stability of the system and software. To this end, we propose a microcontroller-based power-on / off implementation method. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this invention provides a microcontroller-based power-on / off implementation method, comprising: Power on / off control module S1: Obtains the current status of the device, records the time the button is pressed, and determines the function that differs between the current status of the device and the button press time. In the power off state, if no button is pressed within a certain period of time, the device enters deep sleep mode. Low-power module S2: In deep sleep mode, it monitors ambient light intensity and temperature data to intelligently adjust the device's wake-up frequency and power consumption mode, and combines with the wireless communication module to perform remote wake-up and control functions; User recognition module S3: Through different button combinations or long press durations, it enables personalized settings and operations for different users, and combined with the voice recognition module, it enables voice control power on / off functions; Environmental sensing module S4: Combines environmental sensors to automatically adjust the device's operating mode according to environmental conditions, and uses machine learning algorithms to adjust the device's operating mode according to the user's usage habits.
[0004] Furthermore, the function that differentiates between the current state of the device and the button press time includes: A1: Obtain the current device status. If the device is in the off state, detect whether the power button is pressed and detect the button press time. When the button press time reaches a certain time, the device is powered on and outputs a high level. A2: If the device is powered on, determine the button press time and set a time threshold. If the threshold is reached, reduce the output level and send a power-off message. If the button press time exceeds a certain value, power off directly. A3: Before acquiring the key signal, the key signal needs to be debouncing. The debouncing method is as follows: Configure a timer in the device and set an appropriate timing period; The button status is detected. When a button is pressed, a timer is started. In the timer interrupt service routine, the button status is detected again. If the button is still pressed when the timer overflows, the button is considered valid. If the button changes to the released state before the timer overflows, the button operation is ignored.
[0005] Furthermore, the condition of entering deep sleep mode if no key is pressed within a certain period of time includes: B1: In the power-off state, initialize the timer, set the timer interval to t seconds, and start the timer to begin counting; B2: Check the button status during each timer interrupt. If the button is pressed, reset the timer and restart the timing. If the button is not pressed, the timing continues. When the timer counts to T seconds, trigger the deep sleep mode. Where T is the deep sleep threshold.
[0006] Furthermore, the intelligent adjustment device's wake-up frequency and power consumption mode include, C1: In deep sleep mode, the ambient light intensity L and temperature Te data are periodically read through the environmental sensor module; C2: Calculate the new wake-up frequency f and power consumption mode P according to the formula; C3: Dynamically adjusts the device's wake-up frequency and power consumption mode; The formulas for calculating the wake-up frequency f and the power consumption mode P are as follows: ; ; in, This is the default wake-up frequency. The default ambient light intensity, Given the default ambient temperature, a and b is the adjustment coefficient of light intensity and temperature on the wake-up frequency, and c and d are the adjustment coefficients of light intensity and temperature on the power consumption mode.
[0007] Furthermore, the remote wake-up and control function includes: The wireless communication module periodically wakes up the device to receive remote control commands. If a remote wake-up command is received, the device is woken up; if other control commands are received, the commands are recorded and the device remains in sleep mode. If a remote wake-up command is received, the power management module is controlled to wake up the device; Based on the received control commands, perform the corresponding operations and provide feedback on the operation results.
[0008] Furthermore, the ability to personalize settings and operations for different users through different button combinations or long press durations includes: Define different case durations and combinations to correspond to different user settings and operations; Collect user key operation data, including key duration, key combination, and operation frequency, and store the operation frequency; Regularly analyze user operation data, calculate the average key press duration and combination, and automatically adjust the thresholds of key press duration and combination based on the analysis results to adapt to the user's operating habits; Machine learning algorithms are used to analyze user action data, and the key press duration and combination thresholds are dynamically adjusted based on the analysis results.
[0009] Furthermore, the method for dynamically adjusting the key press duration and the threshold of the combination is as follows: The collected data is cleaned to remove obvious errors and outliers, and the data is converted into a format suitable for machine learning algorithms. Calculate the average value μt and standard deviation σt of the key press duration, and calculate the frequency fc of each key press combination; The forest algorithm is used as a machine learning model. Historical data is used to train the model, and the model parameters are adjusted to improve prediction accuracy. Based on the model's prediction results, dynamically adjust the key press duration and the threshold for key combinations; The formula for calculating the key press duration and standard deviation is as follows: ; ; Where ti represents the duration of the i-th key press, and n is the number of operations; The formula for calculating the frequency of the key combination is: ; Where ci represents the i-th key combination, and m is the number of combinations.
[0010] Furthermore, adjusting the device's operating mode according to the user's usage habits includes: Collect environmental sensor data, clean and preprocess the collected data, and acquire user operation data; Extract features related to environmental conditions and user actions, and use these features as input to the machine learning model; A neural network model is established, and the extracted environmental conditions and user operation-related features are input into the neural network model for training. The model parameters are adjusted to improve prediction accuracy, and the operating mode of the device is dynamically adjusted based on the prediction results of the model. During equipment operation, user operation data and environmental sensor data are continuously collected, and the model is updated regularly. Based on the latest model prediction results, the equipment's operating mode is adjusted in real time to adapt to dynamic changes in users and environmental conditions.
[0011] The beneficial effects of this invention are reflected in: 1. The long-press design (e.g., pressing and holding for more than 3 seconds) effectively prevents accidental operation, ensuring the router only powers on and off when the user explicitly intends to. When the router experiences software malfunctions, crashes, or network anomalies, the long-press forced shutdown function acts as a hardware-level reset, quickly restarting the device and preventing damage to the hardware from frequent power plugging and unplugging. During a long-press shutdown, the router can trigger an internal safe shutdown process, reducing hardware and data risks. By automatically adjusting the operating mode, the device can better meet the user's personalized needs, improving operational convenience and comfort. Optimizing the operating mode based on environmental conditions and user habits, the device can reduce energy consumption while maintaining performance. In the shutdown state, it can automatically enter a deep sleep mode, reducing power consumption. Power consumption is managed through timers and key interrupts. The device can enter a deep sleep mode while retaining wake-up functionality, ensuring rapid resumption of operation when needed. By defining different key durations and combinations to correspond to different user settings and operations, user operation data is analyzed regularly to calculate the average key duration and combination. Machine learning algorithms are used to analyze user operation data, and the thresholds for key duration and combination are dynamically adjusted based on the analysis results. This improves user comfort and ensures smooth operation. The model is also updated regularly to adjust the device's operating mode in real time based on the latest model predictions. The operating mode is optimized according to environmental conditions and user habits, enabling the device to reduce energy consumption while maintaining performance. Attached Figure Description
[0012] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the accompanying drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. In all the drawings, similar elements or parts are generally identified by similar reference numerals. The elements or parts in the drawings are not necessarily drawn to scale.
[0013] Figure 1 This is a flowchart illustrating a microcontroller-based power-on / off implementation method according to the present invention. Detailed Implementation
[0014] The embodiments of the technical solution of the present invention will now be described in detail with reference to the accompanying drawings. These embodiments are merely illustrative of the technical solution of the present invention and are therefore intended to limit the scope of protection of the present invention.
[0015] It should be noted that, unless otherwise stated, the technical or scientific terms used in this application should have the ordinary meaning as understood by one of ordinary skill in the art to which this invention pertains.
[0016] like Figure 1 As shown, a method for implementing power on / off based on a microcontroller includes: Power on / off control module S1: Obtains the current status of the device, records the time the button is pressed, and determines the function that differs between the current status of the device and the button press time. In the power off state, if no button is pressed within a certain period of time, the device enters deep sleep mode. Low-power module S2: In deep sleep mode, it monitors ambient light intensity and temperature data to intelligently adjust the device's wake-up frequency and power consumption mode, and combines with the wireless communication module to perform remote wake-up and control functions; User recognition module S3: Through different button combinations or long press durations, it enables personalized settings and operations for different users, and combined with the voice recognition module, it enables voice control power on / off functions; Environmental sensing module S4: Combines environmental sensors to automatically adjust the device's operating mode according to environmental conditions, and uses machine learning algorithms to adjust the device's operating mode according to the user's usage habits; S5: After the movie ends, the edge node uploads the playback progress, rating, and audio EQ preferences to the cloud. The cloud updates the user profile and issues a new content recommendation list. The edge node cleans up the cold movie segments according to the LRU policy and initiates a P2P mutual assistance caching request to the neighboring family nodes to achieve community-level content distribution.
[0017] In this embodiment, the function that differentiates between the current state of the device and the button press time includes: A1: Obtain the current device status. If the device is in the off state, detect whether the power button is pressed and detect the button press time. When the button press time reaches a certain time, the device is powered on and outputs a high level. A2: If the device is powered on, determine the button press time and set a time threshold. If the threshold is reached, reduce the output level and send a power-off message. If the button press time exceeds a certain value, power off directly. A3: Before acquiring the key signal, the key signal needs to be debouncing. The debouncing method is as follows: Configure a timer in the device and set an appropriate timing period; The button status is detected. When a button is pressed, a timer is started. In the timer interrupt service routine, the button status is detected again. If the button is still pressed when the timer overflows, the button is considered valid. If the button changes to the released state before the timer overflows, the button operation is ignored.
[0018] It should be noted that the power supply is controlled by the PA4 pin, the PA6 pin is configured as a status indicator pin to indicate the power-on status of the device, the PA2 and PA3 pins are configured as serial communication pins to send power-off information, and the PA5 pin is configured as an input pin to receive the power-on indication signal from the host computer.
[0019] In this embodiment, the entry into deep sleep mode when no key is pressed within a certain period of time includes: B1: In the power-off state, initialize the timer, set the timer interval to t seconds, and start the timer to begin counting; B2: Check the button status during each timer interrupt. If the button is pressed, reset the timer and restart the timing. If the button is not pressed, the timing continues. When the timer counts to T seconds, trigger the deep sleep mode. Where T is the deep sleep threshold.
[0020] In this embodiment, the intelligent adjustment of the device's wake-up frequency and power consumption mode includes, C1: In deep sleep mode, the ambient light intensity L and temperature Te data are periodically read through the environmental sensor module; C2: Calculate the new wake-up frequency f and power consumption mode P according to the formula; C3: Dynamically adjusts the device's wake-up frequency and power consumption mode; The formulas for calculating the wake-up frequency f and the power consumption mode P are as follows: ; ; in, This is the default wake-up frequency. The default ambient light intensity, Given the default ambient temperature, a and b is the adjustment coefficient of light intensity and temperature on the wake-up frequency, and c and d are the adjustment coefficients of light intensity and temperature on the power consumption mode.
[0021] For example, if the model predicts that users tend to press keys for shorter durations, the threshold for key duration is lowered; if users frequently use a particular key combination, the threshold for that combination is adjusted.
[0022] In this embodiment, the remote wake-up and control function includes: The wireless communication module periodically wakes up the device to receive remote control commands. If a remote wake-up command is received, the device is woken up; if other control commands are received, the commands are recorded and the device remains in sleep mode. If a remote wake-up command is received, the power management module is controlled to wake up the device; Based on the received control commands, perform the corresponding operations and provide feedback on the operation results.
[0023] In this embodiment, the method of enabling personalized settings and operations for different users through different button combinations or long press durations includes: Define different case durations and combinations to correspond to different user settings and operations; Collect user key operation data, including key duration, key combination, and operation frequency, and store the operation frequency; Regularly analyze user operation data, calculate the average key press duration and combination, and automatically adjust the thresholds of key press duration and combination based on the analysis results to adapt to the user's operating habits; Machine learning algorithms are used to analyze user action data, and the key press duration and combination thresholds are dynamically adjusted based on the analysis results.
[0024] In this embodiment, the method for dynamically adjusting the threshold of the key press duration and combination is as follows: The collected data is cleaned to remove obvious errors and outliers, and the data is converted into a format suitable for machine learning algorithms. Calculate the average value μt and standard deviation σt of the key press duration, and calculate the frequency fc of each key press combination; The forest algorithm is used as a machine learning model. Historical data is used to train the model, and the model parameters are adjusted to improve prediction accuracy. Based on the model's prediction results, dynamically adjust the key press duration and the threshold for key combinations; The formula for calculating the key press duration and standard deviation is as follows: ; ; Where ti represents the duration of the i-th key press, and n is the number of operations; The formula for calculating the frequency of the key combination is: ; Where ci represents the i-th key combination, and m is the number of combinations.
[0025] In this embodiment, step 8, adjusting the device's operating mode according to the user's usage habits, includes: Collect environmental sensor data, clean and preprocess the collected data, and acquire user operation data; Extract features related to environmental conditions and user actions, and use these features as input to the machine learning model; A neural network model is established, and the extracted environmental conditions and user operation-related features are input into the neural network model for training. The model parameters are adjusted to improve prediction accuracy, and the operating mode of the device is dynamically adjusted based on the prediction results of the model. During equipment operation, user operation data and environmental sensor data are continuously collected, and the model is updated regularly. Based on the latest model prediction results, the equipment's operating mode is adjusted in real time to adapt to dynamic changes in user behavior and environmental conditions. Adjust power on / off strategy S: ; in, The default power-on / off policy is used. and This represents the default power-on and power-off time distribution, with e and f being adjustment coefficients.
[0026] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention, and they should all be covered within the scope of the claims and specification of the present invention.
Claims
1. A power-on / off implementation method based on a microcontroller, comprising a power-on / off control module S1, a low-power module S2, a user identification module S3, and an environment sensing module S4, characterized in that: Power on / off control module S1: Obtains the current status of the device, records the time the button is pressed, and determines the function that differs between the current status of the device and the button press time. In the power off state, if no button is pressed within a certain period of time, the device enters deep sleep mode. Low-power module S2: In deep sleep mode, it monitors ambient light intensity and temperature data to intelligently adjust the device's wake-up frequency and power consumption mode, and combines with the wireless communication module to perform remote wake-up and control functions; User recognition module S3: Through different button combinations or long press durations, it enables personalized settings and operations for different users, and combined with the voice recognition module, it enables voice control power on / off functions; Environmental sensing module S4: Combines environmental sensors to automatically adjust the device's operating mode according to environmental conditions, and uses machine learning algorithms to adjust the device's operating mode according to the user's usage habits.
2. The power-on / off method based on a microcontroller according to claim 1, characterized in that: The function that differentiates between the current state of the device and the button press time includes: A1: Obtain the current device status. If the device is in the off state, detect whether the power button is pressed and detect the button press time. When the button press time reaches a certain time, the device is powered on and outputs a high level. A2: If the device is powered on, determine the button press time and set a time threshold. If the threshold is reached, reduce the output level and send a power-off message. If the button press time exceeds a certain value, power off directly. A3: Before acquiring the key signal, the key signal needs to be debouncing. The debouncing method is as follows: Configure a timer in the device and set an appropriate timing period; The button status is detected. When a button is pressed, a timer is started. In the timer interrupt service routine, the button status is detected again. If the button is still pressed when the timer overflows, the button is considered valid. If the button changes to the released state before the timer overflows, the button operation is ignored.
3. The power-on / off method based on a microcontroller according to claim 2, characterized in that: The condition of entering deep sleep mode if no key is pressed within a certain period of time includes: B1: In the power-off state, initialize the timer, set the timer interval to t seconds, and start the timer to begin counting; B2: Check the button status during each timer interrupt. If the button is pressed, reset the timer and restart the timing. If the button is not pressed, the timing continues. When the timer counts to T seconds, trigger the deep sleep mode. Where T is the deep sleep threshold.
4. The power-on / off implementation method based on a microcontroller according to claim 3, characterized in that: The intelligent adjustment device adjusts its wake-up frequency and power consumption mode. include, C1: In deep sleep mode, the ambient light intensity L and temperature Te data are periodically read through the environmental sensor module; C2: Calculate the new wake-up frequency f and power consumption mode P according to the formula; C3: Dynamically adjusts the device's wake-up frequency and power consumption mode; The formulas for calculating the wake-up frequency f and the power consumption mode P are as follows: ; ; in, This is the default wake-up frequency. The default ambient light intensity, Given the default ambient temperature, a and b is the adjustment coefficient of light intensity and temperature on the wake-up frequency, and c and d are the adjustment coefficients of light intensity and temperature on the power consumption mode.
5. The power-on / off method based on a microcontroller according to claim 4, characterized in that: The remote wake-up and control functions include: The wireless communication module periodically wakes up the device to receive remote control commands. If a remote wake-up command is received, the device is woken up; if other control commands are received, the commands are recorded and the device remains in sleep mode. If a remote wake-up command is received, the power management module is controlled to wake up the device; Based on the received control commands, perform the corresponding operations and provide feedback on the operation results.
6. The power-on / off implementation method based on a microcontroller according to claim 5, characterized in that: The method of enabling personalized settings and operations for different users through different button combinations or long press durations includes: Define different case durations and combinations to correspond to different user settings and operations; Collect user key operation data, including key duration, key combination, and operation frequency, and store the operation frequency; Regularly analyze user operation data, calculate the average key press duration and combination, and automatically adjust the thresholds of key press duration and combination based on the analysis results to adapt to the user's operating habits; Machine learning algorithms are used to analyze user action data, and the key press duration and combination thresholds are dynamically adjusted based on the analysis results.
7. The power-on / off implementation method based on a microcontroller according to claim 6, characterized in that: The method for dynamically adjusting the key press duration and the threshold of the combination is as follows: The collected data is cleaned to remove obvious errors and outliers, and the data is converted into a format suitable for machine learning algorithms. Calculate the average value μt and standard deviation σt of the key press duration, and calculate the frequency fc of each key press combination; The forest algorithm is used as a machine learning model. Historical data is used to train the model, and the model parameters are adjusted to improve prediction accuracy. Based on the model's prediction results, dynamically adjust the key press duration and the threshold for key combinations; The formula for calculating the key press duration and standard deviation is as follows: ; ; Where ti represents the duration of the i-th key press, and n is the number of operations; The formula for calculating the frequency of the key combination is: ; Where ci represents the i-th key combination, and m is the number of combinations.
8. The power-on / off implementation method based on a microcontroller according to claim 7, characterized in that: The method of adjusting the device's operating mode according to the user's usage habits includes: Collect environmental sensor data, clean and preprocess the collected data, and acquire user operation data; Extract features related to environmental conditions and user actions, and use these features as input to the machine learning model; A neural network model is established, and the extracted environmental conditions and user operation-related features are input into the neural network model for training. The model parameters are adjusted to improve prediction accuracy, and the operating mode of the device is dynamically adjusted based on the prediction results of the model. During equipment operation, user operation data and environmental sensor data are continuously collected, and the model is updated regularly. Based on the latest model prediction results, the equipment's operating mode is adjusted in real time to adapt to dynamic changes in users and environmental conditions.