A single chip computer power on / off circuit and method using a combination of hardware and software
By combining hardware and software, a microcontroller power-on/off circuit is developed. This circuit utilizes field-effect transistors and microcontroller ports to control power supply, solving the problems of complex and cumbersome operation associated with microcontroller power-on/off circuits and achieving a simplified microcontroller power-on/off solution.
Patent Information
- Application Number
- CN202010286243.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-04-13
- Publication Date
- 2024-11-15
- Estimated Expiration
- 2040-04-13
AI Technical Summary
Existing microcontroller power-on/off circuits are complex when using a single button, and cumbersome to operate and take up a lot of space when using two buttons.
A microcontroller power-on/off circuit combining hardware and software is used. It utilizes field-effect transistors and the input/output ports of the microcontroller to control the power supply. The software detects the button status and controls the conduction and cutoff of the field-effect transistors to realize the power-on/off of the microcontroller.
It simplifies the hardware circuitry, avoids cumbersome operation and space occupation, and enables easy power-on and power-off of the microcontroller.
Smart Images

Figure CN111273757B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a single chip microcomputer power on / off circuit and method, and more specifically, to a single chip microcomputer power on / off circuit and method using a combination of hardware and software. Background Art
[0002] Many electronic devices using single-chip microcomputers require a power on / off function to achieve safety and energy saving. The power on / off function can be realized by two buttons or one button. The advantage of one button is that it is easy to operate and saves space. The power on / off function of one button can be realized by a bistable trigger, but the circuit is more complicated. The present invention adopts a method combining hardware and software to simplify the hardware circuit. Summary of the invention
[0003] In order to overcome the disadvantages of the above technical problems, the present invention provides a single chip microcomputer power on / off circuit and method using a combination of hardware and software.
[0004] The single-chip computer switch circuit of the present invention adopts the combination of hardware and software, comprises a single-chip computer, a button K1, a positive power supply P1 and field effect tubes Q1, Q2, Q3 and Q4, one end of the button K1 is connected to the positive power supply P1, and the other end is connected to the power supply ground via resistors R3 and R4 in sequence; the characteristics are: the power connection port VCC of the single-chip computer is connected to the drain of the field effect tube Q1, and the source of Q1 is connected to its gate via resistor R1; the gates of the field effect tubes Q4 and Q2 are both connected to the connection between R3 and R4, the sources of Q4 and Q2 are both connected to the power supply ground, the drain of Q4 is connected to the port Pm.y defined as input on the single-chip computer; the gate of the field effect tube Q3 is connected to the port Pn.y defined as output on the single-chip computer via resistor R5, the gate of Q3 is grounded via resistor R6, the source of Q3 is grounded, the drain of Q3 is connected to the gate of Q1 via resistor R2, and the drain of Q3 is connected to the drain of Q2.
[0005] The single-chip microcomputer switch circuit of the present invention adopts a combination of hardware and software. The single-chip microcomputer adopts a chip of model MSP430F5438, the key K1 is a contact key, Q2, Q3 and Q4 adopt N-channel field effect tubes of model AO3416, and Q1 adopts a P-channel field effect tube of model AO3415.
[0006] The power on / off method of the single chip microcomputer power on / off circuit using a combination of hardware and software of the present invention is characterized by being implemented by the following steps:
[0007] a). Press the button to turn on the machine. When the machine is turned on, press the button K1. After the button K1 is pressed, the gate voltage of the field effect tubes Q2 and Q4 changes from a low level to a high level, Q2 and Q4 are turned on, and Q2 turns on, causing the gate of Q1 to change to a low level, causing Q1 to be turned on. After Q1 is turned on, the positive electrode of the power supply P1 supplies power to the VCC port of the single-chip computer, and the button status detection program in the single-chip computer runs, and step b) is executed;
[0008] b). Low level detection, the MCU detects the state of the input port Pm.y. If it is low level and the low level state is maintained for longer than the set time, it means that the time Q4 drain maintains the low level exceeds the set value, and the button K1 is pressed for effective power-on, not button jitter; execute step c);
[0009] c). Maintain the power-on state. When the key K1 is detected to be effectively pressed through the Pm.y port in step b), a high level is output through the output port Pn.x to turn on Q3, maintain the gate of Q1 in a low level state, and ensure that the positive electrode of the power supply P1 continues to supply power to the single-chip microcomputer; thereafter, after the key K1 is released, the positive electrode of the power supply P1 still supplies power to the single-chip microcomputer;
[0010] d). Press the button to shut down. When the MCU is in operation, if the button K1 is pressed, the low voltage of the drain of Q4 is detected through the port Pm.y. If the low voltage state lasts longer than the set time, it indicates that the shutdown button is pressed effectively. This outputs a low level through the output port Pn.x, turning off Q3 and turning the gate of Q1 to a high level and turning it off. The positive power supply P1 disconnects the power supply to the MCU to shut down the MCU.
[0011] In the on / off method of the single-chip microcomputer on / off circuit using a combination of hardware and software of the present invention, the setting time in step b) and step d) is 50 ms.
[0012] The beneficial effects of the present invention are as follows: the single-chip computer power on / off circuit and method of the present invention adopts a combination of hardware and software, the hardware part is composed of a button K1 and field effect tubes Q1, Q2, Q3, and Q4, the positive electrode P1 of the power supply supplies power to the single-chip computer through Q1, the positive electrode P1 of the power supply is connected to the gates of Q2 and Q4 after passing through the button K1, the gate of Q1 is connected to the drains of Q2 and Q3, the input port Pm.y and the output port Pn.x of the single-chip computer are respectively connected to the drain of Q4 and the gate of Q3, so that when the computer is turned on, after the button K1 is pressed, the single-chip computer is powered on, and the button detection program runs. If the low voltage maintenance time of the drain of Q4 detected by Pm.y exceeds the set time (50ms, anti-shake), it is considered that the power-on button is valid, and a high level is output through the output port Pn.x to turn on Q3, maintain Q1 on, and keep the single-chip computer in a running state. Similarly, when the single-chip microcomputer is in operation and the button K1 is pressed, if it is detected that Q4 is at a low level and maintains the set time (50ms), the shutdown button is considered to be valid, Pn.x outputs a low level to turn off Q3, Q1 is turned off to stop the power supply to the single-chip microcomputer, and the single-chip microcomputer is shut down. The single-chip microcomputer power on and off circuit and method of the present invention adopts a combination of hardware and software, solves the problem of complex circuits when only one button is used to power on and off, and avoids the problem of cumbersome operation and large space occupation when two buttons are used, with significant beneficial effects and suitable for application promotion. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 A circuit diagram of a single-chip microcomputer power on / off circuit that combines hardware and software according to the present invention;
[0014] Figure 2 A circuit diagram of a specific embodiment of the present invention.
[0015] In the figure: 1 single chip microcomputer, 2 button K1, 3 positive power supply P1, 4 field effect transistor Q1, 5 field effect transistor Q2, 6 field effect transistor Q3, 7 field effect transistor Q4. DETAILED DESCRIPTION
[0016] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0017] like Figure 1As shown, a circuit diagram of a single-chip microcomputer switch circuit combining hardware and software of the present invention is given, which consists of a single-chip microcomputer 1, a button K1, a positive power supply P1, and four field effect transistors Q1, Q2, Q3 and Q4. The single-chip microcomputer 1 shown has the functions of signal acquisition, data calculation and control output. The button K1 is a contact button, which is turned on when pressed and disconnected after being released. Q1 is a P-channel field effect transistor, and Q2, Q3 and Q4 are all N-channel field effect transistors. The positive power supply P1 is connected to the source of Q1, and the power supply terminal of the single-chip microcomputer 1 is connected to the drain of Q1. In this way, when Q1 is turned on, the single-chip microcomputer 1 can be powered.
[0018] One end of the button K1 is connected to the positive pole of the power supply P1, and the other end is grounded via resistors R3 and R4 in sequence. The gates of Q2 and Q4 are connected to the connection between resistors R3 and R4, the sources of Q2 and Q4 are grounded, and the drain of Q4 is connected to the Pm.y port defined as input on the microcontroller 1, so that the microcontroller 1 can detect the state of the drain end of Q4 through the port Pm.y.
[0019] The gate of Q1 is connected to its source through resistor R1, and the gate of Q1 is connected to the drains of Q2 and Q3 through resistor R2. In this way, when one of Q2 and Q3 is turned on, the gate voltage of Q1 will become low level, making Q1 turned on. The source of Q3 is grounded, the gate of Q3 is grounded through resistor R6, and the gate of Q3 is connected to the Pn.y port defined as output on the microcontroller 1 through resistor R5. When Q2 is in the off state, the microcontroller 1 outputs high and low levels through the Pn.y port, which can control the on and off of Q3, and then control the on and off of Q1, so as to realize the power supply and power off of the positive electrode of the power supply P1 to the microcontroller 1.
[0020] When in use, in the MCU shutdown state, press the button K1, the gates of Q2 and Q4 receive voltage, Q2 and Q4 are turned on, the gate voltage of Q1 drops, Q1 is turned on, the MCU gets power, and the MCU program starts running. After Q4 is turned on, its drain voltage becomes low level, and the MCU program detects this low level through the MCU DI pin Pm.y. If the low level time exceeds the set time, the MCU DO pin Pn.x output pin is high level, Q3 is turned on, and then the gate of Q1 is kept low level, so that Q1 remains in the open state. At this time, the MCU is in the power-on state. The MCU continues to detect the level of Pm.y. If the high level lasts for more than the set time, it enters the running state and completes the startup process. In the running state, the MCU detects the level of Pm.y. If the low level lasts for more than the set time, Pn.x is low level, and then Q3 is turned off. After that, if K1 is released, the power switch is turned off, and the MCU U1 loses power and shuts down.
[0021] like Figure 2As shown, a circuit diagram of a specific implementation of the present invention is given. The single-chip microcomputer uses MSP430F5438, the power supply uses 3.3V, the power switch tube Q1 uses P-channel field effect transistor AO3415, the other transistors use N-channel field effect transistors, the keys use 6x6x7 keys, the resistance values of R1, R4, and R6 are 100k ohms, and the resistance values of R2, R3, and R5 are 10k ohms. The software implementation method is as follows: define four variables status, key, keyTime, and keyLast and initialize them to 0, which respectively represent the program status, key status, key status duration, and last key status. Set the single-chip microcomputer timer to interrupt once every 10 milliseconds. Detect the key status and time in the timer interrupt service program. The program is as follows:
[0022] key=P1IN&2;
[0023] if ( key == keyLast )
[0024] keyTime++ ;
[0025] else
[0026] { keyTime = 0; keyLast = key}
[0027] In the main loop, the duration of the key state is detected. The program is as follows:
[0028] if ( status == 0 )
[0029] { if ( key == 0 && keyTime > 50 ) { P1OUT |= 1 ; status = 1 ;}}
[0030] else if ( status == 1 )
[0031] { if ( key != 0 && keyTime > 50 ) status = 2 ;}
[0032] else if ( status == 2 )
[0033] { if ( key == 0 && keyTime > 50 ) P1OUT &= ~1;}
[0034] The operator "|" represents the bitwise OR operation, "&" represents the bitwise AND operation, and "~" represents the NOT operation.
Claims
1. A single-chip microcomputer on / off circuit using a combination of hardware and software, comprising a single-chip microcomputer (1), a key K1 (2), a positive power supply P1 (3), and field effect transistors Q1, Q2, Q3, and Q4, wherein one end of the key K1 is connected to the positive power supply P1, and the other end is connected to the power supply ground via resistors R3 and R4 in sequence; characterized in that: The power connection port VCC of the single-chip computer is connected to the drain of the field effect tube Q1, and the source of Q1 is connected to its gate via the resistor R1; the gates of the field effect tubes Q4 and Q2 are both connected to the connection between R3 and R4, the sources of Q4 and Q2 are both connected to the power ground, and the drain of Q4 is connected to the port Pm.y defined as the input on the single-chip computer; the gate of the field effect tube Q3 is connected to the port Pn.y defined as the output on the single-chip computer via the resistor R5, the gate of Q3 is grounded via the resistor R6, the source of Q3 is grounded, the drain of Q3 is connected to the gate of Q1 via the resistor R2, and the drain of Q3 is connected to the drain of Q2; The microcontroller uses MSP430F5438, the power supply uses 3.3V, the power switch tube Q1 uses P-channel field effect transistor AO3415, the other transistors use N-channel field effect transistors, the buttons use 6x6x7 buttons, the resistance values of R1, R4, and R6 are 100k ohms, and the resistance values of R2, R3, and R5 are 10k ohms.
2. A method for turning on and off a single-chip computer turning on and off a circuit combining hardware and software according to claim 1, characterized in that: This is accomplished by following these steps: a). Press the button to turn on the machine. When the machine is turned on, press the button K1. After the button K1 is pressed, the gate voltage of the field effect tubes Q2 and Q4 changes from a low level to a high level, Q2 and Q4 are turned on, and Q2 turns on, causing the gate of Q1 to change to a low level, causing Q1 to be turned on. After Q1 is turned on, the positive electrode of the power supply P1 supplies power to the VCC port of the single-chip computer, and the button status detection program in the single-chip computer runs, and step b) is executed; b). Low level detection, the MCU detects the state of the input port Pm.y. If it is low level and the low level state is maintained for longer than the set time, it means that the time Q4 drain maintains the low level exceeds the set value, and the button K1 is pressed for effective power-on, not button jitter; execute step c); c). Maintain the power-on state. When the key K1 is detected to be effectively pressed through the Pm.y port in step b), a high level is output through the output port Pn.x to turn on Q3, maintain the gate of Q1 in a low level state, and ensure that the positive electrode of the power supply P1 continues to supply power to the single-chip microcomputer; thereafter, after the key K1 is released, the positive electrode of the power supply P1 still supplies power to the single-chip microcomputer; d). Press the button to shut down. When the MCU is in operation, if the button K1 is pressed, the low voltage of the drain of Q4 is detected through the port Pm.y. If the low voltage state lasts longer than the set time, it indicates that the shutdown button is pressed effectively. This outputs a low level through the output port Pn.x, turning off Q3 and turning the gate of Q1 to a high level and turning it off. The positive power supply P1 disconnects the power supply to the MCU to shut down the MCU.
3. The method for turning on and off a single chip microcomputer by combining hardware and software according to claim 2, characterized in that: The setting time in step b) and step d) is 50 ms.
