A method and system for controlling a turn signal using a timer interrupt
By independently controlling the flashing and turning off of the turn signals through a timer interrupt mechanism, the problems of high resource consumption and poor real-time response in traditional turn signal control systems are solved, thus achieving efficient turn signal control.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 徐协臣
- Filing Date
- 2026-05-07
- Publication Date
- 2026-07-24
AI Technical Summary
Traditional turn signal control systems have high resource consumption, poor real-time response, and are prone to failure.
The system employs a timer interrupt mechanism, responding to the turn signal and turn-off buttons via external interrupts. It utilizes a blink timer and a duration timer to independently control the blinking and turning off of the turn signals, with the main program only responsible for initialization and waiting for interrupts.
It improves the system's real-time response capability, ensures the accuracy of the turn signal flashing frequency and the reliability of automatic shut-off, decouples the main program from the timing control, and frees up CPU resources.
Smart Images

Figure CN122458282A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of turn signal control technology, specifically to a turn signal control method and system implemented using timer interrupts. Background Technology
[0002] Turn signals are crucial safety indicators in electric bicycles, motorcycles, and various other motor vehicles, used to signal the vehicle's turning intention to other road users. Traditional turn signal control systems typically employ oscillating circuits composed of electronic components. This approach is costly and prone to malfunctions. Summary of the Invention
[0003] The present invention aims to provide a turn signal control method and system that utilizes timer interrupts, thereby solving the technical problems of high resource consumption and poor real-time response caused by the main program undertaking timing control tasks.
[0004] To achieve the above objectives, the technical solution adopted by this invention is: a turn signal control method using timer interrupts, comprising the following steps:
[0005] Upon system power-up, the main program initializes, sets the turn signal button detection method to interrupt response, turns off the turn signal, and enters the interrupt waiting state.
[0006] When the turn signal button is pressed, an external interrupt will be triggered, and the turn signal button interrupt program will be executed: the turn signal button will be identified and the corresponding turn signal indicator will be set, the corresponding turn signal indicator will be turned on, and the blink timer and duration timer will be started at the same time, and then the interrupt will return.
[0007] When the flashing timer reaches its set time, a flashing timer interrupt will be generated, and the flashing timer interrupt program will be executed: the state of the corresponding turn signal will be switched between on and off according to the direction identifier bit, and then the process will return.
[0008] When the duration timer expires, a duration timer interrupt will be generated, and the duration timer interrupt routine will be executed: turn off all turn signals, stop the flashing timer and the duration timer, clear the direction indicator bit, and then return;
[0009] The main program, after initialization, is only responsible for waiting for interrupts. The flashing control and automatic shut-off control of the turn signals are both completed through different timer interrupt programs, which do not occupy the execution time of the main program.
[0010] Preferably, it also includes a light-off button control step:
[0011] Configure the light-off button to respond to external interrupts.
[0012] When the turn-off button is pressed, an external interrupt will be triggered, executing the turn-off interrupt procedure: regardless of the current state of the turn signals, the left and right turn signals will be turned off immediately, the flashing timer and duration timer will be stopped, and the direction indicator bit will be cleared, and then the interrupt will return.
[0013] Preferably, the steering button is a self-resetting steering button, which is engaged when pressed and disengaged when released.
[0014] Preferably, the blinking timer and the duration timer are started simultaneously in the turn button interrupt routine; the execution order of the light blinking timer interrupt routine and the duration timer interrupt routine depends on the arrival order of their respective timing times, are independent of each other, and can both be turned off by the light-off interrupt routine at any time.
[0015] On the other hand, the present invention proposes a turn signal control system implemented using a timer interrupt, comprising:
[0016] The processor is used to execute the main program and various interrupt service routines.
[0017] The directional button module is connected to the processor's external interrupt pin and is used to generate an external interrupt signal to the processor when the button is pressed.
[0018] A timer module, connected to the processor, includes a flashing timer for controlling the flashing frequency of the lights and a duration timer for controlling the operating duration of the turn signals;
[0019] The turn signal driver module is connected to the processor's output port and is used to turn on, off, or switch the state of the left / right turn signals according to the processor's instructions.
[0020] Preferably, the system further includes:
[0021] The turn signal button module is connected to another external interrupt pin of the processor and is used to generate an external interrupt signal at any time to force the turn signal system to turn off.
[0022] Preferably, the processor is configured to: perform only initialization and wait for interrupts in the main program; respond to the operation of the turn signal button and the turn-off button via an external interrupt; and independently execute the turn signal state toggling and automatic off logic via a timer interrupt.
[0023] Preferably, the processor is a single-chip microcomputer or a microcontroller.
[0024] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0025] This invention delegates the button triggering, light flashing, and automatic shut-off logic to different interrupt service routines, while the main program only enters a waiting state after initialization. This frees up the main program's execution resources, allowing it to focus on other tasks and significantly improves the overall real-time response capability of the system. At the same time, by using the processor's built-in timer interrupt to independently control the timing, the accuracy of the turn signal flashing frequency and the reliability of the automatic shut-off function are ensured, achieving decoupling and efficient operation of each functional module. Attached Figure Description
[0026] Figure 1 A flowchart illustrating the operation of the main program of this invention;
[0027] Figure 2 This is a flowchart illustrating the operation of the left (right) button interrupt program of this invention.
[0028] Figure 3 This is a flowchart of the light-off interruption process of the present invention;
[0029] Figure 4 This is a flowchart illustrating the interrupt operation of the LED flashing timer in this invention;
[0030] Figure 5 This is a flowchart illustrating the operation of the duration timer in this invention. Detailed Implementation
[0031] The following description is intended to disclose the invention and enable those skilled in the art to implement it. The preferred embodiments described below are merely examples, and other obvious variations will occur to those skilled in the art.
[0032] like Figures 1-5 As shown, this invention proposes a turn signal control method using timer interrupts, comprising the following steps:
[0033] Upon system power-up, the main program initializes, sets the turn signal button detection method to interrupt response, turns off the turn signal, and enters an interrupt waiting state. This ensures that the system is in a definite safe state (lights off) at the moment of startup and establishes an efficient interrupt response mechanism. This allows the main program to immediately enter a low-power waiting mode without polling, thereby maximizing the release of CPU resources and improving the system's real-time response speed to turn signals.
[0034] When the turn button is pressed, an external interrupt will be triggered, executing the turn button interrupt program: identifying the turn direction and setting the corresponding turn direction indicator bit, illuminating the corresponding turn signal, and starting the flashing timer and duration timer, and then returning from the interrupt; the turn button is a self-resetting turn button, which is engaged when pressed and disengaged when released.
[0035] By utilizing the instantaneous triggering characteristic of the self-recovery button in conjunction with an external interrupt, the instantaneous response and accurate recognition of the turn signal are achieved. By completing the direction locking, light activation, and dual timer initialization in the interrupt and returning immediately, the real-time performance of the turn indication is guaranteed, while avoiding resource waste caused by continuous button detection is avoided.
[0036] When the flashing timer reaches its set time, a light flashing timer interrupt is triggered, and the light flashing timer interrupt program is executed: the state of the corresponding turn signal is switched between on and off according to the direction identifier bit, and then returns;
[0037] By utilizing the processor's built-in timer interrupt to independently take over the lighting timing control, the main program and the flashing logic are completely decoupled, ensuring that the cycle of the turn signal on and off is accurate and stable; at the same time, the mechanism of returning immediately after the interrupt is executed greatly reduces the CPU utilization.
[0038] When the duration timer expires, a duration timer interrupt is triggered, and the duration timer interrupt routine is executed: all turn signals are turned off, the flashing timer and the duration timer are stopped, the direction indicator bit is cleared, and then the process returns.
[0039] By precisely controlling the working duration through the processor's built-in timer, the turn signals are automatically turned off, completely eliminating the problem of turn signals remaining on due to driver forgetfulness. The actions such as turning off the lights are completed within the interrupt, ensuring that the system can quickly return to the initial standby state, significantly improving driving safety and system reliability.
[0040] The main program, after initialization, only waits for interrupts. The turn signal flashing and automatic shut-off controls are handled by different timer interrupt routines, without consuming the main program's execution time. A fully event-driven, non-blocking architecture is constructed, completely decoupling timing control tasks from the main loop, allowing the main program to maintain a very low-power waiting state. This design not only achieves zero coupling between the turn signal control logic and the main business process, ensuring absolute accuracy of the light flashing frequency and reliability of automatic shut-off, but also maximizes CPU computing power, providing ample resources for the system to concurrently process other tasks.
[0041] Further steps include controlling the turn-off button: setting the turn-off button to an external interrupt response mode; when the turn-off button is pressed, an external interrupt is triggered, executing the turn-off interrupt procedure: regardless of the current turn signal status, the left and right turn signals are immediately turned off, the flashing timer and duration timer are stopped, and timer interrupts are prevented. The direction indicator bit is cleared, and then the interrupt returns. This effectively solves the problems of delayed response and complex logic in traditional polling methods, ensuring that drivers can quickly cancel turn signals in unexpected road conditions, significantly improving the real-time performance of human-machine interaction and driving safety.
[0042] The flashing timer and the duration timer are started simultaneously in the turn button interrupt routine; the execution order of the flashing timer interrupt routine and the duration timer interrupt routine depends on the arrival order of their respective timing times, they are independent of each other, and both can be turned off by the turn-off interrupt routine at any time.
[0043] A highly cohesive and loosely coupled parallel timing control mechanism was constructed. The independent counting of the processor's built-in timer eliminated program logic dependencies, ensuring that the flashing frequency and working duration do not interfere with each other.
[0044] On the other hand, the present invention proposes a turn signal control system implemented using a timer interrupt, comprising:
[0045] The processor (CPU) is used to execute the main program and various interrupt service routines;
[0046] The steering button module is connected to the processor's external interrupt pin and is used to generate an external interrupt signal to indicate the steering direction when pressed.
[0047] A timer module, connected to the processor, includes a flashing timer for controlling the flashing frequency of the lights and a duration timer for controlling the operating duration of the turn signals;
[0048] The turn signal driver module is connected to the processor's output port and is used to turn on, off, or switch the state of the left / right turn signals according to the processor's instructions.
[0049] The turn signal button module is connected to another external interrupt pin of the processor and is used to generate an external interrupt signal at any time to force the turn signal system to turn off.
[0050] The processor is a single-chip microcomputer or microcontroller, used only for initialization in the main program and waiting for interrupts; responding to the operation of the turn signal buttons and the turn-off button through external interrupts; and independently executing the turn signal state toggling and automatic turning-off logic through timer interrupts.
[0051] Furthermore, the components in the above system are also used to employ the following methods during execution:
[0052] After the CPU starts up, it first executes the main program. In the main program, the CPU sets the key input to interrupt response mode.
[0053] When a turn signal button is pressed, the CPU generates an external interrupt. The CPU will automatically execute the left (right) button interrupt routine. In this routine, the CPU processes the signal as follows: it maintains a flag in memory to indicate whether the left or right turn signal button has been pressed, and initializes and starts two timers (one to blink the turn signal, and the other to turn it off after a set time). After these steps, the task of the left (right) button interrupt routine is complete, and the two timer interrupt routines will automatically handle the tasks of blinking and automatically turning off the turn signal.
[0054] The process is as follows: When the blinking timer expires, the CPU automatically executes the LED blinking timer interrupt routine. In this interrupt routine, the CPU changes the state of the LED (on to off, off to on), then exits the interrupt routine. When the next timer expires, the CPU changes the state of the LED again.
[0055] When the timer expires, the CPU will automatically execute the timer interrupt routine. In this routine, the CPU will turn off the turn signals, as well as the blink timer and the timer itself. It will also indicate that no button is currently pressed.
[0056] If the button to turn off the lights is pressed, the CPU will automatically execute the light-off interrupt routine. In this interrupt routine, the process is as follows: turn off the left and right turn signals, turn off the two timers, and indicate that no turn signal button has been pressed.
[0057] The timer calculates the number of CPU cycles. If the set number is reached, an interrupt is generated, and the CPU executes the timer interrupt routine.
[0058] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely principles of the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the claimed invention. The scope of protection claimed by the appended claims and their equivalents is defined.
Claims
1. A turn signal control method using timer interrupts, characterized in that, Includes the following steps: Upon system power-up, the main program initializes, sets the turn signal button detection method to interrupt response, turns off the turn signal, and enters the interrupt waiting state. When the turn signal button is pressed, an external interrupt will be triggered, and the turn signal button interrupt program will be executed: the turn signal button will be identified and the corresponding turn signal indicator will be set, the corresponding turn signal indicator will be turned on, and the blink timer and duration timer will be started at the same time, and then the interrupt will return. When the flashing timer reaches its set time, a flashing timer interrupt will be generated, and the flashing timer interrupt program will be executed: the state of the corresponding turn signal will be switched between on and off according to the direction identifier bit, and then the process will return. When the duration timer expires, a duration timer interrupt will be generated, and the duration timer interrupt routine will be executed: turn off all turn signals, stop the flashing timer and the duration timer, clear the direction indicator bit, and then return; The main program, after initialization, is only responsible for waiting for interrupts. The flashing control and automatic shut-off control of the turn signals are both completed through different timer interrupt programs, which do not occupy the execution time of the main program.
2. The turn signal control method using timer interrupts according to claim 1, characterized in that, It also includes the steps for controlling the light to turn off: Configure the light-off button to respond to external interrupts. When the turn-off button is pressed, an external interrupt will be triggered, executing the turn-off interrupt procedure: regardless of the current state of the turn signals, the left and right turn signals will be turned off immediately, the flashing timer and duration timer will be stopped, and the direction indicator bit will be cleared, and then the interrupt will return.
3. The turn signal control method using timer interrupts according to claim 1, characterized in that, The steering button is a self-resetting steering button; it is engaged when pressed and disengaged when released.
4. The turn signal control method using timer interrupts according to claim 1, characterized in that, The blinking timer and the duration timer are started simultaneously in the turn button interrupt routine; the execution order of the light blinking timer interrupt routine and the duration timer interrupt routine depends on the arrival order of their respective timing times, they are independent of each other, and both can be turned off by the light-off interrupt routine.
5. A turn signal control system implemented using a timer interrupt for implementing the method as described in any one of claims 1-4, characterized in that, include: The processor is used to execute the main program and various interrupt service routines. The directional button module is connected to the processor's external interrupt pin and is used to generate an external signal to the processor when the button is pressed. A timer module, connected to the processor, includes a flashing timer for controlling the flashing frequency of the lights and a duration timer for controlling the operating duration of the turn signals; The turn signal driver module is connected to the processor's output port and is used to turn on, off, or switch the state of the left / right turn signals according to the processor's instructions.
6. The turn signal control system implemented using a timer interrupt according to claim 5, characterized in that, The system also includes: The turn signal button module is connected to another external interrupt pin of the processor and is used to generate an external interrupt signal at any time to force the turn signal system to turn off.
7. The turn signal control system implemented using a timer interrupt according to claim 5, characterized in that, The processor is configured to: perform only initialization and wait for interrupts in the main program; respond to the operation of the turn signal button and the turn-off button via external interrupts; and independently execute the turn signal state toggling and automatic turn-off logic via timer interrupts.
8. The turn signal control system implemented using a timer interrupt according to claim 5, characterized in that, The processor is a single-chip microcomputer or microcontroller.