I have worked on single-chip microcomputer products for two years. In the process of single-chip microcomputer programming, I gradually formed a roughly fixed overall framework, which can also be said to be a programming idea. I now put it forward for your reference.
First, classify the peripheral chips. The programs with the same function or the same chip are modularized and implemented with several fixed functions. Generally, the functions of different chips should not overlap as much as possible, and one function should not cover several chips, so as to facilitate later debugging. If it involves communication between chips, it can be listed separately and processed with special functions;
Secondly, classify the work that needs to be completed in the single-chip microcomputer according to the importance. Generally, I will set two timer interrupts, one of which is about 20ms, which is used to handle some button anti-shake processing, time and date calculation, corresponding flag bits generated after input processing, device refresh, and other things that do not require high real-time requirements but must have time requirements. In addition, set up a timer interrupt of about 1ms, which is mainly used to realize the clock reference and do some operations with high real-time requirements. Generally, it is necessary to set the timer interrupt with high real-time requirements to a high priority, otherwise it cannot be normal operation. If there is a serial interrupt that needs to be processed, the code length in the real-time interrupt needs to be strictly controlled to avoid delaying the processing of the serial interrupt. In addition, if software is used to implement serial port and wireless communication soft decoding, the code length of each part should also be reasonably allocated;
Finally, common event detection, processing and response are implemented in the main program body. This part generally only requires a few parallel functions, and the main program body can be implemented with a few simple lines of code.
I have developed several single-chip microcomputer products using the above structure, including a wireless burglar alarm host with wireless soft decoding, an RS485 repeater (one to 100), an alarm receiver with Chinese display, etc., all of which have achieved stable and effective operation.
I hope some of my experiences can be helpful to you!
Previous article:How to use C language variable parameter function
Next article:Common naming conventions for C language
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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!
- 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
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [National Technology N32G457 Review] ML component control
- Playing with Zynq Serial 47——[ex66] Image Histogram Equalization Processing of MT9V034 Camera
- Anlu SparkRoad Development Board Review (6) Use of FIFO IP
- Features and differences of ARM, DSP and FPGA
- [GD32L233C-START Review] 14. RT-Thread kernel and finsh ported to GD32L233
- Introduction to the classification and development history of carrier aggregation
- Share the written test questions for embedded software engineers
- csmc0.5um process library
- The internal structure of the MCU
- Questions about multi-channel schematic connection