Experts talk about MCU programming ideas

Publisher:CelestialMagicLatest update time:2018-11-22 Source: eefocusKeywords:Expert Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

 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!


Keywords:Expert Reference address:Experts talk about MCU programming ideas

Previous article:How to use C language variable parameter function
Next article:Common naming conventions for C language

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号