Introduction
With the improvement of performance and the reduction of price, more and more embedded applications adopt ARM processors. With the support of powerful functions and rich peripherals, embedded real-time operating systems have become an ideal choice for development and design with high development efficiency, maintainability and reliability.
μC/OS-II is a complete, portable and scalable preemptive real-time multitasking kernel. It is written in ANSI C language and contains a small part of assembly language code, which can be used by microprocessors of different architectures. μC/OS was completed by American Jean J. Labrosse in 1992 and developed into μC/OS-II in 1998. The current version is μC/OS-II v2.83. In 2000, μC/OS was certified by the US Aviation Administration (FAA) and can be used in aircraft. As a typical embedded operating system, μC/OS-II is widely used, such as cameras, medical equipment, audio equipment, engine control, highway telephone systems, ATMs, etc.
This paper mainly discusses the implementation of interrupt button debounce processing and LCD multi-level menu display in μC/OS-II environment, and explains the processing flow of interrupt button and the program framework of multi-level menu display through an example design of a product.
1 Display control system hardware design
This design uses the ARM processor LM3S1960 based on the Cortex-M3 architecture and the LCD display HS240128A as the core of the display control system, and the buttons use the interrupt method. The circuit schematic diagram of the display control system is shown in Figure 1.
LM3S1960 is a cost-effective microprocessor launched by Luminary. It has 256 KBFlash, 64 KB RAM, 4 32-bit timers, 6 motion control PWMs, 3 UARTs, 2 I2Cs, 2 SSIs and 60 user-available I/Os. The maximum operating frequency of LM3S1960 is 50 MHz. All its GPIO inputs can trigger interrupts and support UART with IRDA, which is very suitable for embedded control systems.
HS240128A is a 240×128 graphic dot matrix LCD display module, which uses T6963C as the built-in controller, built-in character generator and 32 KB display buffer, and has the characteristics of simple interface and complete control instruction set.
2 Interrupt key debounce processing
When there are many keys, the scanning query method is generally used. In this design, all keys are interrupted, mainly because there are not many keys and each pin of the processor has an interrupt function, which is simple to implement and has a fast response speed.
Jitter is easy to occur during the key pressing process, and sometimes there may be interference pulses when no key is pressed. If it is not processed, it is easy to cause misoperation. Therefore, debounce is a necessary process for key processing. In general processors, debounce processing mostly uses a delay judgment method, which is not suitable for implementation in the operating system. Because adding a large delay to the interrupt will greatly reduce the real-time performance and response speed of the system, this design adopts the processing method shown in Figure 2.
Figure 2(a) is the key interrupt processing program flow. In order to improve the real-time performance of the interrupt, as few operations as possible are performed during the interrupt processing process. In this design, only the operations of saving the key value and sending the key interrupt semaphore are performed, which greatly improves the real-time performance of the interrupt response.
Figure 2(b) is the key processing task flow. After completing the initialization, the task starts to wait for the interrupt to send the semaphore of the original key value that needs to be judged () SSemPend(C)SKeyRawSem, O, &err). The parameter OSKeyRawSem is the original key interrupt semaphore. If no semaphore is sent, the task will be suspended here. After receiving it, the key interrupt is first turned off, and the system delay OSTimeDlyHMSM (0, 0, 0, JitterTime) is performed. JitterTime is the delay time. During this delay process, the task will be scheduled, and the task will also be suspended until the delay ends and it is added to the waiting task list again. After the delay ends and the task regains the CPU, the key is judged again to determine whether a key interrupt has really occurred. If the judgment is correct, it is necessary to wait for the key to be released. In the process of judging whether the key is released, the system delay judgment OSTimeDly-HMSM (0, 0, 0, CheckTime) is also added. CheckTime is the time of each detection delay. After the key is released, the task sends the key signal to other tasks using OSSemPost (OSKeySem), where OSKeySem is the confirmed key interrupt. If the judgment is wrong, the key value is cleared. Finally, the key interrupt is turned on and waits for a new key interrupt again.
3 LCD multi-level menu display
For the writing of multi-level menus, the control relationship is relatively complex, especially for different interfaces, the content of human-computer interaction is generally different. Therefore, when implementing the operating system, the implementation of each level of the menu is generally designed as a task. This way of thinking is clear, problems are not likely to occur, and it is convenient to delete and add menu items, and it is also convenient for program maintenance and updating. The program in the main menu task loop is as follows:
The program description is as follows:
① At the beginning of the task, determine whether the system mode SystemMode is the main menu mode SysMode_MainMenu. If not, then the main menu display task needs to be suspended until it returns from other tasks.
② Wait for the key semaphore OSKeySem, and perform corresponding operations according to the user's key. RfreshTime is the refresh time of the menu. The semaphore waiting function waits within the RfreshTime time. If the key has not been operated after the waiting time, it continues to execute the following program, and the err variable will return an incorrect value.
③ If there is no error in the err return in ②, it means that a key interruption occurred during the refresh time, then enter the key operation handler.
④ Perform corresponding operations according to the key value variable KeyNumber, such as confirming the key processing, returning the key processing, etc.
⑤ If the confirmation key KEY_OK is pressed, then first assign the system submenu number SubMenuNumber to the SystemMode variable, and perform corresponding initialization operations.
⑥ For example, if it is a XXXX submenu, then send the semaphore OSSemPost (OSDisXXXXSem) after the initialization is completed. Among them, OSDisXXXXSem is the display semaphore of the submenu XXXX.
The purpose of ⑦ is to call the main menu display function. The reason for the second judgment is that the semaphore sent in ⑥ is to perform system scheduling. If the subsystem task priority is higher than the main menu, the main menu will be suspended and the submenu will be executed. During the interval of submenu execution, it will be rescheduled to display the main menu, which will cause display errors.
The task flow of submenu display is similar to that of the main menu. When the return key is pressed, the semaphore OSSemPost (OSDisMain-MenuSem) to start the main menu is sent, and the system will return to the main menu.
Conclusion
This paper studies the interrupt button debounce processing and LCD multi-level menu display method under the μC/OS-II operating system, and proposes a simple, highly reliable and easy-to-maintain implementation solution. This method has been applied to the development and design of a certain product with good results and stable and reliable operation.
Previous article:Design of Ultrasonic Density Meter Based on Ultrasonic Echo Splash Theory
Next article:Design of motion data collection and transmission of Zig Bee module
- Popular Resources
- Popular amplifiers
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- CGD and Qorvo to jointly revolutionize motor control solutions
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- Bosch and Tsinghua University renew cooperation agreement on artificial intelligence research to jointly promote the development of artificial intelligence in the industrial field
- GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
- Advantech: Investing in Edge AI Innovation to Drive an Intelligent Future
- CGD and QORVO will revolutionize motor control solutions
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- FAQ_How to test Mesh low power nodes
- How to Suppress Zero Drift in Direct-Coupled Amplifier Circuits
- FPGA Implementation of Digital Signal Processing.pdf
- Phase-Locked Loop (PLL) Basics
- Mir MYC-YT507 development board review: review video summary
- 【GD32450I-EVAL】+ 03 Basic usage of library functions - taking key interrupt as an example
- Please help, which of these two constant current sources is better?
- Silicon Labs Launches New Sub-GHz System-on-Chip with 1+ Mile Wireless Range and 10+ Year Battery Life
- Excuse me, does anyone have the dimension drawing of TQFN20 package?
- TIOBE Index May 2022