We already know that single-chip microcomputer has Rom, ram, and parallel I/O Ports, so what are there in the single-chip microcomputer besides these? How are these fragmented things connected together?
Next let's make a complete analysis of the single-chip microcomputer!
We can see that in 51 single-chip microcomputer, there is a CPU for Operation and Control, there are four parallel I/O Ports, respectively P0, P1, P2, P3, there is 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.
For further analysis of the graph, we know that the read and write operations on the parallel I/O port only need to send the data to the corresponding I/O port lock. For the Timer/counter, how to use 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 the table below.
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 |
89 h |
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 |
Next, we will introduce several common SFr instances.
1ACC --- is a accumulator, which is usually represented by.
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 in this article, and we can find that all operational commands are inseparable from it. Itself has a zero Mark Z, if a = 0 then z = 1; if a = 0 then z = 0. This flag is often used as a condition for determining the Branch Transfer of programs.
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 ----- program status word.
This is a very important thing. It contains many States when the CPU is working, so that we can understand the current status of the CPU and handle it accordingly. For more information about its functions, see the following table:
D7 |
D6 |
D5 |
D4 |
D3 |
D2 |
D1 |
D0 |
Cy |
AC |
F0 |
RS1 |
Rs0 |
Ov |
|
P |
Next we will introduce your usage one by one.
Cy: Carry flag.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. With advances and bits,Cy = 1;No entry, borrow, Cy = 0
Example: 78 H + 97 h (01111000 + 10010111)
AC:Secondary inbound and outbound (Inbound and Outbound ).
Example: 57 H + 3ah (01010111 + 00111010)
F0:The user flag space is determined by the user (programmer) when to use and when not to use.
RS1, rs0:Work register group selection bit. We have known this.
0 V:Overflow flag. The computation result is interpreted as a complement operation. Overflow exists, ov = 1; no overflow, ov = 0. What is overflow.
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. The calculation result has an odd number of 1, P = 1; the calculation result has an even number of 1, P = 0.
For example, a certain calculation result is 78 H (01111000). Obviously, the number of 1 is an even number, so p = 0.
4,P0, P1, P2, P3------ We already know that this is the register of four parallel input/output ports. The content in it corresponds to the output of the pin.
5. ie ----- interrupt register
Address: a8h
B7 |
B6 |
B5 |
B4 |
B3 |
B2 |
B1 |
B0 |
EA |
- |
Et2 |
Es |
ET1 |
Ex1 |
Et0 |
Ex0 |
EA (ie.7): When Ea = 0, all interruptions are prohibited (that is, no interruptions are generated)
When Ea = 1, the generation of each interrupt is determined by the individual bits
-(Ie.6): Reserved
Et2 (ie.5): timed 2 Overflow interrupt (8052 used)
ES (ie.4)
ET1 (ie.3): timed 1 interrupted
Ex1 (ie.2): The int1 interrupt is sufficient.
Et0 (ie.1): the timer 0 is interrupted.
Ex0 (ie.0): External Interrupt int0 interrupt allowed
7. IP ----- interrupt priority control register
Addressing by bit, b8h b8h
6. pointer registers
(1) program counter PC
Specifies the address of the next command to be executed, 16-bit, addressing 64 kB range,
Reset Pc = 0000 h
(2) Stack pointer sp
Specifies the address of the top element of the stack, which is 8 bits. The initial value can be set by software. sp = 07 h for resetting
(3) Data Pointer dptr
@ R0, @ R1, @ dptr; specify the address of the accessed data storage unit, 16 bits, and the addressing range is 64kb. Dptr = DPH + DPL. It 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 decide how to use it. It is divided into two registers: DPL (8-bit low) and DPH (8-bit high. It is used to store 16-bit address values, so that external data Ram or program memory can be operated within 64 kB in indirect or address change addressing mode.
7. Timing/Counter
(1) Timer mode register: tmod
(2) Timer control register: tcon
(3) counting registers: th0, tl0; Th1, TL1. It can be used to set the initial count value.
8052/8032 add a special register
(1) Timer 2 control register t2con; control and set the working mode.
(2) counting registers: SP2 and tl2
(3) Timer 2 capture/reload registers: rcap2h, rcap2l
Store data that is automatically reloaded to 2nd and tl2.