Through the previous study, we know that the Microcontroller has a Rom, a ram, and a parallel I/O port, so what else is there inside the microcontroller, how are these fragmented items connected together? Let's make a complete functional analysis on the registers in the single chip microcomputer!
We can see that there is a CPU inside 51 for Operation and Control, there are four parallel I/O Ports, respectively P0, P1, P2, P3, with Rom, it is used to store programs, Ram, intermediate results, timing/counters, serial I/O Ports, interrupt systems, and an internal clock circuit. There are so many things in a 51 microcontroller. <MCU internal structure>
For further analysis on the above figure, we know that the read and write operations on the parallel I/O ports only need to send the data to the corresponding I/O port lock, so how can I use timing/counter and serial I/O ports? Some independent storage units in the microcontroller are used to control these devices. They are called special function registers (SFR ). In fact, we have been in touch with the special function register P1. What else? See table 1.
Symbol |
Address |
Features |
B |
F0h |
Register B |
ACC |
E0h |
Accumulators |
Psw |
D0h |
Program status word |
IP |
B8h |
Interrupt priority control register |
P3 |
B0h |
P3 port latches |
IE |
A8h |
Interrupt permitted control register |
P2 |
A0h |
P2 port latches |
Sbuf |
99 h |
Serial Port latches |
Scon |
98 h |
Serial Port Control Register |
P1 |
90 h |
P1 port latches |
Th1 |
8dh |
Timer/Counter 1 (8-bit high) |
Th0 |
8ch |
Timer/Counter 1 (8-bit low) |
TL1 |
8bh |
Timer/Counter 0 (8-bit high) |
Tl0 |
8ah |
Timer/Counter 0 (8-bit low) |
Tmod |
89a |
Timer/counter control register |
Tcon |
88 h |
Timer/counter control register |
DPH |
83 H |
Data address pointer (8 bits in height) |
DPL |
82 H |
Data address pointer (8-bit low) |
SP |
81 h |
Stack pointer |
P0 |
80 h |
P0 port latches |
Pcon |
87 h |
Power Control Register |
Table 1 <special function Register address image table (1)> <special function Register address image table (2)> <special function Register address image Table (3)> more SCM learning information please http://www.51hei.com below, we introduce several common SFR, see Figure 2. ACC: accumulators, often expressed as. What is this? It cannot be understood from the name. It is a register, not an addition. Why is it such a name? It may be because one of the numbers in the iterator must be in ACC. Its name is special and its identity is special. We will learn instructions later, and we can find that all operational commands are inseparable from it. 2. B: a register. Add a multiplier or divisor when performing multiplication or division, and do not perform multiplication or division as needed. 3. psw: The program status word. This is a very important thing. It puts many States during CPU operation, so that we can understand the current status of CPU and make corresponding processing. For more information about its functions, see table 2.
D7 |
D6 |
D5 |
D4 |
D3 |
D2 |
D1 |
D0 |
Cy |
AC |
F0 |
RS1 |
Rs0 |
Ov |
|
P |
Table 2 psw is also known as the mark register. Understanding this is very important for understanding the principle of single chip microcomputer and storing various related signs. Its structure and definition are as follows: Next we will introduce the usage of SFR one by one (1) Cy: Carry mark. Indicates whether acc.7 is carried to a higher position. The splitter in 8051 is an 8-bit splitter. We know that the 8-bit splitter can only be expressed as 0-255. If an addition is made, the sum of the two numbers may exceed 255, in this way, the highest bit will be lost, causing an operation error. What should I do? The highest bit is here. So it will be okay. Example: 78 H + 97 h (01111000 + 10010111) (2) AC: the secondary carry mark is also called the semi-carry mark. Indicates whether acc.3 has been carried to acc.4. Example: 57 H + 3ah (01010111 + 00111010) (3) F0: User flag. It is up to us (programmers) to determine when to use it, when not required. (4) RS1 and rs0: Work register group selection bit. We have known this.
RS1, rs0 = 00 -- Zone 0 (00h ~ 07 h) RS1, rs0 = 01 -- Zone 1 (08h ~ 0fh) RS1, rs0 = 10 -- Zone 2 (10 h ~ 17 h) RS1, rs0 = 11 -- Zone 3 (18h ~ 1fh) (5) 0 V: overflow flag. It indicates ACC overflow in the arithmetic operation of the number of symbols. Let's talk about overflow later. (6) P: parity bit: it is used to represent the parity of the number of binary digits "1" in the ALU operation result. If it is an odd number, P = 1, otherwise it is 0. For example, a certain calculation result is 78 H (01111000). Obviously, the number of 1 is an even number, so p = 0. 4. dptr (DPH, DPL): A Data Pointer that can be used to access any unit in the external data storage. If it is not used, it can also be used as a general-purpose register. It is up to us to determine how to use it. It consists of two 8-bit registers, DPH and DPL. It is mainly used to store a 16-bit address as an address pointer to access external memory (external Ram and ROM. 5. P0, P1, P2, and P3: as we know, they are registers of four parallel input/output ports. The content in it corresponds to the output of the pin. 6. SP: Stack pointer. (Used to indicate the data address at the top of the stack .) Stack Introduction: in our daily life, we have noticed this phenomenon. The bowls we wash at home are stacked one by one and put on the top at the latest, the first put is placed at the bottom. The opposite is true when we take the data. We will first extract the data from the top. This phenomenon can be summarized in one sentence: "first, then, first, first, and foremost ". What else can this happen? In fact, bricks and materials stacked on the construction site and goods placed in the warehouse are all "first-in-first-out, last-in-first-out". This is actually a rule for accessing items, we call it "stack ". In single-chip microcomputer, we can also construct such an area in Ram to store data. The rule for storing data in this area is "first-in-first-out, second-in-first-out", which is called "stack ". Why do we need to store data like this? Isn't the storage itself capable of storing data by address? Yes. If we know the address, we can know the content. But if we want to store a batch of data and every data needs to know the address, isn't it a problem? If we place the data one by one, we only need to know the address unit where the first data is located (see figure 2). If the first data is at 27 h, the second and third are 28 h and 29h. So using the stack method to store data can simplify operations. So what is the stack in 51? The region where data can be stored in the single-chip microcomputer is limited. We cannot allocate a specific part of the stack, So we open up a part in the memory (RAM) for the stack, but which memory is used? It is still difficult to determine, because 51 is a general microcontroller, the actual needs of each person are different, some people need more stacks, while some people do not need so much, so how can we solve this problem? If the score is not good, you can simply ignore it. You can give the score right to the user (programmer) and set it based on your own needs. Therefore, the stack position in 51 single-chip microcomputer can be changed. This change is reflected in the change in the value of the SP. As shown in figure 2, if the value in the SP is 27h, isn't it equivalent that a pointer points to the 27h unit? Of course, in the real 51 machine, the starting pointer refers not to the data storage location, but to the previous data storage location. For example, the starting Pointer Points to the 27h unit, the first data is located in units 28h, not units 27h. Why? Let's explain it again when learning stack commands. For other SFr instances, we will introduce them later.