
Principle and application development of single chip microcomputer

MCU is the abbreviation of microcontroller unit, which is called microcontroller in Chinese and commonly known as single chip microcomputer. It appropriately reduces the frequency and specification of CPU, and integrates the peripheral interfaces such as memory, counter, USB, a / D conversion, UART, PLC, DMA and even LCD drive circuit on a single chip to form a chip level computer to do different combined control for different applications, such as mobile phone MCU can be seen in PC peripherals, remote controls, automotive electronics, industrial stepping motors, robot arm control, etc.
Brief history of single chip microcomputer development
The history of single chip microcomputer is not long, but it develops very rapidly. Its emergence and development are roughly synchronized with the emergence and development of microprocessor (CPU). Since Intel first launched 4-bit microprocessor in 1971, its development can be roughly divided into five stages. The following is an introduction to the development of single chip microcomputer of Intel company.
1971 ~ 1976
The primary stage of the development of single chip microcomputer. In November 1971, Intel first designed a 4-bit microprocessor Intel 4004 with an integration of 2000 transistors / chip, equipped with RAM, ROM and shift register, forming the first mcs-4 microprocessor, and then introduced an 8-bit microprocessor Intel 8008, as well as 8-bit microprocessors successively introduced by other companies.
1976 ~ 1980
Low performance MCU stage. Represented by Mcs-48 series launched by Intel in 1976, it adopts a monolithic structure integrating 8-bit CPU, 8-bit parallel I / O interface, 8-bit timing / counter, ram and ROM on a semiconductor chip. Although its addressing range is limited (no more than 4 KB), there is no serial I / O, the capacity of ram and ROM is small, and the interrupt system is relatively simple, However, the function can meet the needs of general industrial control and intelligent instruments and meters.
1980 ~ 1983
High performance MCU stage. The high-performance 8-bit MCU launched at this stage generally has serial port, multi-level interrupt processing system and multiple 16 bit timers / counters. The capacity of on-chip RAM and ROM is increased, and the addressing range can reach 64 kb. Some on-chip are also equipped with a / D conversion interfaces.
1983 ~ late 1980s
16 bit MCU stage. In 1983, Intel introduced the high-performance 16 bit MCU MCS-96 series. Due to the latest manufacturing technology, the chip integration is as high as 120000 transistors / chip.
191990s
Single chip microcomputer is developing to a higher level in all aspects such as integration, function, speed, reliability and application fields.
Classification and application of single chip microcomputer
MCU can be divided into no on-chip ROM type and with on-chip ROM type according to its memory type. For chips without on-chip ROM, EPROM must be connected externally to be applied (typical 8031); Chips with on-chip ROM type are divided into on-chip EPROM type (typical chip is 87C51), mask on-chip mask ROM type (typical chip is 8051), on-chip flash type (typical chip is 89C51), etc.
According to the purpose, it can be divided into general type and special type; According to the width of the data bus and the length of data bytes that can be processed at one time, it can be divided into 8, 16 and 32-bit MCU.
At present, the domestic MCU application market is the most widely used in the field of consumer electronics, followed by the industrial field, and automotive electronics market. Consumer electronics include household appliances, televisions, game consoles, audio and video systems, etc. Industrial fields include smart home, automation, medical applications and new energy generation and distribution. The automotive field includes automotive powertrain and safety control system.
Basic functions of single chip microcomputer
For most MCU, the following functions are the most common and basic. For different MCU, the description methods may be different, but they are basically the same in essence.
Timer: Although there are many types of timers, they can be divided into two categories: one is the timer with fixed time interval, that is, the timing time is set by the system and can not be controlled by the user program. The system only provides several fixed time intervals for the user program to choose, such as 32Hz, 16Hz, 8Hz, etc. such timers are common in 4-bit MCU, Therefore, it can be used to realize clock, timing and other related functions.
The other is programmable timer. As the name suggests, the timing time of this kind of timer can be controlled by the user's program. The control methods include: selection of clock source, selection of Prescale number and setting of preset number. Some MCU have all three at the same time, while others may be one or two of them. This kind of timer application is very flexible, and its actual use is also changeable. 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 counter.
IO port: any MCU has a certain number of IO ports. Without IO ports, MCU will lose the channel of external communication. According to the configuration of IO ports, they can be divided into the following types.
Pure input or pure output: this kind of IO port is determined by MCU hardware design. It can only be input or output, and software can not be used for real-time setting.
Direct read / write IO port: for example, the IO port of MCS-51 belongs to this kind of IO port. When the instruction of reading IO port is executed, it is the input port; When the write IO port instruction is executed, it is automatically the output port.
Program programming to set the input and output direction: the input or output of this kind of IO port is set by the program according to the actual needs. The application is flexible and can realize some bus level applications, such as I2C bus, control buses of various LCD and LED drivers, etc.
For the use of IO port, it is important to remember that there must be a clear level signal for the input port to ensure that it cannot float (it can be realized by adding pull-up or pull-down resistance); For the output port, the external connection must be considered for the output state level, and there shall be no pull current or fill current in standby or static state.
External interrupt: external interrupt is also the basic function of most MCU. It is generally used for real-time signal triggering, data sampling and state detection. The interrupt modes are triggered by rising edge, falling edge and level. External interrupt is generally realized through input port. If it is IO port, its interrupt function will be enabled only when it is set as input; If it is an output port, the external interrupt function will be automatically closed (there are some exceptions in atiny series of ATMEL, and the interrupt function can also be triggered at the output port). The application of external interrupt is as follows:
Detection of external trigger signals: one is based on real-time requirements, such as thyristor control, detection of sudden signals, etc., while the other is the need to save power.
For the measurement of signal frequency, in order to ensure that the signal is not missed, external interrupt is the most ideal choice.
Data decoding: in the field of remote control applications, in order to reduce the design cost, software is often used to decode various encoded data, such as Manchester and PWM encoding decoding.
Key detection and system wake-up: MCU entering sleep state generally needs to wake up through external interrupt. The most basic form is the key, and the level change is generated through the action of the key.
Communication interface: the communication interfaces provided by MCU generally include SPI interface, UART, I2C interface, etc., which are described as follows:
SPI interface: this kind of interface is the most basic communication mode provided by most MCU. Its data transmission is controlled by 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 kind of interface can work in master mode or slave mode. In popular terms, it depends on who provides the clock signal. The party providing the clock is the master and the other party is the slave.
UART (universal asynchronous receive transmit): it is the most basic asynchronous transmission interface, with only RX and TX signal lines. 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 occupied by one bit of data is called baud rate.
For most MCU, the length of data, data verification mode (odd verification, even verification or no verification), the length of stop bit and baud rate can be flexibly set through program programming. The most common way of this kind of interface is data communication with the serial port of 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 attached to this bus for identification and access through addresses; One of the biggest advantages of I2C bus is that it is very convenient to use software to realize it through IO port. The data rate transmitted is completely controlled by SCLK, which can be fast or slow. Unlike UART interface, it has strict rate requirements.
Watchdog timer: watchdog is also a basic configuration of most MCUs (some 4-bit MCUs may not have this function). The watchdog of most MCUs can only be reset by the program and cannot be closed (some are set when the program is burned in, such as Microchip PIC Series MCU), while some MCU decide whether to turn it on in a specific way, Such as Samsung's ks57 series, as long as the program accesses the watchdog register, it will be automatically turned on and can no longer be turned off. Generally speaking, the reset time of watchdog can be set by program. The most basic application of watchdog is to provide a self recovery ability for MCU crash caused by accidental failure.
Learning tips of single chip microcomputer
The basic principles and functions of any MCU are similar. The only difference is the configuration and number of peripheral function modules, instruction system, etc.
Although the instruction system looks very different in form, it is actually just different in symbols. Its meaning, functions to be completed and addressing methods are basically similar.
To understand an MCU, we first need to know its ROM space, RAM space, number of IO ports, number and timing mode of timers, peripheral circuit provided, interrupt source, working voltage and power consumption, etc.
After understanding these MCU features, the first step is to compare the functions of the selected MCU with the functions required by the actual project development to clarify which resources are needed at present and which are not used in the project.
For the functions that need to be used in the project but are not provided by the selected MCU, it is necessary to carefully understand the relevant data of MCU in order to realize them by indirect methods. For example, the developed project needs to communicate with PC COM port, while the selected MCU does not provide UART port, it can be realized by external interrupt.
For the resources needed for project development, manua * needs to be carefully understood and read, while the unnecessary functional modules can be ignored or browsed. For MCU learning, application is the key and the main purpose.
After defining the relevant functions of MCU, you can start programming.
For beginners or designers who use this MCU for the first time, they may encounter many unclear descriptions of MCU functions. For such problems, two methods can be used to solve them. One is to write a special verification program to understand the functions described in the data; The other can be ignored temporarily. The MCU program design is written according to its current understanding and left to be modified and improved during debugging. The former method is suitable for projects with loose time and beginners, while the latter method is suitable for people with certain MCU development experience or the situation of urgent project progress.
The instruction system must not take special time to understand. The instruction system is just a symbol of logic description. You can only view the relevant instructions according to your own logic and program logic requirements during programming. Moreover, with the progress of programming, you will become more and more proficient in the instruction system, and you can even remember it unconsciously.
Programming of single chip microcomputer
The programming of MCU is very different from that of PC. although MCU development tools based on C are becoming more and more popular, assembly language is still the most concise and effective programming language for an efficient program code and a designer who likes to use assembly.
The basic framework of MCU programming can be said to be generally consistent. It is generally divided into three parts: initialization part (which is the biggest difference between MCU programming and PC), main program loop body and interrupt processing program, which are described as follows:
Initialization: for the design of all MCU programs, birth is the most basic and important step, which generally includes the following contents:
Mask all interrupts and initialize the stack pointer: the initialization part generally does not want any interrupts to occur.
Clear the RAM area and display memory of the system: although it may not be completely necessary sometimes, it is recommended to develop good programming habits from the perspective of reliability and consistency, especially to prevent accidental errors.
Initialization of IO port: set the input and output mode of relevant IO port according to the application requirements of the project. For the input port, it is necessary to set its pull-up or pull-down resistance; For the output port, the output level must be set to prevent unnecessary errors.
Interrupt setting: the interrupt sources needed for all projects should be turned on and the trigger conditions for interrupts should be set, while the unused redundant interrupts must be turned off.
Initialization of other functional modules: for all peripheral functional modules of MCU that need to be used, corresponding settings must be made according to the application requirements of the project, such as UART communication, baud rate, data length, verification method and stop bit length. For programmer timer, its clock source, frequency division number and reload data must be set.
Parameter birth: after the birth of MCU hardware and resources, the next step is to initialize some variables and data used in the program
Commax-Tech Electronic Co., Ltd Electronic component specialist
B23, second floor, ASEAN building, Longhua District, Shenzhen
sales@commax-tech.com
https://commax-tech.com
Keyword:Single chip microcomputer MCU microcontroller mobile phone PC peripheral remote control automotive electronics industrial stepping motor robot control no on-chip ROM type with on-chip ROM type IO port SPI interface UART I2C interface Commax-Tech Electronic
Relevant information
-
What does the new specification approved by risc-v mean?
-
Use cases of 8-bit MCU and 32-bit MCU
-
Analysis of vehicle MCU
-
Discussion on RF PCB design
-
Summary of WiFi module suitable for novice learning
-
Detailed explanation of WiFi module applicable to set-top box
-
Selection Guide for on-board special crystal oscillator
-
GPS navigation is not accurate, quartz crystal oscillator has the final say!
-
Understand the importance of chip crystal oscillator by disassembling outdoor sports smart watches
-
Relationship between differential crystal oscillator and quartz crystal oscillator
-
How to control the temperature has become the number one problem in the use of quartz crystal oscillator
-
How to judge the pin order of IC chip
-
What is an IC chip
-
Difference between triode BJT and FET
-
FET -- understanding the function of capacitance in circuit from its name


