Circuit and method for realizing infrared receiving detection and key detection pin multiplexing
By designing a circuit that reuses infrared receiving heads and keys in the embedded system, it is difficult to achieve the problem of limited MCU pin resources that are difficult to achieve infrared receiving and button detection, and realize the effective implementation of the function and the reduction of cost.
Patent Information
- Application Number
- CN202411476722.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-22
- Publication Date
- 2025-01-21
AI Technical Summary
In embedded systems, limited microcontroller (MCU) pin resources are difficult to achieve both infrared reception and key detection, resulting in resource exhaustion or the need to use more expensive MCUs.
By designing a circuit, using the pins of the infrared head and the pins of the keys to combine the pins management of the MCU and the control of LED lights to achieve the distinction and processing of infrared signals and keys.
Reduce the number of packaged pin pins, reduce the cost of the PCB board, and effectively realize the function of infrared receiving and button detection.
Smart Images

Figure CN119341540A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of chip applications, and in particular to a circuit and method for realizing pin multiplexing of infrared receiving detection and key detection. Background Art
[0002] In modern embedded systems, infrared reception and key detection are common functional requirements. These functions are often used in a variety of application scenarios such as remote controls, smart home devices, and consumer electronics. However, in actual design, how to efficiently utilize limited microcontroller (MCU) pin resources has become an important challenge.
[0003] The infrared receiving function is usually used to receive signals from remote controls or other infrared transmitting devices. Traditional infrared receiving modules require a dedicated MCU pin to read infrared signals. This pin is usually configured as input mode and detects the arrival of infrared signals through interrupts or polling. The key detection function is used to detect user input. A common implementation method is to connect the key to one or more pins of the MCU. These pins are usually configured as input mode and use internal pull-up or pull-down resistors to ensure that the pins maintain a stable level when no key is pressed.
[0004] In many embedded systems, especially those using small or low-cost MCUs, pin resources are very limited. For example, some small MCUs may have only 8 pins or less. In this case, occupying one pin for each function will quickly exhaust the available pin resources, resulting in the inability to implement more functions or the need to use a more expensive MCU. In order to add more functions, designers may have to choose an MCU with more pins, which not only increases cost, but also may increase the complexity of the design. Summary of the invention
[0005] The purpose of the present invention is to provide a circuit and method for realizing the multiplexing of infrared receiving detection and key detection pins, so as to solve the problems existing in the above-mentioned prior art.
[0006] To achieve the above object, the technical solution adopted by the present invention is: In a first aspect, the present invention provides a circuit for realizing pin multiplexing of infrared receiving detection and key detection, comprising: MCU, which has multiple sets of pins; The infrared receiving head has its pin 1 connected to VCC, and its pin 2 and the pin 2 of the MCU are connected to GND; A button, a first end of which and pin three of the infrared receiving head are connected to pin one of the MCU, a second end of the button is connected to a first end of a first resistor, and a second end of the first resistor is connected to GND.
[0007] In one possible implementation, it also includes: A first MOS tube, whose gate is connected to pin 6 of the MCU and whose source is connected to GND; A second resistor, a first end of which is connected to pin 6 of the MCU, and a second end of which is connected to GND; The LED-R lamp has a cathode connected to the drain of the first MOS tube, and an anode connected to VCC.
[0008] In one possible implementation, it also includes: A second MOS tube, a gate of which is connected to pin 4 of the MCU, and a source of which is connected to GND; A third resistor, a first end of which is connected to pin 4 of the MCU, and a second end of which is connected to GND; The LED-G lamp has a cathode connected to the drain of the second MOS tube, and an anode connected to VCC.
[0009] In one possible implementation, it also includes: A third MOS tube, whose gate is connected to pin 3 of the MCU and whose source is connected to GND; a fourth resistor, a first end of which is connected to pin 3 of the MCU, and a second end of which is connected to GND; The cathode of the LED-B lamp is connected to the drain of the third MOS tube, and the anode of the LED-B lamp is connected to VCC.
[0010] In one possible implementation, it also includes: A capacitor, a first end of which is connected to pin 5 of the MCU, and a second end of which is connected to GND.
[0011] In a second aspect, the present invention provides a method for realizing the multiplexing of infrared receiving detection and key detection pins, the method being applied to any circuit for realizing the multiplexing of infrared receiving detection and key detection pins as described above, the method comprising: In response to the MCU being powered on, the pin 1 of the MCU is set to the input mode, the internal pull-up resistor is turned on or the pin 1 of the MCU is directly maintained at a high level state through the infrared receiving port; Set the pins of other MCUs that control LED lights to low level to put the device into a low power state; Monitor the level change of pin 1 of the MCU. When it is detected that pin 1 of the MCU changes to a low level, wake up the MCU from a low power state. In the interrupt service program, the level state of pin 1 of the MCU is detected with a period of 100 microseconds; If the MCU pin 1 is continuously detected as low level and the duration is between 8 milliseconds and 10 milliseconds, it is determined to be a valid infrared signal; Analyze infrared signals and verify whether they comply with NEC6122 protocol, including pilot code, user code, data code and data inverse code; When the received data code matches the preset power-on code value, the MCU lights up the specified LED by outputting a high level on the control pin.
[0012] In one possible implementation, it also includes: When it is detected that the low level of pin 1 of the MCU lasts for more than 100 interrupt cycles of 100 microseconds, that is, more than 10 milliseconds, it is determined to be a valid key operation; According to the status of the button operation, the working mode of the device is switched, including power on or off.
[0013] In one possible implementation, when the device is powered off, a key press will cause the MCU to perform the following operations: Pin 6, pin 4 and pin 3 of MCU output high level; The first MOS tube, the second MOS tube and the third MOS tube are turned on to light up the LED-R lamp, the LED-G lamp and the LED-B lamp.
[0014] In one possible implementation, when the device is powered on, a key press will cause the MCU to perform the following operations: Pin 6, pin 4 and pin 3 of MCU output low level; Turn off the LED-R, LED-G and LED-B lights.
[0015] The beneficial effects brought about by the technical solution provided by the present invention include at least: The MCU provided by the present invention has multiple groups of pins, wherein the first pin of the infrared receiving head is connected to VCC, the second pin of the infrared receiving head and the second pin of the MCU are connected to GND, the first end of the button and the third pin of the infrared receiving head are connected to the first pin of the MCU, the second end of the button is connected to the first end of the first resistor, and the second end of the first resistor is connected to GND. In this case, the infrared receiving pin is multiplexed with the button, and when the pin receives the infrared signal, it is necessary to distinguish between the infrared signal and the button trigger according to the protocol requirements of different infrared signals. According to the NEC6122 protocol, by judging the low level time, the button judgment program determines whether it is a button trigger, thereby reducing the number of required package pins, thereby reducing the cost of the PCB board. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.
[0017] Figure 1 A schematic diagram of a circuit for implementing pin multiplexing of infrared receiving detection and key detection provided by an exemplary embodiment of the present invention is shown.
[0018] Figure 2 A flow chart of a method for implementing pin multiplexing for infrared receiving detection and key detection provided by an exemplary embodiment of the present invention is shown.
[0019] Figure 3 A logic block diagram of a method for implementing pin multiplexing of infrared receiving detection and key detection provided by an exemplary embodiment of the present invention is shown. DETAILED DESCRIPTION
[0020] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0021] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0022] Figure 1 A schematic diagram of a circuit for implementing pin multiplexing of infrared receiving detection and key KEY1 detection provided by an exemplary embodiment of the present invention is shown. The circuit for implementing pin multiplexing of infrared receiving detection and key KEY1 detection includes: an MCU single-chip computer P1, an infrared receiving head H1, and a key KEY1, wherein the MCU single-chip computer P1 has multiple groups of pins; a pin 1 of the infrared receiving head H1 is connected to VCC (a positive electrode of a 5V power supply), a pin 2 of the infrared receiving head H1 and a pin 2 of the MCU single-chip computer P1 are commonly connected to GND (a negative electrode of a power supply); a first end of the key KEY1 and a pin 3 of the infrared receiving head H1 are commonly connected to a pin 1 of the MCU single-chip computer P1, a second end of the key KEY1 is connected to a first end of a first resistor R1, and a second end of the first resistor R1 is connected to GND.
[0023] In the embodiment of the present application, the infrared receiving head H1 is used for filtering the infrared carrier and transmitting the processed high and low levels to the MCU. After comparing the received high and low levels with the protocol, the MCU determines whether functional operation is required.
[0024] In the embodiment of the present application, the key KEY1 is used to switch the MCU function mode and plays the role of switching the high and low levels of the MCU pin.
[0025] In the embodiment of the present application, the first resistor R1 is used to limit the current of the pin and plays a protective role.
[0026] In the embodiment of the present application, the infrared receiving pin is multiplexed with the button. When the pin receives the infrared signal, it needs to distinguish the infrared signal from the button trigger according to the protocol requirements of different infrared signals. According to the NEC6122 protocol, the maximum low level time in the protocol is 9ms. By judging the low level time, the button judgment program determines whether it is a button trigger.
[0027] Furthermore, the above-mentioned circuit for realizing the multiplexing of infrared receiving detection and key KEY1 detection pins also includes: a first MOS tube Q1, a second resistor R2, and an LED-R lamp D1, the gate of the first MOS tube Q1 is connected to pin six of the MCU microcontroller P1, and the source of the first MOS tube Q1 is connected to GND; the first end of the second resistor R2 is connected to pin six of the MCU microcontroller P1, and the second end of the second resistor R2 is connected to GND; the cathode of the LED-R lamp D1 is connected to the drain of the first MOS tube Q1, and the anode of the LED-R lamp D1 is connected to VCC.
[0028] In the embodiment of the present application, the first MOS tube Q1 is used as a driving module of the LED-R lamp D1 and is controlled by an MCU pin.
[0029] In the embodiment of the present application, the second resistor R2 is used for pull-down to prevent the first MOS tube Q1 from being turned on for a short time when power is just turned on.
[0030] Furthermore, the above-mentioned circuit for realizing the multiplexing of infrared receiving detection and key KEY1 detection pins also includes: a second MOS tube Q2, a third resistor R3, and an LED-G lamp D2, the gate of the second MOS tube Q2 is connected to pin four of the MCU microcontroller P1, and the source of the second MOS tube Q2 is connected to GND; the first end of the third resistor R3 is connected to pin four of the MCU microcontroller P1, and the second end of the third resistor R3 is connected to GND; the cathode of the LED-G lamp D2 is connected to the drain of the second MOS tube Q2, and the anode of the LED-G lamp D2 is connected to VCC.
[0031] In the embodiment of the present application, the second MOS tube Q2 is used as a driving module of the LED-G lamp D2 and is controlled by the MCU pin.
[0032] In the embodiment of the present application, the third resistor R3 is used for pull-down to prevent the second MOS tube Q2 from being turned on for a short time when power is just turned on.
[0033] In more detail, the above-mentioned circuit for realizing the multiplexing of infrared receiving detection and key KEY1 detection pins also includes: a third MOS tube Q3, a fourth resistor R4, and an LED-B lamp D3. The gate of the third MOS tube Q3 is connected to the pin three of the MCU microcontroller P1, and the source of the third MOS tube Q3 is connected to GND; the first end of the fourth resistor R4 is connected to the pin three of the MCU microcontroller P1, and the second end of the fourth resistor R4 is connected to GND; the cathode of the LED-B lamp D3 is connected to the drain of the third MOS tube Q3, and the anode of the LED-B lamp D3 is connected to VCC.
[0034] In the embodiment of the present application, the third MOS tube Q3 is used as a driving module of the LED-B lamp D3 and is controlled by the MCU pin.
[0035] In the embodiment of the present application, the fourth resistor R4 is used for pull-down to prevent the third MOS tube Q3 from being turned on for a short time when power is just turned on.
[0036] It is worth mentioning that the above circuit for realizing the multiplexing of infrared receiving detection and key KEY1 detection pins also includes: capacitor C1, a first end of which is connected to pin 5 of MCU microcontroller P1, and a second end of which is connected to GND.
[0037] In the embodiment of the present application, capacitor C1 is used for filtering the power supply of the MCU and plays a role in stabilizing the operation of the chip.
[0038] Figure 2 A flowchart of a method for implementing pin multiplexing of infrared receiving detection and key detection provided by an exemplary embodiment of the present invention is shown. Figure 3 A logic block diagram of a method for implementing infrared receiving detection and key detection pin multiplexing provided by an exemplary embodiment of the present invention is shown. The method is applied to the circuit for implementing infrared receiving detection and key detection pin multiplexing as described above. The method includes: Step 201, in response to the MCU being powered on, setting the pin 1 of the MCU to an input mode, turning on an internal pull-up resistor or directly maintaining the pin 1 of the MCU in a high level state through an infrared receiving port.
[0039] Step 202, setting the pins of other MCUs controlling LED lights to a low level, so that the device enters a low power consumption state.
[0040] Step 203, monitoring the level change of pin 1 of the MCU, and waking up the MCU from the low power consumption state when detecting that the pin 1 of the MCU changes to a low level.
[0041] Step 204, in the interrupt service program, the level state of the pin 1 of the MCU is detected with a period of 100 microseconds.
[0042] Step 205: If the MCU pin 1 is continuously detected to be at a low level and the duration is between 8 milliseconds and 10 milliseconds, it is determined to be a valid infrared signal.
[0043] Step 206, parse the infrared signal to verify whether it complies with the NEC6122 protocol, including the guide code, user code, data code and data inverse code (32 bits in total, one bit is composed of "1" or "0", distinguished by different time of high and low levels).
[0044] In the embodiment of the present application, the "1" signal in the NEC6122 protocol consists of a low level of 0.56 milliseconds and a high level of 1.69 milliseconds, and the "0" signal consists of two low levels and a high level of 0.56 milliseconds.
[0045] Step 207, when the received data code matches the preset power-on code value, the MCU lights up the designated LED lamp by outputting a high level through the control pin.
[0046] In one possible implementation, the method further includes: When it is detected that the low level of pin 1 of the MCU lasts for more than 100 interrupt cycles of 100 microseconds, that is, more than 10 milliseconds, it is determined to be a valid key operation; According to the status of the button operation, the working mode of the device is switched, including power on or off.
[0047] Furthermore, when the device is in shutdown state, a key trigger will cause the MCU to perform the following operations: Pin 6, pin 4 and pin 3 of MCU output high level; The first MOS tube, the second MOS tube and the third MOS tube are turned on to light up the LED-R lamp, the LED-G lamp and the LED-B lamp.
[0048] Furthermore, when the device is powered on, a key press will cause the MCU to perform the following operations: Pin 6, pin 4 and pin 3 of MCU output low level; Turn off the LED-R, LED-G and LED-B lights.
[0049] In a specific embodiment, the method for implementing the multiplexing of infrared receiving detection and key detection pins includes: (1) Infrared reception judgment: According to the 6122 protocol, there are 32 bits in total, including the guide code, user code, data code and data inverse code. One bit is composed of "1" or "0", and is distinguished by the different time of high and low levels. "1" is composed of a low level of 0.56ms and a high level of 1.69ms. "0" is composed of a low level of 0.56MS and a high level of 0.56MS.
[0050] Pin 1 of the MCU is judged to change from low level to high level, and it is judged whether it reaches 80 times and less than 100 times. If this condition is met, the infrared is effective, and then the infrared protocol is judged. Determine whether the received 32-bit code is consistent with the user code, and then compare the data code. If the data code is the power-on code value, then pin 6 of the MCU outputs a high level, pin 4 outputs a high level, and pin 3 outputs a high level, and at the same time turns on the first MOS tube, the second MOS tube and the third MOS tube, so that the LED-R lamp, LED-G lamp and LED-B lamp are lit.
[0051] (2) Key detection and judgment: If the MCU's pin 1 is at a low level during the increase process and the cumulative increase reaches more than 100, the key is considered to be effective, and the key-related program processing is performed and the corresponding working mode is entered.
[0052] When the LED-R, LED-G and LED-B lights are off in the shutdown state, the button is triggered and the power-on state is entered. Pin six of the MCU outputs a high level, pin four of the MCU outputs a high level, and pin three of the MCU outputs a high level. At the same time, the first MOS tube, the second MOS tube and the third MOS tube are turned on to light up the LED-R, LED-G and LED-B lights.
[0053] When the power is on, the button is triggered and the power enters the off state. Pin six of the MCU outputs a low level, pin four of the MCU outputs a low level, and pin three of the MCU outputs a low level, turning off the LED-R, LED-G, and LED-B lights.
[0054] It should be understood that the specific examples herein are only intended to help those skilled in the art to better understand the present disclosure, rather than to limit the scope of the present invention.
[0055] It is understood that in the various implementations of this specification, the size of the sequence number of each process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the present disclosure.
[0056] It can be understood that the various implementation modes described in this specification can be implemented individually or in combination, and the present disclosure is not limited to this.
[0057] Unless otherwise stated, all technical and scientific terms used in this disclosure have the same meaning as those generally understood by those skilled in the art of the technical field of this specification. The terms used in this specification are only for the purpose of describing specific embodiments and are not intended to limit the scope of this specification. The term "and / or" used in this specification includes any and all combinations of one or more related listed items. The singular forms of "a", "above", and "the" used in this disclosure and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0058] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this specification.
[0059] The above is only a specific implementation of this specification, but the protection scope of the present invention is not limited thereto. Any person skilled in the art who is familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in this specification, which should be included in the protection scope of this specification. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A circuit for realizing the multiplexing of infrared receiving detection and key detection pins, characterized in that: include: MCU, which has multiple sets of pins; The infrared receiving head has its pin 1 connected to VCC, and its pin 2 and the pin 2 of the MCU are connected to GND; A button, a first end of which and pin three of the infrared receiving head are connected to pin one of the MCU, a second end of the button is connected to a first end of a first resistor, and a second end of the first resistor is connected to GND.
2. The circuit for realizing the multiplexing of infrared receiving detection and key detection pins according to claim 1, characterized in that: Also includes: A first MOS tube, a gate of which is connected to pin 6 of the MCU, and a source of which is connected to GND; A second resistor, a first end of which is connected to pin 6 of the MCU, and a second end of which is connected to GND; The LED-R lamp has a cathode connected to the drain of the first MOS tube, and an anode connected to VCC.
3. The circuit for realizing the multiplexing of infrared receiving detection and key detection pins according to claim 2, characterized in that: Also includes: A second MOS tube, a gate of which is connected to pin 4 of the MCU, and a source of which is connected to GND; A third resistor, a first end of which is connected to pin 4 of the MCU, and a second end of which is connected to GND; The LED-G lamp has a cathode connected to the drain of the second MOS tube, and an anode connected to VCC.
4. The circuit for realizing the multiplexing of infrared receiving detection and key detection pins according to claim 3, characterized in that: Also includes: A third MOS tube, whose gate is connected to pin 3 of the MCU and whose source is connected to GND; a fourth resistor, a first end of which is connected to pin 3 of the MCU, and a second end of which is connected to GND; The cathode of the LED-B lamp is connected to the drain of the third MOS tube, and the anode of the LED-B lamp is connected to VCC.
5. The circuit for realizing the multiplexing of infrared receiving detection and key detection pins according to claim 1, characterized in that: Also includes: A capacitor, a first end of which is connected to pin 5 of the MCU, and a second end of which is connected to GND.
6. A method for realizing pin multiplexing of infrared receiving detection and key detection, characterized in that: The method is applied to the circuit for realizing the multiplexing of infrared receiving detection and key detection pins as claimed in any one of claims 1 to 5, and the method comprises: In response to the MCU being powered on, the pin 1 of the MCU is set to the input mode, the internal pull-up resistor is turned on or the pin 1 of the MCU is directly maintained at a high level state through the infrared receiving port; Set the pins of other MCUs that control LED lights to low level to put the device into a low power state; Monitor the level change of pin 1 of the MCU. When it is detected that pin 1 of the MCU changes to a low level, wake up the MCU from a low power state. In the interrupt service program, the level state of pin 1 of the MCU is detected with a period of 100 microseconds; If the MCU pin 1 is continuously detected as low level and the duration is between 8 milliseconds and 10 milliseconds, it is determined to be a valid infrared signal; Analyze infrared signals and verify whether they comply with NEC6122 protocol, including pilot code, user code, data code and data inverse code; When the received data code matches the preset power-on code value, the MCU lights up the specified LED by outputting a high level on the control pin.
7. The method for realizing pin multiplexing of infrared receiving detection and key detection according to claim 6, characterized in that: Also includes: When it is detected that the low level of pin 1 of the MCU lasts for more than 100 interrupt cycles of 100 microseconds, that is, more than 10 milliseconds, it is determined to be a valid key operation; According to the status of the button operation, the working mode of the device is switched, including power on or off.
8. The method for realizing pin multiplexing of infrared receiving detection and key detection according to claim 7, characterized in that: When the device is in shutdown state, a key trigger will cause the MCU to perform the following operations: Pin 6, pin 4 and pin 3 of MCU output high level; The first MOS tube, the second MOS tube and the third MOS tube are turned on to light up the LED-R lamp, the LED-G lamp and the LED-B lamp.
9. The method for realizing the multiplexing of infrared receiving detection and key detection pins according to claim 7, characterized in that: When the device is powered on, a key press will cause the MCU to perform the following operations: Pin 6, pin 4 and pin 3 of MCU output low level; Turn off the LED-R, LED-G and LED-B lights.
Citation Information
Cited By
Input signal-based pin configuration method and actuator separation detection device
CN121115649A