1. What is a microcontroller?
Simply put, a single-chip microcomputer is a small computer system. To explain this issue clearly, we have to start with computers. When it comes to computers, you may immediately think of "monitor, mouse, keyboard", but these are not the core and key of a computer. The core of the computer is in the chassis on one side. Open the chassis and you can see that there are motherboards, hard drives, optical drives, etc. in the chassis. Look carefully at the motherboard, which has CPU, memory sticks, BIOS chips, and usually a 25-pin printer interface, etc. These components are connected to each other through the wires on the motherboard.
No matter how complex a computer is, it always consists of five parts: the arithmetic unit, the controller, the memory, the input/output interface, and the bus. Usually the arithmetic unit and the controller are made into a chip, that is, the CPU (central processing unit). On the computer motherboard, the memory stick and the BIOS chip are the memory, the 25-pin printer interface is the input/output device, and the bus is designed on the motherboard, that is, the line that connects the components to each other.
Figure 1
In some applications, people do not need computers to complete very complex calculations, but they hope that the computer is small, reliable and cheap. So people integrated all the five parts of the computer into a chip, that is, a chip can constitute an independent computer. Under the technical conditions at that time, this was a remarkable thing, so people named it "single-chip microcomputer" based on this feature.
If all the five parts needed to form a computer are integrated into one chip, will the chip be very large and expensive? Not really. If all the components on the motherboard shown in Figure 1 are integrated into one chip, it will of course be very expensive and may not be technically feasible. However, the functions required in many single-chip microcomputers do not need to be so powerful, so many single-chip microcomputers are very small and cheap. For example, the common single-chip microcomputers on the market have 8, 14, 16, 18, 20, 28, 40, 84 pins, and some even have only 6 pins. As shown in Figure 2, this is a 6-pin single-chip microcomputer released by Microchip. The prices range from a few yuan to tens or hundreds of yuan, and some varieties can even be as low as 1 yuan when ordered in large quantities.
Figure 2
People who have just come into contact with single-chip microcomputers often have a doubt: since people are already capable of making powerful computers, why do we still produce some computers with weak functions? In fact, the power is not the decisive factor in determining whether to produce, but the market demand is the key. For example, a computer used to control an electric box obviously does not need to use the powerful computing power of the "Pentium" chip. It only needs to perform very simple calculations, make a comparison, see if the temperature is within the control range, and then make corresponding controls.
Single-chip microcomputers are used everywhere in people's lives and in industrial and agricultural production equipment, such as various timing devices, automatic control devices, etc. Enthusiasts who learn single-chip microcomputers should pay attention to observing things and find occasions around them where single-chip microcomputers can be used, so as to apply the knowledge they have learned to practice. For example, using single-chip microcomputer technology to transform traditional electromechanical equipment and using single-chip microcomputers to replace PLCs in specific occasions have broad application prospects; for example, using single-chip microcomputers to control electric fans, range hoods, air conditioners, etc., so as to produce controllers with more powerful functions and universal applications, is also worth trying.
2. How does a microcontroller work?
The working process of the single-chip microcomputer is a process of constantly "fetching instructions-analyzing instructions-executing instructions". The program of the single-chip microcomputer is stored in the program memory in the form of instructions one by one. After the single-chip microcomputer starts working, it starts to fetch instructions from a specific location in the program memory, and then the controller inside the single-chip microcomputer analyzes the instructions. According to the instructions, it performs one or more of the basic operations such as "fetching numbers, sending numbers, arithmetic operations, logical operations, and jumping". These operations are completed in a specified cycle. After execution, it fetches instructions from the next memory unit and repeats the previous operation (of course, the specific content of these operations to be performed may be different from the last time), and repeats this process until the power is turned off. The "specific memory location" and "specified cycle" mentioned here are related to the model of the single-chip microcomputer. The following is an example of the 51 series single-chip microcomputer.
There is a register called PC in the 51 series microcontroller (a container for storing numbers). After the microcontroller is reset, the content of this register is set to 0000H. The controller inside the microcontroller always fetches instructions from the corresponding program memory unit according to the value in the PC register. Therefore, after the power is turned on, the first instruction will be fetched from the 0000H unit, analyzed and executed. At the same time, the PC value will be adjusted accordingly to point to the location of the next instruction to be executed. Where is the location of the next instruction? For the 51 microcontroller, an instruction may occupy one byte, two bytes or three bytes. If the first instruction is a single-byte instruction, after the first instruction is fetched, the value of PC will become 0001H. Therefore, after the first instruction is executed, the second instruction will be fetched from the 0001H unit to execute, and so on. If the program is executed sequentially, the value of PC will always increase. If there is a jump instruction in the program, the instruction will affect the value in PC, so that the value in PC points to the address unit where the next instruction to be executed is located. This jump can be either forward, such as jumping from 0000H to 0030H, or reverse, that is, jumping back, such as jumping from 200H to 100H. It is precisely because instructions can affect the value in PC that programs can implement various functions such as "branching" and "looping". So, how long does it take to execute an instruction? For 51 single-chip microcomputers, there are three possible instruction execution times: single cycle, double cycle and four cycle. No matter how much work an instruction needs to do, it must be completed within the specified time.
3. What is the function of a microcontroller program? How to write it? How to write it into a microcontroller?
The purpose of the microcontroller program is to make the microcontroller "obedient" and complete a series of actions according to the predetermined design, and ultimately achieve a specific function.
For example, when using a single-chip microcomputer to control a running light, after the power is turned on, the light turns on for the first time, then a delay period, the light turns on for the second time, then a delay period, the light turns on for the third time..., after a delay period, the light turns on again for the first time, and the cycle repeats endlessly. Here are some questions: how many lights should be turned on for the first time, how long should the delay period be, how many times should different lights be turned on in a cycle..., these determine the pattern of the running light and the speed of the flow, and the single-chip microcomputer obviously has no self-judgment ability, it must rely on people to "assign" tasks to it, and it executes them in sequence according to people's designs. [page]
To make the microcontroller "obedient", we need to issue commands in a language that the microcontroller can understand. The language that the microcontroller can understand is called "instructions". The instructions that any type of microcontroller can accept are limited. The number of instructions for the 51 microcontroller is 111, while the number of instructions for the PIC microcontroller is only 35. Each instruction completes a basic action. In order to complete a specific function, people need to arrange and combine these instructions into an instruction sequence, which is a program.
There are two forms of instructions: machine language and assembly language. Take 51 as an example. If you want to make the P1.0 pin low, it is expressed in machine language as C2H 90H. Put these two numbers into the program memory of the microcontroller. After the microcontroller executes, the P1.0 pin can be turned to a low level; and if you want to make the P1.0 pin high, it is expressed in machine language as D2H, 90H. As for why these two numbers are used, there is no need to investigate. This is stipulated by the design engineer who designed this chip. We cannot change it, but can only learn from it.
C2H, 90H is an instruction. Obviously, such an instruction form is difficult to remember and programming is also very difficult, so people use "mnemonics" to replace these numbers. For example, the mnemonic of C2H, 90H is CLR P1.0, and the mnemonic of D2H, 90H is SETB P1.0. Since the mnemonics use the abbreviations of English letters and have certain meanings, they are easier to remember and use than digital instructions. Using mnemonic instructions to write programs is called "assembly language source program". However, the assembly language source program cannot be directly sent to the microcontroller. The program written using mnemonic instructions must eventually become such as: C2H, 90H, D2H, 90H, and this form of instruction can be sent to the program memory of the microcontroller. The process of converting mnemonic instructions into digital instructions is called "assembly". There are two methods of assembly. One is "manual assembly", that is, people find the digital form of the assembly instructions by looking up a table and then write it down; the other is "machine assembly", that is, after writing the assembly language source program, use a computer software to process these source programs to obtain a digital instruction sequence. This instruction sequence is usually called "machine code", which is code that can be directly executed by a machine.
The digital instruction sequence obtained after the machine is assembled is saved on the disk in the form of a file. The extension of this file is generally HEX, which is commonly known as a HEX file. After obtaining the HEX file, it can be written into the program memory. To write the program into the chip, a special device called a "programmer" is usually required. Run the matching programming software on the computer, and then open the HEX file in this software to write it into the chip. With the development of technology, there are more and more programming methods, but the general concept is this. The specific details will be answered in another question "What is a microcontroller programmer?"
4. What does the “XX bit” in 8-bit, 16-bit, and 32-bit microcontrollers mean?
8-bit, 16-bit, and 32-bit refer to the "word length" of the microcontroller, that is, the length of the data involved in an operation. This bit refers to the binary bit. Taking 8-bit as an example, the expression range of 8-bit binary is 0000, 0000~1111, 1111 is 0~255 in decimal, that is, the maximum data involved in each operation cannot exceed 255. The word length of a 16-bit machine is 16 bits, and its data expression range is 0~65535, that is, the maximum data involved in each operation cannot exceed 65535; the word length of a 32-bit microcontroller is 32 bits, and its data expression range is 0~4294967295, that is, the maximum data involved in each operation cannot exceed 4294967295.
8-bit, 16-bit, and 32-bit are closely related to the performance of single-chip microcomputers. Usually, the performance of 32-bit microcomputers is higher than that of 16-bit microcomputers, and the performance of 16-bit microcomputers is higher than that of 8-bit microcomputers. Why is this so? This needs to be analyzed from two aspects. First, the number of bits is different, and the operation efficiency is different. For an 8-bit microcomputer, since each number in an operation cannot exceed 8 bits, even an operation such as 100+200=300 cannot be completed at one time, because 300 exceeds the maximum range that 8 bits can express (255). Therefore, to operate such an equation, it is necessary to write a program to complete the operation step by step and finally synthesize it to get a correct result. If a 16-bit microcomputer is used for operation, then one operation is enough. Obviously, the time required for step-by-step completion is much longer than the time required for single-step completion. By the same token, when the result or intermediate value of a certain operation is greater than 65535, a 16-bit microcomputer cannot operate at one time and must implement it step by step, while a 32-bit microcomputer can complete it at one time. Second, commercial factors. Generally speaking, the higher the computing power, the stronger the performance of the microcontroller. Of course, people can accept a higher price. With price space, manufacturers will usually provide more other functions in these chips to further improve the overall performance of the chip.
Among typical single-chip microcomputers, the 80C51 series, PIC series, and AVR series are all 8-bit single-chip microcomputers; the 80C196 and MSP430 series are 16-bit machines; and the currently very popular ARM series is a 32-bit machine.
5. What are microcontroller programmers, emulators, writers, and download cables? What are their uses?
The MCU programmer is a tool used to write program code into the memory chip or the internal part of the MCU. Figure 5-1 shows a typical programming appearance. The black integrated circuit socket in the figure can be locked or loosened by pulling the handle. Lock it during programming to ensure good contact, and loosen it after programming to replace the next chip.
Figure 5-1 Programmer
When the chip is in dual in-line form, it can be burned by directly inserting it into the socket. But if you encounter chips in various packaging forms as shown in Figure 5-2, how to write and burn them? One way is to use an adapter. Figure 5-3 shows the adapters used for various packaged chips.
Figure 5-2 Integrated circuits in various packaging forms
QFN32 Adapter SOP28 Adapter
Figure 5-3 Programming adapters of various packages
Another method is to use a download cable. With the advancement of technology, more and more single-chip microcomputer chips begin to support the "ISP" function, that is, In System Programmer, online programming technology. Using this technology, a blank (unprogrammed) chip is directly soldered on the printed circuit board, and the chip can be programmed using a few pre-reserved pins. There is no need to remove the chip and put it on the programmer. Therefore, this brings great convenience to small-batch production and saves the purchase of expensive adapters. Figure 5-4 shows a schematic diagram of using a download cable to program the chip online.
Figure 5-4 Schematic diagram of download line for online programming of chip [page]
6. What are the necessary hardware equipment for self-learning microcontrollers?
In order to learn about microcontrollers, in addition to a computer, you also need the following equipment.
1. Experimental board
If you know nothing about single-chip microcomputers, it is a good choice to make or buy an experimental board. Usually, some common devices such as switches, LED indicators, digital tubes, various interface chips, etc. are designed on the experimental board. Through programming exercises on these devices, you can gradually master the programming technology of single-chip microcomputers.
2. Simulation machine
The purpose of the simulator is to replace the MCU chip on the circuit board. The simulator communicates with the PC through serial ports, USB interfaces, etc., receives instructions from the PC control software, and executes programs in various ways such as single-step, process single-step, and full-speed operation. When executing programs in single-step or process single-step mode, the results of the execution can be fed back to the PC control software for display after each execution of the program. Since it is necessary to clearly know what the results will be after each instruction is executed when programming the MCU, and to find out whether the actual results after the operation are consistent with the expected results, the simulation function can play an important role in the study and development of MCUs.
3. Programmer or download cable
Its purpose is to write the code into the microcontroller chip. For learners, if you have a simulator, you don't need a programmer or download cable for the time being, because you can do experiments with a test board and simulator. However, it is recommended to configure one, so that you can understand all aspects of microcontroller development.
4. Multimeter, soldering iron and other electronic production tools
Microcontroller development is not a simple programming. So far, there are few pure "microcontroller programmers". Developers are usually required to be familiar with both software and hardware. Therefore, these electronic production work still needs to be equipped.
It should be noted that the simulators, experimental boards, download cables or programmers mentioned here are general concepts and do not involve specific products. There are also some products on the market that integrate part or all of the experimental boards, simulation functions, download or programming functions into one board during design to form a complete experimental system.
All the equipment introduced above require a certain amount of investment, and enthusiasts may not necessarily be able to buy them. In fact, as long as you have a certain level of hands-on ability, you can also make some simple experimental equipment and start learning. Here we recommend the use of STC microcontrollers for learning. The feature of the STC series of microcontrollers is that they can directly download programs through the serial port, thereby minimizing the cost of development tools. As shown in Figure 6-1, this is a complete circuit. The device cost is only more than 20 yuan, but it can realize some common functions such as single light flashing, running lights, key-controlled lights, PC-controlled lights, etc., so as to learn basic instructions, timers, counters, serial port communications and other microcontroller knowledge.
Figure 6-1 Simple microcontroller experimental circuit board
In the figure, R1~R9 are 1K resistors, D1~D8 are light-emitting diodes, E1 uses 10u electrolytic, Y1 uses 11.0592M crystal, C1 and C2 use 27P small magnetic pieces, C3~C7 use 104 magnetic pieces, U1 uses STC89C52 chip, and U2 uses MAX232. Then make or buy a serial cable for communication with the computer. When making the cable, connect J1 to the serial port 2, 3, and 5 of the computer respectively.
After making this circuit board, use Keil software (you can download the DEMO version at http://www.keil.com/demo/default.asp?bhcp=1) to compile and link the program to obtain the Hex file. Use STC_ISP software (download from http://www.mcu-memory.com) to write the Hex file into the chip to observe the effect of the program running.
7.What are the commonly used single-chip microcomputers in China?
1.80C51 and its compatible series
(1) 80C51 series, which is the most basic series. It includes 80C31, 80C51, 87C51, 80C32, 80C52, 87C52 and other chips. Although these chips are basically no longer used, they are the basis of subsequent chips. Among them, the 80C31 microcontroller has no ROM inside, the 80C51 has a one-time 4K PROM, and the 87C51 has a 4K EEPROM. The internal RAM of these chips is 128 bytes. The internal RAM of the last three chips is 8K, and the internal ROM of the last two chips is 8K bytes.
(2)80C51 compatible series
These chips are usually compatible with the 51 series MCU at the instruction level, but they have expanded many new functions. The most common ones are as follows.
The main features of the STC89 series microcontrollers are: direct programming of the microcontroller through the serial port; programmable to run at multiple speeds; ultra-low power consumption; built-in watchdog; internal FLASH ROM can be used as EEPROM to save data when power is off.
The main features of STC12 series microcontrollers are: single clock cycle, operating frequency 0~35M, equivalent to ordinary 80C510~420M; wide voltage range; low power consumption; built-in E2PROM function on the chip; built-in hardware watchdog; general I/O ports can be set to four working modes and can "spit out" current in strong pull-up mode.
The main features of Philips' LPC series are: built-in RC oscillator, no external oscillation device is required when selecting the RC oscillator; all ports have 20mA LED driving capability; and a wide operating voltage range.
The main features of the C8051F series are: one machine cycle is only one clock cycle; an interrupt source is added; there is an internal independent clock source or an external clock, and the internal and external clocks can be switched when the program is running. Each I/O port pin can be set to push-pull or open-drain output. The most unique feature of the C8051F series microcontroller I/O port is the addition of a digital cross switch, which can be used to direct internal digital system resources to the P0, P1 and P2 port I/O pins. Many models of chips in this series have functions such as ADC, DAC, PCA, etc.
2.PIC series
The development idea of PIC microcontroller is different from that of 51 microcontroller. It does not simply pile up functions, but starts from reality, attaches importance to the performance and price ratio of products, relies on the development of multiple models to meet the application requirements of different levels; streamlined instructions greatly improve its execution efficiency. There are currently hundreds of varieties of PIC10, PIC12, PIC16, and PIC18 series. Take the PIC16F676 chip as an example. The chip has a built-in 1K word FLASH ROM, 128 bytes EEPROM, 64 bytes RAM, 8-channel 10-bit AD converter, built-in oscillator with an accuracy of up to ±1%, extremely low power consumption, and a wide operating voltage range. Such a high-performance 14-pin chip costs less than ¥7, and the cost performance is quite high.
3.AVR series
AVR series microcontrollers are enhanced RISC structure microcontrollers, and their main features are: fast speed, one machine cycle is only one clock cycle; rich variety, similar to the PIC series, relying on the development of multiple models to meet different levels of application requirements; support ISP, IAP functions, online programming, convenient remote maintenance; wide working range, strong anti-interference ability. Take the ATMEGA8 chip as an example, the chip has built-in 8K Flash ROM, 512 bytes EEPROM, 1K bytes RAM, 8-channel 10-bit AD, and built-in RC oscillator. Such a high-performance 28-pin chip costs only about ¥7, and the cost performance is also quite high.
4. Others
Other commonly used single-chip microcomputers include: ST, EMC, Motorola, Samsung, etc. Some of these single-chip microcomputers have a large market share, but we did not focus on introducing them because the content we introduced is mainly for amateurs. Although some chips are powerful and cost-effective, they are not targeted at amateurs. Small batches of chips are difficult to buy, and the price of development tools such as emulators and C compilers is extremely expensive, so we will not introduce them here. If you are interested, you can search for relevant information on the Internet. [page]
8.What is the approximate price of commonly used microcontrollers?
The prices of microcontrollers vary greatly, ranging from less than 1 yuan to tens of yuan or even hundreds of yuan. The following is a brief introduction to the prices of commonly used microcontrollers.
The price of a microcontroller is closely related to its shipment volume and performance. Take the 80C51 series of microcontrollers as an example. This is a huge series, and the performance of the microcontrollers in this series varies greatly. For example, the internal ROM is different, ranging from 1K to 64K; the number of pins is different, ranging from 14 pins to 84 pins; the internal RAM is different, ranging from 128 bytes to 2K; the internal modules are different, such as some microcontrollers are equipped with 8-bit analog-to-digital converters, some are equipped with 10-bit analog-to-digital converters, and some have CCP modules inside. The prices of microcontrollers with different configurations are different. The price of the 89S52 microcontroller chip commonly used by enthusiasts is about 6 yuan. This chip has an internal ROM of 8K, an internal RAM of 128 bytes, and an internal watchdog circuit. A commonly used PIC microcontroller, PIC16F676, has 14 pins and a 10-bit AD converter, and the price is only about 7 yuan. Generally, the more powerful the function, the higher the price, but this is not absolute, especially for the same type of products from different manufacturers, which often cannot be directly compared. Therefore, if readers want to know the prices of various chips, they still have to search for specific models. There are some websites with relevant quotations for reference.
9. What are the commonly used software for microcontroller programming, simulation, and debugging?
Different types of microcontrollers require different development software. We will use the 80C51 series, PIC series and AVR series as examples to explain them respectively.
The writing of single-chip microcomputer programs does not require any special software, as long as it is a text editor software, such as the notepad and WORD that come with WINDOWS, but these software are not convenient to write. There are some better text editors to choose from, such as UltraEdit, PE2, etc. Of course, people most often use the editor that comes with the development software to write. Taking the 80C51 series single-chip microcomputer as an example, the most popular software is Keil software. Keil software is a comprehensive development tool with built-in editors, ASM assemblers, C51 compilers, debuggers, etc. Figure 9-1 is a schematic diagram of the Keil software interface.
Figure 9-1 Keil software
MPLAB IDE is commonly used for PIC series development software, as shown in Figure 9-2. MPLAB Integrated Development Environment (IDE) is a comprehensive editor, project manager and design platform suitable for embedded design application development using Microchip PICmicro and dsPIC microcontrollers. This software can be used to: create and edit source code using the built-in editor; assemble, compile and link source code; debug executable logic by observing program flow using the built-in software simulator, or by observing program flow in real time using an online emulator or online debugger; perform timing measurements using a software simulator or emulator; view variables in the Watch window; and use a device programmer to burn machine code into the device.
Figure 9-2 MPLAB IDE development software
The commonly used development software for AVR microcontrollers is AVR Studio, as shown in Figure 9-3.
Figure 9-3 AVR Studio software
AVR Studio is an embedded development environment (IDE) for writing and debugging AVR applications under Windows 9x/Me/NT/2000/XP operating systems. AVR Studio provides project management tools, source file editors, chip simulators and in-circuit emulation debugging interfaces for AVR 8-bit RISC instruction set microcontrollers.
10. Can you recommend some books or other tutorials for learning microcontrollers?
There are a lot of books on microcontrollers on the market. For beginners, it is generally better to choose the 80C51 series. If you have a clear work object, that is another matter.
This book is mainly aimed at beginners. Based on the author's self-study and many years of experience in teaching microcontrollers, and in view of the fact that it is not easy for beginners to get started, it adopts the "task-based teaching method", focusing on tasks such as "lighting up the LED", "making the LED flash", "key-controlled lights", and "flowing lights". It introduces methods to achieve these functions and in the process of achieving these tasks, readers will learn about the internal structure of the microcontroller, the use of Keil software, the use of development tools, etc., so that readers can easily get started.
Previous article:Interrupt timer source program - 0-99 seconds adjustable time
Next article:The process of learning single chip microcomputer
Recommended ReadingLatest update time:2024-11-16 22:47
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Gossip negative feedback
- Do you think domestic regulators will prevent Nvidia from acquiring ARM?
- PFC switching power supply has these performance characteristics, do you know?
- Problems with encrypted transmission of STC microcontroller programs
- Issues that need attention when initializing SPI of C2000 series 280049 chip
- [Power amplifier case] Application of power amplifier based on voice coil motor test system design
- TI BMS Power Battery Management Technology: Why do batteries fail? How does BMS manage them?
- Music control board made by CircuitPython
- What can the PG pin of CH221K be used for?
- AMEYA360 design solution | Intelligent LED lighting solution based on TI