Summary of Microcontroller Basic Concepts

Summary of Microcontroller Basic Concepts

Microcontroller Instruction Execution
Let’s consider a question: when we write an instruction into the microcontroller using a programmer, and then take the microcontroller out, it can execute that instruction.
So this instruction must be stored somewhere in the microcontroller, and this place can retain the instruction even after the microcontroller loses power. What is this place?
This place is the microcontroller’s internal Read-Only Memory, or ROM (READ ONLY MEMORY).
Why is it called Read-Only Memory? Didn’t we just write two numbers into it? Actually, in the 89C51, the ROM is a type of electrically erasable ROM, known as FLASH ROM. What we used just now was a programmer that writes to the ROM under special conditions from an external device. Under normal operating conditions, the microcontroller can only read from it and cannot write data back, so we still call it ROM.
The Essence of Microcontroller Numbers and Physical Phenomena
We know that computers can perform mathematical operations, which is quite hard for us to understand. They are just some electronic components, how can they perform mathematical operations?
When we humans solve a math problem like 37 + 45, we write 37 on paper, then write 45 below it, and finally compute the result in our brain, writing the result down. The raw materials for the calculation are 37 and 45, and the result is 82, all written on paper. Where is this stored in a computer?
To solve this problem, let’s conduct an experiment: here is a light. We know the light can either be on or off, which gives us two states. We can use ‘0’ and ‘1’ to represent these two states: we define on as ‘1’ and off as ‘0’.
Now, if we have three lights, how many states are there? Let’s list them: 000 / 001 / 010 / 011 / 100 / 101 / 110 / 111. We see that 000 / 001 / 101 are just the binary numbers we have learned. Originally, the on and off states of the lights are just physical phenomena, but when we arrange them in a certain order, the on and off states represent numbers.
Let’s abstract this further. Why does the light turn on? It is because the output circuit outputs a high level, supplying power to the light. Therefore, the on and off states can be replaced by whether the circuit output is high or low. In this way, numbers are linked to the high and low levels of voltage.
The Meaning of Microcontroller Bits
From the previous experiment, we know that a light being on or the high or low level of a wire can represent two states: 0 and 1. In fact, this is a binary digit.
Thus, we call a wire a “bit,” represented as BIT.
The Meaning of Microcontroller Bytes
One wire can represent 0 and 1, two wires can express 00 / 01 / 10 / 11 four states, which means they can express 0 to 3, and three wires can express 0 to 7. In computers, usually 8 wires are grouped together to count simultaneously, which can represent 0 to 255, a total of 256 states.
These 8 wires or bits are called a byte (BYTE).
The Structure of Microcontroller Memory
Memory is a place used to store data. It uses the high and low levels of voltage to store data, meaning it actually stores high and low levels, rather than the numbers like 1234 that we are accustomed to. Thus, a mystery is solved.
A memory can be thought of as a set of small drawers, with each drawer containing eight small compartments, each used to store “charges.” The charges flow in and out through the connected wires. As for how the charges are stored in the compartments, we don’t need to worry about that; you can think of the wires as water pipes, with the charges in the compartments representing water, which makes it easier to understand. Each small drawer in the memory is a place to store data, and we call it a “cell.”
With this structure, we can start storing data. To store a data value of 12, which is 00001100, we simply need to fill the second and third compartments with charges while releasing the charges in the other compartments.
However, a problem arises: a memory has many cells, and the wires are connected in parallel. When we insert charges, it will fill all the cells, and when we release charges, it will release all the charges in each cell. Thus, regardless of how many cells the memory has, we can only store the same number, which is certainly not what we want. Therefore, we need to make a slight structural change.
We need to have a control line for each cell. To store data in a specific cell, we send a signal to the control line of that cell, which opens the switch, allowing charges to flow freely. The control lines of other cells do not receive signals, so the switches remain closed and are not affected.
In this way, by controlling the control lines of different cells, we can write different data into each cell. Similarly, if we want to retrieve data from a specific cell, we just need to open the corresponding control switch.
Decoding in Microcontroller Memory
So, how do we control the control lines of each cell? This seems simple; we can connect each cell’s control line to the outside of the integrated circuit.
However, it is not that simple. A 27512 memory has 65536 cells. If we connect each wire outside, the integrated circuit would need over 60,000 pins? That won’t work; we need to find a way to reduce the number of wires.
One method called decoding helps us with this: one wire can represent 2 states, two wires can represent 4 states, three wires can represent 8 states, and how many wires are needed to represent 256 states? Eight wires, so 65536 states can be represented with just 16 wires.
The Concept of Chip Selection in Microcontroller Memory
Now that we have solved the decoding issue, let’s focus on another problem. Where do the eight wires sent to each cell come from? They come from the computer; generally, these eight wires connect not only to one memory but also to other devices.
This raises a problem: since these eight wires are not dedicated to the memory and computer, if a specific cell is always connected to these eight wires, issues may arise: for instance, if the value in one memory cell is 0FFH and another memory cell is 00H, how do we determine whether the wire is at a high or low level? How do we differentiate?
The solution is simple: when the external wires connect to the pins of the integrated circuit, they do not connect directly to each cell; instead, we add a set of switches in between. Normally, we keep the switches open, and if we need to write data to this memory or read data from it, we close the switch.
This set of switches is controlled by three lines: the read control line, the write control line, and the chip select line. To write data into the chip, we first select the chip, then send a write signal, closing the switch and writing the incoming data (charges) into the chip. If we want to read, we first select the chip, then send a read signal, close the switch, and the data is sent out.
Read and write signals can also be connected to another memory, but because the chip select lines are different, the other memory will not be “misled” into opening the door, causing a conflict. Will it happen that two chips are selected at the same time?
As long as the system is designed correctly, it won’t happen because it is controlled by the computer, not manually by us. If it does occur, it means there is a fault in the circuit, which is beyond our discussion.
The Concept of Buses in Microcontrollers
From the previous introduction, we can see that the eight wires used to transmit data are not dedicated; rather, many devices share them.
Thus, we call it a data bus; the English name for bus is BUS, which is like a public bus lane that anyone can use. The sixteen address lines are also connected together, referred to as the address bus.
This article is reprinted from: STM32 Embedded Development

