How to learn a new type of MCU

Any one MCU, the basic principles and functions are similar, except that only a peripheral configuration and the number of functional modules, and other instruction. For the command system, although seemingly vary in form, but in fact only the meaning of different symbols, they represent, to be completed and addressing functions are substantially similar. Therefore, for any one MCU, mainly the following aspects should be to understand and master.
  Initialization parameters: After the completion of the initialization of the MCU hardware and resources, the next step is to use the program in a number of variables and data initialization settings, initialization, this part needs to be designed in accordance with the overall arrangements for specific projects and programs. For some applications a number of EEPROM to save the project terms preform, it is recommended initialization copying data related to the MCU of RAM, the program to improve the data access speed while reducing power consumption of the system (in principle, to access the external EEPROM will increase power consumption).
  MCU features: For a MCU, you first need to know is its ROM space, RAM, space, the number of IO ports, the number of timers and timing mode, the function provided by the peripheral module (Peripheral Circuit), the interrupt source, the operating voltage and power consumption, and so on.
  After about these MCU Features, followed by the first step is to request the selected MCU function and the actual project development functions were compared, clear what resources are currently required, which is not used in this project. The MCU features for the selected item is not available in the need to use, you need to seriously understand the relevant information for the MCU, in order to use indirect methods to achieve, for example, the development of the project needs to communicate with the PC COM port, and the selected MCU UART port is not available, you might consider a way to achieve external interrupt.
  For resource development projects need to use, you need to carefully read and understand its Manua *, and for unnecessary functions module can be ignored or to browse. For MCU learning is concerned, the application is the key, is the main purpose.
  Clearly related functions of the MCU, then you can begin programming. For beginners or first-time section of the MCU designers, you may encounter a lot of MCU functional description is not clear where, for such problems can be solved in two ways, one is to write special verification program to understand the function of the data; the other can be temporarily ignored, according to their own programming in the current understanding to write, to modify and improve upon leaving the commissioning. The former method is suitable for the project and a more relaxed time for beginners, while the latter method is suitable for MCU development experience with a certain person or project behind schedule urgent situation.
  Command systems do not particularly take the time to understand. Symbol a logical instruction just described, only in the view according to programming logic requires its own logic and program instructions related to, and with the programming, the system will be more skilled instruction, even unconsciously memorized.
  The basic functions of the MCU:
  For the vast majority MCU, the following function is the most common and most basic, for different MCU, in a manner described may be different, but the essence is basically the same:
  TIMer (timer): TImer Although more species, but it can be summarized into two categories: one is tImer a fixed time interval, i.e. the time by which the timing set by the system, user programs can not control, the system provides only a fixed time interval to several user selected program, such as 32Hz, 16Hz, 8Hz, etc., such tImer common in the MCU 4, can be used to implement the functions associated clock timing; the other is the programmable timer (programmable timer) , by definition, is the regular time timer class may be controlled by a user program control mode comprising: selecting a clock source, the frequency division number (Prescale) selecting and setting the number of prefabricated, and some are three MCU along with, while others might be one of them or both. Such Timer very flexible, practical use is ever-changing, the most common application is to use one for PWM output thereof (the particular application, particular description will follow). Since the clock source can be freely selected, and therefore, generally these together with Timer Event Counter (event counter).
  IO port: Any MCU has a certain number of IO ports, no IO ports, MCU will lose the channel of communication with the outside. The configurable IO port of the case can be divided into the following types.
  Pure or pure Input Output: IO port the MCU hardware such design decisions can only be input or output, can not be set by software in real time;
  direct write IO port: The IO port on the MCS-51 belonging to this class IO ports. When a read command IO port is an input port; IO port when the write instruction is executed automatically output port;
  programming input and output setting direction: input or output port IO to perform such a program is provided according to actual needs fixed, flexible application can be achieved at some other bus-level applications, such as the I2C bus, various LCD, LED Driver control bus and the like;
  for the IO ports, it is important to bear in mind that: the input port must have a clear level signal that it can not float (can be pulled up or down on the increase achieved by); and the output port, the state level of its output must be considered external connections, should ensure that the Standby or static state is not presence source or sink current.
  External Interrupt: External Interrupt MCU also has the majority of the basic functions, it is generally used for real-time detection of a trigger signal, and data sampling state, the interrupt mode by the rising edge, falling edge triggered and level triggered several. Usually by external interrupt inputs to achieve, it will open if the interrupt function for the IO ports, only to enter; if it is output, the external interrupt function will automatically turn off (ATMEL series of ATiny some exceptions, output when can trigger an interrupt function). Application of external interrupts as follows:
  external trigger detection signal: one is based on real-time requirements, such as controlling the thyristor, detection of the burst signal; and the other is the case where power needs;
  signal frequency measurement: in order to ensure that the signal is not missed, the external interrupt is the best choice;
  decoded data: the remote control application in the field, in order to reduce the cost of design, often by way of software required to decode the various encoded data, such as Manchester and decoding the PWM encoded;
  Wake-up button and the detection system: For the MCU enters the Sleep state, generally need to wake up an external interrupt, the most basic form is a key, to generate level change through key operation;
  Communication Interface: MCU provided generally comprises a communication interface SPI interface, UART, I2C interface, which are described as follows:
  SPI interface: This interface is a basic means of communication provided by the vast majority of the MCU, the data transmission to control the synchronous clock signal comprising : SDI (serial data input), the SDO (serial data output), the SCLK (serial clock) signal and Ready; Ready signal may not in some cases; such an interface can operate in Master or Slave mode mode, popular providing a clock signal to see who is to say, one of them is to provide a clock Master, compared with the opposite party Slaver;
  the UART (Universal asynchronous the Receive transmit): an asynchronous transfer belongs to the basic interface, the Rx and Tx signal lines only two, basic data format: Start Bit + data Bit (7 -bits / 8-bits) + Parity Bit (Even, Odd or None) + Stop Bit (1 ~ 2Bit). Bit of data occupies time called Baud Rate (baud rate). For most of the terms MCU, the data length, data check mode (odd, even or no parity), the stop bit (Stop Bit) and a length of flexible Baud Rate is set by programming set. Such an interface is the most common way data communication with the PC serial port.
  I2C interface: I2C developed by Philips is a data transmission protocol, using the same two signals is achieved: SDAT (serial data input and output) and the SCLK (serial clock). Its greatest advantage is mounted a plurality of devices on this bus, to be identified and accessed by address; an I2C bus, the greatest advantage is very easy to be implemented in software through the IO port, a data transmission rate which is fully SCLK to control, can be fast or slow, unlike the UART interface, have strict rate requirements.
  Watchdog (Watchdog Timer): Watchdog is a basic configuration of the vast majority of the MCU (MCU number 4 may not have this feature), most of the MCU's Watchdog program only allows them to reset but can not close them (some of them in the program to burn fashionable set, such as Microchip PIC series MCU), MCU while others are to decide whether to open it in a specific way, such as the Samsung KS57 series, as long as the program accesses the Watchdog register automatically open and can no longer be closed. Generally watchdog reset time can be set in a program. The most basic application Watchdog of the MCU is because an unexpected failure caused the crash provides a self-recovery capability.
  : MCU program written in
  the presence of writing programs under preparation with the PC program the MCU big difference, although C-based MCU development tool more and more popular, but for an efficient use of assembly code and favorite designers in terms of assembly language is still the most simple and most effective programming language. For the MCU programming, its basic framework can be said to be roughly the same, generally divided into the initialization section (MCU programming which is the biggest difference with the PC), the main program loop and interrupt handlers into three parts (see Figure 1 a and B), which are described as follows:
  initialization: for the design of all the MCU program is concerned, is the birth of the first and most important step, generally includes the following aspects:
  mask all interrupts and initialize the stack pointer: initialization part generally do not want any interruption;
  Clear system RAM area and display Memory: although sometimes may not completely necessary, but from the perspective of reliability and consistency, especially to prevent unexpected errors, it is recommended to develop good programming habits;
  initializing IO port: according to the requirements of the application program, the setting of the IO input and output ports of the input port needs to be set pullup or pulldown resistor thereon; for output, it is necessary to set out the level of the output, to prevent unnecessary errors;
  interruption settings: for all projects need to use interrupt sources should be given to open and set trigger conditions interruption, and for the extra interrupt is not used, it must give close;
  initialize other functional modules: for all of the necessary function modules of the MCU peripherals must be applied according to the requirements of the corresponding item set, the UART communications as necessary to set the Baud Rate, the length of the data length, parity, and Stop Bit and the like, and for Programmer Timer, you must set its clock source, the frequency division number Reload Data and the like;
  initialization parameters: completion of the MCU hardware and resources After the birth of, the next step is to use the program in a number of variables and data initialization settings, initialization, this part needs to be designed in accordance with the overall arrangements for specific projects and programs. For some applications a number of EEPROM to save the project terms preform, it is recommended initialization copying data related to the MCU of RAM, the program to improve the data access speed while reducing power consumption of the system (in principle, to access the external EEPROM will increase power consumption).
  The main program loop: Most MCU is part of a long uninterrupted run, so the main body are basically designed in a circular manner, for application in terms of the presence of multiple modes of operation, there may be multiple cycles body, to convert each other via a state flag. For the main body, generally follows the major modules:
  calculation program: calculation program is generally more time-consuming, and therefore firmly opposed any interruption in processing, in particular multiplication and division operation;
  real-time sensitive or real-time requirements without handler;
  It shows the transfer procedure: The main application for the presence of an external LED, LCD Driver's.
  Interrupt handler: interrupt handling procedure used mainly for higher real-time requirements of the tasks and events, such as, sudden external signal detected, and key detection processing, timer counter, LED display scanning. Under normal circumstances, the interrupt routine should be as brief as possible and ensure that short codes for functions do not require real-time to deal with, you can set a flag in the interrupt trigger, and then to perform a specific transaction by the main program - this is very important, especially for low-power, low-speed MCU is concerned, we must ensure that all timely response to interrupts.
  For the body of schedule different tasks, different methods of its processing MCU are different. For example, for a low-speed, low-power MCU (Fosc = 32768Hz) applied, taking into account such items are the handheld device and the ordinary LCD display, keys and the reaction of the reaction displayed high real-time requirements, this should be timer interrupt commonly used way to handle the operation and display key data; for high-speed MCU, such as greater than 1MHz Fosc application, since then MCU has enough time to execute the main program loop, it is possible only in the corresponding various interrupt trigger flag is set, and all the tasks performed on the main body;
  the programming of the MCU, also need to pay special attention to the point is: to prevent access or interruption and at the same time the main program body set the same situation a variable or data. Effective prevention is arranged to process such data in a block by determining whether the trigger flag to determine data related to the operation; in other programs in the body (mainly the interrupt), the data required for where only the processing of setting the flag is triggered. - This ensures that the data is performed is predictable and unique.
  In short, MCU development is concerned, we must remember one thing: "All roads lead to Rome", not impossible things, the key is to see whether the method correctly then there are more hands to do more and think!.
  I can exchange learning more private WBL: 13260562029

Guess you like

Origin blog.csdn.net/weixin_42832780/article/details/92773596