Basic functions of the MCU

Basic functions of the MCU

For most MCUs, the following functions are the most common and basic. For different MCUs, the description may be different, but they are basically the same in essence.

1. TImer (timer): Although there are many types of TImer, they can be classified into two categories: one is TImer with fixed time interval, that is, its timing is set by the system, and the user program cannot be controlled. Only several fixed time intervals are provided for the user program to choose, such as 32Hz, 16Hz, 8Hz, etc. This kind of TImer is more common in 4-bit MCU, so it can be used to realize related functions such as clock and timing.

The other type is Programmable Timer (programmable timer). As the name suggests, the timing time of this type of Timer can be controlled by the user's program. The control methods include: selection of clock source, selection of frequency division (Prescale) and Prefabricated number setting, etc. Some MCUs have all three at the same time, while others may have one or two of them. This kind of Timer application is very flexible, and the actual use is also ever-changing. One of the most common applications is to use it to realize PWM output.

Since the clock source can be freely selected, such Timers are generally combined with Event Counters.

图片无替代文字

2. IO ports: Any MCU has a certain number of IO ports. Without IO ports, the MCU will lose the communication channel with the outside world. According to the configuration of the IO port, it can be divided into the following types:

Pure input or pure output port: This type of IO port is determined by the MCU hardware design. It can only be input or output, and cannot be set by software in real time.

Directly read and write IO ports: For example, the IO ports of MCS-51 belong to this type of IO ports. When executing the read IO port instruction, it is an input port; when executing a write IO port instruction, it is automatically an output port.

Program programming to set the input and output direction: the input or output of this type of IO port is set by the program according to the actual needs, the application is relatively flexible, and some bus-level applications can be realized, such as I2C bus, various LCDs, LED Drivers control bus, etc.

For the use of the IO port, the important point must be kept in mind: for the input port, there must be a clear level signal to ensure that it cannot be floating (it can be achieved by adding a pull-up or pull-down resistor); for the output port, its output The state level must consider its external connection, and it should be ensured that there is no current source or sink in the Standby or static state.

图片无替代文字

3. External interrupt: External interrupt is also a basic function of most MCUs. It is generally used for real-time triggering of signals, data sampling and status detection. There are several types of interrupts: rising edge, falling edge trigger and level trigger. External interrupts are generally implemented through input ports. If it is an IO port, the interrupt function will only be enabled when it is set to input; if it is an output port, the external interrupt function will be automatically turned off (there are some exceptions in the ATiny series of ATMEL, the output port can also trigger the interrupt function). The application of external interrupt is as follows:

Detection of external trigger signals: one is based on real-time requirements, such as the control of silicon controlled rectifiers, detection of burst signals, etc., and the other is the need for power saving.

Measurement of signal frequency: In order to ensure that the signal is not missed, an external interrupt is the ideal choice.

Data decoding: In the field of remote control applications, in order to reduce the design cost, it is often necessary to use software to decode various encoded data, such as the decoding of Manchester and PWM encoding.

Key detection and system wake-up: For an MCU that enters the Sleep state, it generally needs to be woken up through an external interrupt. The most basic form is a key, and the level change is generated by the action of the key.

图片无替代文字

4. Communication interface: The communication interface provided by MCU generally includes SPI interface, UART, I2C interface, etc., which are described as follows:

SPI interface: This type of interface is the most basic communication method provided by most MCUs. Its data transmission is controlled by a synchronous clock. The signals include: SDI (serial data input), SDO (serial data output), SCLK (serial clock) and Ready signal; in some cases, there may be no Ready signal; this type of interface can work in Master mode or Slave mode, the popular saying is to see who provides the clock signal, the party that provides the clock is the Master, and the opposite party Then it is Slaver.

UART (Universal Asynchronous Receive Transmit): It is the most basic asynchronous transmission interface. Its signal lines are only Rx and Tx. The basic data format is: Start Bit + Data Bit(7-bits/8-bits) + Parity Bit(Even, Odd or None) + Stop Bit(1~2Bit). The time taken by one bit of data is called Baud Rate (baud rate).

For most MCUs, the length of data bits, data check method (odd check, even check or no check), the length of stop bit (Stop Bit) and Baud Rate can be flexibly set through programming. Certainly. The most commonly used way of this type of interface is to communicate with the serial port of the PC.

I2C interface: I2C is a data transmission protocol developed by Philips, which is also realized by two signals: SDAT (serial data input and output) and SCLK (serial clock). Its biggest advantage is that multiple devices can be connected to this bus, which can be identified and accessed through addresses; one of the biggest benefits of the I2C bus is that it is very convenient to use software to realize it through the IO port, and its transmission data rate is completely controlled by SCLK To control, it can be fast or slow, unlike the UART interface, which has strict speed requirements.

5. Watchdog (watchdog timer): Watchdog is also a basic configuration of most MCUs (some 4-bit MCUs may not have this function), and most MCU Watchdogs can only allow programs to reset them and cannot reset them. It is closed (some are set when the program is burned in, such as Microchip PIC series MCU), and some MCUs decide whether to open it through a specific method, such as Samsung's KS57 series, as long as the program accesses the Watchdog register, is automatically turned on and cannot be turned off again. Generally speaking, the reset time of watchdog can be set by program. The most basic application of Watchdog is to provide a self-recovery capability for the MCU to crash due to unexpected failures.

图片无替代文字

要查看或添加评论,请登录

Hedy Chip supplier的更多文章

社区洞察

其他会员也浏览了