Discussing My Microcontroller Programming Ideas

Wu Jianying Microcontroller Development Board Address

Store:Wu Jianying’s Shop

Address:https://item.taobao.com/item.htm?_u=ukgdp5a7629&id=524088004171

Discussing My Microcontroller Programming Ideas

I have developed microcontroller products for two years, and during the process of programming microcontrollers, I gradually formed a generally fixed overall framework, which can also be referred to as a programming idea. I present it here for everyone’s reference.

First, classify the peripheral chips, and use a modular approach for the programs of chips with the same function or the same chip, implementing them with a fixed number of functions. Generally, the function capabilities between different chips should not overlap as much as possible, and avoid using one function to cover several chips to facilitate later debugging. If communication between chips is involved, it can be listed separately and handled with dedicated functions;

Second, categorize the tasks that need to be completed by the microcontroller based on urgency. Generally, I set up two timer interrupts, one with a timing of about 20ms, used to handle button debounce, time and date calculations, generate corresponding flags after processing inputs, device refreshing, etc., which have real-time requirements that are not very high but must meet time requirements. Additionally, I establish another timer interrupt of about 1ms or less, mainly to implement clock reference and perform operations with high real-time requirements. The timer interrupt with higher real-time requirements should generally be set to high priority; otherwise, normal operation cannot be achieved. If there are serial interrupts to handle, the code length in the real-time interrupt must be strictly controlled to avoid delaying serial interrupt processing. Also, in cases where software is used to implement serial and wireless communication soft decoding, the code length for each part must be reasonably allocated;

Finally, implement ordinary event detection, handling, and response in the main program body. This part generally only requires a few parallel functions, and the main program body can be implemented with just a few lines of code.

I have developed several microcontroller products using the above structure, including a wireless anti-theft alarm host with wireless soft decoding, an RS485 repeater (one to 100), and an alarm receiver with Chinese display, all of which have achieved stable and effective operation.

I hope my experiences can be helpful to everyone!

For those who like this article, feel free to give a thumbs up

Discussing My Microcontroller Programming Ideas

Discussing My Microcontroller Programming Ideas

Technology Comes From Accumulation, Success Comes From Persistence

——Microcontroller Expert Wu Jianying

Leave a Comment