(End)

More Exciting:

Yan Shi│Reflections and Suggestions on the “Predicament” of Young Teachers in Universities

Academician Zheng Weimin: Why Computer Majors Have Become Hot Choices for Candidates

【Contents】”Computer Education” Issue 5, 2022

【Contents】”Computer Education” Issue 4, 2022

【Contents】”Computer Education” Issue 3, 2022

【Contents】”Computer Education” Issue 2, 2022

【Contents】”Computer Education” Issue 1, 2022

[Editorial Committee Message] Professor Li Xiaoming from Peking University: Thoughts from the “Year of Classroom Teaching Improvement”…

Professor Chen Daoxu from Nanjing University: Teaching students to ask questions and teaching students to answer questions, which is more important?

[Yan Shi Series]: Trends in Computer Discipline Development and Their Impact on Computer Education

Professor Li Xiaoming from Peking University: From Fun Math to Fun Algorithms to Fun Programming—A Path for Non-Majors to Experience Computational Thinking?

Reflections on Several Issues in Building a First-Class Computer Discipline

Professor Liu Yunhao from Tsinghua University Answers 2000 Questions on AI

Professor Zhan Dechen from Harbin Institute of Technology: A New Model to Ensure Teaching Quality in Higher Education—Synchronous and Asynchronous Blended Teaching

[Principal Interview] Accelerating the Advancement of Computer Science Education as a Pathfinder for Data Science Education—Interview with Professor Zhou Aoying, Vice President of East China Normal University

New Engineering and Big Data Major Construction

Learning from Others—Compilation of Research Articles on Computer Education at Home and Abroad

Summary of Microcontroller Basic Concepts

Summary of Microcontroller Basic Concepts

Leave a Comment