Several basic concepts of the single-chip microcomputer

MCU executes instructions

Let's think about a problem. When we write an instruction into the microcontroller in the programmer, and then remove the microcontroller, the microcontroller can execute this instruction.

Then this instruction must be stored somewhere in the microcontroller, and this place can still keep the instruction from being lost after the microcontroller is powered off. What is this place?

This place is the ROM (READ ONLY MEMORY) inside the microcontroller.

Why is it called a read-only memory? Didnt we clearly write the two numbers in just now? The original ROM in 89C51 is a kind of electrically erasable ROM, called FLASH ROM. Just now, we used the programmer. Under special conditions, external equipment writes the ROM. Under normal operating conditions of the microcontroller, It can only be read from that side, and data cannot be written in, so we still call it ROM.

Nature and physical phenomenon of the number of single-chip computers

We know that computers can perform mathematical operations, which makes it very difficult for us to understand. They are just some electronic components. How can they perform mathematical operations?

We, humans, do math problems such as 37+45. We first write 37 on the paper, then write 45 below, and then the brain calculates and finally writes the result. The raw materials for the calculation are 37 and 45, and the result is that 82 is written in On paper, where is it in the computer?

To solve this problem, let us experiment: here is a light, we know that the light is either on or off, there are two states, we can use '0' and '1' to replace these two states: It is specified that the light is '1' and the light is '0'.

Now put on the three lights, how many states are there? Let's take a look at the list: 000/001/010/011/100/101/110 / 111. Lets see, isnt this 000/001/101 the binary number we have learned? Originally, the on and off of the lights is just a physical phenomenon, but when we arrange them in a certain order, the on and off of the lights represent numbers.

Let us abstract a step further, why does the light turn on? It is because the output circuit outputs a high level, which energizes the lamp. Therefore, the light on and off can be replaced by whether the output of the circuit is high or low. In this way, the number is connected with the high and low levels.

The meaning of single-chip microcomputer digital

Through the above experiments, we already know: a light on or the level of a line can represent two states: 0 and 1. This is a binary bit.

Therefore, we call a wire a "bit", which is represented by BIT.

The meaning of MCU byte

One line can express 0 and 1, two lines can express the four states of 00/01/10 / 11, that is, 0~3 can be expressed, and three lines can express 0~7. Usually, 8 wires are used in the computer. Together, counting at the same time can represent a total of 256 states from 0 to 255.

These 8 wires or 8 bits are called a byte (BYTE).

The structure of single-chip microcomputer memory

The memory is used to store data. It uses the level of high and low to store data, that is to say, it actually stores the high and low of the level, instead of the number 1234 that we are used to thinking. In this way, one of our mysteries will be solved. Up.

A memory is like a small drawer, there are eight small grids in a small drawer, each small grid is used to store "electric charge", the charge is transmitted in or released through the wires connected to it. As for how the electric charge is stored in the small grid, we dont need to worry about it. You can think of the wire as a water pipe. Each small drawer in the memory is a place for storing data, which we call a "unit".

With such a structure, we can start storing data. If we want to put a data 12, which is 00001100, we only need to store the charges in the second and third small cells, and the charges in the other small cells Just let it go.

But the problem arises. Memory has many cells, and the lines are connected in parallel. When the charge is put in, the charge is put into all the cells, and when the charge is released, the charge in each cell is discharged. . In this case, no matter how many units there are in the memory, you can only put the same number, which of course is not what we want. Therefore, a slight change in the structure is required.

You need to have a control line on each unit. To which unit you want to put the data into, you need to send a signal to the control line of this unit, and this control line turns on the switch so that the charge can flow freely. However, there is no signal on the control line of other units, so the switch is not turned on and will not be affected.

In this way, as long as the control lines of different units are controlled, different data can be written to each unit. Similarly, if you want to fetch data from a certain unit, you only need to turn on the corresponding control switch.

Decoding of MCU memory

So, how do we control the control lines of each unit? This is not simple, just lead the control lines of each unit to the outside of the integrated circuit?

Things are not that simple. There are 65536 cells in a piece of 27512 memory. If every line is led out, this integrated circuit must have more than 60,000 pins? No, what should I do? Think about reducing the number of lines.

There is a way to call this decoding, a brief introduction: one wire can represent 2 states, 2 wires can represent 4 states, 3 wires can represent 8 states, and how many wires are needed to represent 256 states? 8 lines, so we only need 16 lines to represent 65536 states.

The Selection Concept of Single-Chip Microcomputer Memory

At this point, the problem of decoding is solved, let us focus on another problem. Where do the eight wires send into each unit come from? It is connected to the computer. Generally, these eight wires must be connected to other devices in addition to memory.

Then the problem arises. Since these eight wires are not dedicated between the memory and the computer, if a certain unit is always connected to these eight wires, there will be a problem: for example, the value in this memory unit is 0FFH The cell of the other memory is 00H, so is this line at a high level or a low level? How to distinguish?

The solution is very simple. After the external wires are connected to the pins of the integrated circuit, they are not directly connected to the units, and a set of switches is added in the middle. Usually, we leave the switch on. If we want to write data to this memory or read data from the memory, just turn the switch on.

This group of switches is selected by three leads: read control terminal, write control terminal, and chip select terminal. To write data into the slice, first select the slice, and then send a write signal, the switch is closed, and the transferred data (charge) is written into the slice. If you want to read, first select the piece, then send out the read signal, close the switch, and the data will be sent out.

The read and write signals are also connected to another memory at the same time, but because the chip select ends are different, although there is a read or write signal, but there is no chip select signal, the other memory will not "misunderstand" and open the door, causing conflicts. Will two chips be selected at the same time?

As long as it is a well-designed system, it wont be because it is controlled by calculations, not by us. If two pieces are selected at the same time, it means that the circuit has failed, and this is not ours. Discussion column.

MCU bus concept

From the above introduction, we have seen that the eight wires used to transmit data are not dedicated, but are shared by many devices.

So we call it the data bus. The English name of the bus is BUS, which is always the bus lane, and anyone can go. The sixteen address lines are also connected, which is called the address bus.