1. What is a microcontroller? In simple terms, a microcontroller is a small computer system. In order to clarify this issue, we must start with the computer. When it comes to computers, you may immediately think of "monitors, mice, and keyboards." However, this is not the core and key of a computer. The core part of the computer is in the side chassis. Open the chassis, you can see, there are motherboards, hard drives, optical drives and so on. Look carefully at the motherboard, which has a CPU, a memory stick, a BIOS chip, and usually a 25-pin printer interface. These components are connected to each other through the connections on the motherboard. Regardless of the complexity of the computer, it always consists of five parts: the operator, the controller, the memory, the input/output interface, and the bus. Usually the calculator and controller are made into a single chip, which is the CPU (Central Processing Unit). On a computer motherboard, the memory module and the BIOS chip are memories, the 25-pin printer interface is an output/output device, and the bus is designed on the motherboard, which is the line connecting the components to each other. In some applications, people don't need computers to perform very complex operations, but they want the computer to be small, reliable, and low in price. So people integrated the five parts that make up a computer into a single chip. It also means that a single chip can constitute an independent computer. Under the current technological conditions, this is a remarkable thing, and people use it. This feature is named for it, called "single chip microcomputer." All the five parts that make up a computer are all integrated into a single chip. Does the chip have to be large and the price is high? This is not the case. If all the components on the main board shown in Fig. 1 are to be integrated into a single chip, it is of course very expensive and may not be technically feasible. However, the functions required by many microcontrollers are not necessarily so powerful, so many microcontrollers The volume is small and the price is very low. For example, there are 8, 14, 16, 18, 20, 28, 40, 84 and other pins on the market, and some even have only 6 pins, as shown in Figure 2 is a chip released by Microchip. 6-pin microcontroller. Prices range from a few dollars to tens or hundreds of dollars. Some varieties can even be as low as 1 yuan or less when ordered in large quantities. People who have just come into contact with MCUs often have doubts: Since people are already capable of producing powerful computers, why do they need to produce more powerful computers? In fact, the strength of function is not a decisive factor in deciding whether or not to produce, and the market needs. It is the key. For example, the computer used to control an electrical box obviously does not need to use the "Pentium" chip's powerful computing power, as long as a very simple calculation, a comparison, see if the temperature is within the control range, and then make The corresponding control will do. Microcontrollers are used everywhere in people's lives, industrial and agricultural production equipment, such as timing devices, automatic control devices, and so on. Enthusiasts learning MCU should pay attention to observing things and find the occasions around which they can use the MCU, so as to apply the learned knowledge to the actual situation. For example, the use of single-chip technology to transform the traditional mechanical and electrical equipment, the use of single-chip instead of PLC in a particular situation has a broad application prospects; for example, the use of single-chip control of electric fans, range hoods, air conditioners, etc., in order to produce a stronger function, A universal controller can also be tried. 2. How does a microcontroller work? The working process of the single-chip microcomputer is a process of constantly "taking instructions - analyzing instructions - executing instructions". The program of the one-chip computer is stored in the program memory in the form of one instruction. After the one-chip computer starts to work, the instruction is fetched from the specific position of the program memory. Then the instruction is analyzed by the controller inside the single-chip microcomputer and the instruction is executed according to the requirements of the instruction. One or more of basic operations such as number, number, arithmetic operation, logic operation, jump, etc. These operations are completed in a specified cycle. After the execution is completed, instructions are fetched in the next memory unit and repeated. Just the operation (of course, the specific content of these operations may not be the same as the previous one), so continue to repeat until the power outage. The “memory-specific location†and “prescribed period†mentioned here are related to the model of the MCU. The following is a description of the 51-series MCU as an example. There is a register named PC (which is used to store a number of containers) in the 51 series MCU. After the MCU is reset, the contents of this register is set to 0000H. The controller inside the MCU is always based on the PC register. The value goes to the corresponding program memory unit to fetch the instruction. Therefore, after booting, the first instruction will be fetched from the 0000H unit and analyzed and executed. At the same time, the PC value will be adjusted accordingly, pointing to the position of the next instruction to be executed, and the next Where is the position of the instruction? For a 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 taken, The PC's value will become 0001H. Therefore, after the first instruction is executed, the second instruction will be fetched from the 0001H unit, and so on. If the program is executed sequentially, the value of the PC will always increase. If there is a jump instruction in the program, the instruction will affect the value in the PC so that the value in the PC points to the address of the next instruction to be executed. This jump may be positive, such as jumping from 0000H to 0030H, or it may be reversed, that is, jumping back, such as jumping from 200H to 100H. It is precisely because the instruction can affect the value in the PC, so that the program can achieve "branches", "loop" and other functions. So, how long does it take to execute an instruction? For 51 microcontrollers, there are three possible instruction execution times, one cycle, two cycles, and four cycles. No matter how much work an instruction requires, it must be completed within the specified time. . 3. What is the role of the microcontroller program? How to write? How to write to the microcontroller? The purpose of the SCM program is to make the SCM “obedient†and to complete a series of actions according to people's intended design, and ultimately achieve a specific function. For example, when using a single-chip microcomputer to control the flow of water, after the power is turned on, the first light is on, and then the delay is for a period of time, the second light is on, and then the delay is for a period of time, the third light is on, and the time is delayed for a period of time. Once the lights are on, the cycle is endless. Here are some of the questions: how many times the first light is on, how much time is delayed, how many different lights are set in a cycle, etc. These determine the flow of lights, the speed of the flow, and these SCM obviously does not have self-judgment ability, it must rely on people to "lay out" the task, and it is in accordance with people's design and execution. To make the SCM “obedientâ€, it is necessary to issue commands in a language that can be understood by the SCM. The language that the SCM can understand is called “instructionâ€. The instruction that any one kind of type one-chip computer can accept is limited, the order number of 51 one-chip computers is 111, and there are only 35 instructions of PIC one-chip computer. Each instruction completes one of the most basic actions. In order to accomplish a specific function, people must arrange and combine these instructions into a sequence of instructions. This is the program. There are two types of instructions: machine language and assembly language. Take 51 as an example. If you want to make the P1.0 pin low, use the machine language to represent C2H 90H. Put these two numbers into the program memory of the microcontroller. After the microcontroller is executed, you can make P1. The 0 pin goes low; to make the P1.0 pin high, it is D2H,90H in machine language. As to why these two numbers are, we do not need to pursue it. This is stipulated by the design engineer who designed the chip. We cannot change it, we can only study it. C2H, 90H is an instruction. Obviously, this form of instruction is difficult to remember and programming is very difficult, so people use “mnemonics†instead of these numbers. For example, the mnemonic of C2H and 90H is CLR P1.0, and the mnemonic of D2H and 90H is SETB P1.0. Since the mnemonic character is an abbreviation of the English alphabet, it has a certain meaning, so it is easier than the instruction in the digital form. Remember and easy to use. Writing programs using instructions in the form of mnemonics is called "assembly language source programs." But the assembly language source program has no way to go directly to the internal of the microcontroller. The program written using the mnemonic form of the instruction will eventually become such as: C2H, 90H, D2H, 90H, this form of instruction can be sent Program memory into the microcontroller. The process of changing an instruction in the form of a mnemonic to an instruction in digital form is referred to as "assembly." There are two methods of assembly, one is "manual assembly", that is, people find the written form of assembly instructions in the form of a table lookup and write down; the other is "machine assembly", that is, after the preparation of the assembly language source program Using a computer software to process these source programs to obtain a sequence of instructions in digital form, this instruction sequence is often referred to as "machine code," ie, code that can be executed directly by the machine. The sequence of instructions in digital form obtained by the machine assembly is stored on the disk as a file. The extension of this file is generally HEX, which is commonly known as the HEX file. Once you have the HEX file, you can write it into program memory. To write the program to the chip, a special device called a “programmer†is usually required to run the programming software on the computer, and then open the HEX file in the software to write it into the chip. With the development of technology, there are more and more programming methods, but the overall concept is such that the specific details will be answered in another question “What is the microcontroller programmer?â€. 4. What is the "XX bit" in 8-bit, 16-bit, and 32-bit microcontrollers? 8-bit, 16-bit, 32-bit refers to the "word length" of the microcontroller, which is the length of data involved in the operation in an operation. This bit refers to binary bits. Taking 8-bit as an example, the 8-bit binary expression range is 0000,0000-1111 and 1111 is decimal 0-255, that is, the maximum number of data that can participate in each operation cannot exceed 255. The 16-bit machine has a 16-bit word length, and its data expression range is 0~65535. That is, the maximum data of each participating operation cannot exceed 65535; the 32-bit microcomputer has a 32-bit word length, and the data expression range is 0~4294967295. , that is, the maximum number of data that can participate in the operation each time cannot exceed 4294967295. 8-bit, 16-bit, and 32-bit are closely related to the performance of the microcontroller. Usually the performance of 32-bit machines is higher than that of 16-bit machines, and the performance of 16-bit machines is higher than 8-bit machines. Why is this happening? This should be analyzed from two aspects. First, the number of digits is different and the operation efficiency is different. For an 8-bit machine, since each number in an operation cannot exceed 8 bits, even if such an operation as 100+200=300, it cannot be completed at once because 300 has exceeded 8 bits to express The maximum range (255), therefore, to operate on such a formula, we must write a program to complete the operation step by step, and finally get a correct result. If you use a 16-bit microcontroller to calculate, then one operation is enough. Obviously, the time required for step-by-step completion is much greater than the time required for a single step to complete. In the same way, when the result or intermediate value of an operation is greater than 65535, the 16-bit machine cannot perform an operation once. It must be implemented step by step, and the 32-bit machine can be completed by one operation. Second, business factors. Usually, the higher the computing power, the stronger the performance of the microcontroller. Of course, some people can accept the higher price. With the price space, manufacturers will usually provide more other functions in these chips, so that the overall performance of the chip Greater improvement. In a typical microcontroller, the 80C51 series, the PIC series, and the AVR series are 8-bit microcontrollers; the 80C196 and MSP430 series are 16-bit microcomputers; and the currently popular ARM series are 32-bit microcomputers. 5. What is the use of microcontroller programmers, emulators, programmers, and downloaders? Microcontroller programmer is a tool used to write program code into the memory chip or the internal of the microcontroller. When the chip is dual-inline, it can be programmed by directly plugging it into the socket. Another method is to use the download line. As technology advances, more and more microcontroller chips begin to support the "ISP" function, namely In System Programmer, on-line programmable technology. Using this technique, blank (unprogrammed) chips are soldered directly to the printed circuit board, and the chip can be programmed using several pins that have been left in advance without having to remove the chip and put it on the programmer. This brings great convenience to small-batch production and eliminates the need to purchase expensive adapters. 6. What are the necessary hardware devices for self-learning microcontrollers? In addition to computers, the following microcontrollers are needed to learn the MCU. 1. Experiment board If you know nothing about the MCU, then it is a good choice to build or purchase an experiment board. Usually on the experimental board will be designed some switches, LED indicators, digital tubes, various interface chips and other commonly used devices, through the programming practice of these devices, and gradually master the microcontroller programming technology. 2. Simulator The purpose of the simulator is to replace the SCM chip on the circuit board. The simulator communicates with the PC through the serial port, USB interface, etc., and receives commands issued by the PC control software to run at single step, single step and full speed. When the program is executed in various ways such as single-step or single-step execution of the process, the execution result can be fed back to the PC-side control software after each execution of the program. Because the microcontroller must be clear about what kind of result each instruction will have after execution, make sure whether the actual result is consistent with the expected result. Therefore, the simulation function can play an important role in the learning and development of the microcontroller. Help function. 3. Programmer or download line Its purpose is to write code into the microcontroller chip. For learners, with the simulator can also be temporarily equipped with programmer or download line, because with the experimental board, the simulator can do experiments. However, it is recommended to configure one so that you can understand all aspects of microcontroller development. 4. Multimeter, electric iron and other electronic production tools The development of single-chip microcomputer is not a simple programming. Up to now, there are few pure "MCU programmers", and developers are usually required to be familiar with software and hardware. Therefore, these electronic productions still need to be equipped. It should be noted that the simulation machines, experiment boards, download lines, or programmers mentioned here are all based on general concepts and do not involve specific products. There are also some products on the market that will be used to design the experiment board, Some or all of the simulation functions, downloads, or programming functions are integrated on one board to form a complete set of experimental systems. 7. What are the commonly used SCMs in China? 1.80C51 and its compatible series (1) 80C51 series, this is the most basic series. Including 80C31, 80C51, 87C51, 80C32, 80C52, 87C52 and other chips, although these chips are basically no longer used, but they are the basis for the subsequent development of the chip. One 80C31 microcontroller chip ROM, 80C51 internal is a one-time 4K PROM, 87C51 internal 4K EEPROM, the internal RAM of these chips are 128 bytes. The latter three kinds of chips have internal RAM of 8K, and the latter two chips have 8K bytes of on-chip ROM. (2) 80C51 compatible series These chips are usually compatible with the 51 series microcontrollers at the instruction level, but all have many new features. The following are some of the most common ones. STC89 series MCU, its main features are: directly through the serial port on the microcontroller programming; programmable for double speed operation; ultra-low power consumption; built-in watchdog; internal FLASH ROM can be used as an EEPROM to save data for power. STC12 series MCU, its main features are: single clock cycle, operating frequency 0 ~ 35M, equivalent to the ordinary 80C510 ~ 420M; wide voltage range; low power consumption; chip built-in E2PROM function; built-in hardware watchdog; general purpose I / O port It can be set to four operating modes, which can “spill†the current when in a strong pull-up mode. Philip's LPC series, its main features are: built-in RC oscillator, no external oscillator components when selecting the RC oscillator; all ports have 20mA LED drive capability; have a wider operating voltage range. C8051F series, its main features are: a machine cycle is only a clock cycle; increase the interrupt source; an internal independent clock source or external clock, and can achieve internal and external clock switching when the program is running. Each I/O port pin can be configured as a push-pull or open-drain output. The most unique feature of the C8051F series microcontroller I/O ports is the addition of a digital crossbar switch that uses a digital crossbar switch to direct internal digital system resources to P0. P1 and P2 Port I/O Pins. Many models of this series of chips have ADC, DAC, PCA and other functions. 2.PIC Series The development of the PIC microcontroller is different from that of the 51 single-chip microcomputer. It does not engage in simple functional accumulation. Instead, it focuses on the actual situation, values ​​the performance and price ratio of the product, and depends on the development of various models to meet different levels of application requirements; it simplifies the implementation of instructions. Greatly improved efficiency. There are currently hundreds of varieties of PIC10, PIC12, PIC16, PIC18 series. Taking the PIC16F676 as an example, the chip contains 1K word of FLASH ROM, 128 bytes of EEPROM, 64 bytes of RAM, and 8 10-bit AD converters. The built-in oscillator has an accuracy of ±1%, and it has extremely low power consumption and wide operating voltage. Range, such a high-performance 14-pin chip, the price is less than Â¥ 7, the price is quite high. 3.AVR series AVR series single-chip microcomputers are enhanced RISC-structured single-chip microcomputers, whose main features are: fast speed, one machine cycle is only one clock cycle; rich in variety, similar to PIC series, rely on the development of various models to meet different levels of application requirements; support ISP, IAP function, can be programmed online, convenient remote maintenance; wide working range, strong anti-interference ability. Taking the ATMEGA8 chip as an example, the chip has 8K Flash ROM, 512 bytes of EEPROM, 1 Kbyte of RAM, 8 10-bit AD, and an internal RC oscillator. Such a high-performance 28-pin chip, the price is only about Â¥ 7, the price is quite high. 4. Others Other commonly used MCUs include: ST, EMC, Motorola, Samsung, and others. Some of these MCUs have large market usage, but we do not focus on them because we mainly focus on amateurs. Although some chips are powerful and cost-effective, they are not targeted at amateurs and small-lot chips. It is difficult to buy, and development tools such as simulators and C compilers are extremely expensive, so we will not introduce them here. We are interested in searching for information on the Internet. 8. What is the approximate price of a common microcontroller? The prices of single-chip microcomputers vary widely, ranging from less than 1 yuan to tens of yuan, and up to 100 yuan. The following is a brief introduction to the price of commonly used microcontrollers. 9 microcontroller programming, simulation, debugging commonly used software? Different types of microcontrollers require different development software. We illustrate the 80C51 series, the PIC series, and the AVR series as examples. The preparation of SCM program does not require any special software, as long as it is text editing software, such as WINDOWS's own Notepad, WORD, etc., but these software is not easy to write, there are some better text editor For selection, such as UltraEdit, PE2 and so on. Of course, the most commonly used by people is to use the editor that comes with the development software. Take 80C51 series one-chip computer as examples, the most popular software is Keil software. Keil software is a comprehensive development tool, built-in compiler, ASM assembler, C51 compiler, debugger and other parts. 10. Can I recommend learning MCU books or other forms of tutorials? There are a lot of books on the market for microcontrollers. As a beginner, the 80C51 series is usually the best choice. If you have a clear working object, it is another matter. UHC Marine Electrode Water Level Sensor Uhc Marine Electrode Water Level Sensor,Electrode Type Water Ingress Detection Sensor,Water Ingress Detection Sensor,Water Ingress Detection Sensotion Sensor Taizhou Jiabo Instrument Technology Co., Ltd. , https://www.taizhoujiabo.com