1. Simple introduction to 51 single chip microcomputer (compilation)

Preface

Friends who can click in, the term 51 single chip microcomputer must be familiar to everyone. I won't say much nonsense. Let's go directly to the topic and start our MCU journey.

Warning statement

When I wrote this article, I was a junior undergraduate. All articles in this column are about the author's personal experience in learning MCU and some personal programming skills. When I first arrived, there are some errors and limitations. I also hope that everyone can correct me and communicate more and make progress together.

Most of the topics come from the experiment instruction book of the experiment teacher, and a small part come from the Internet. The routines given are all independently written by the author. Any similarity is purely coincidental.

Our learning goals

Through this article, I hope that I can lead you to:

1. Simple and familiar with the experimental environment
2. Master the use of some basic 51 single-chip microcomputer introductory instructions
3. Introduce the operation method of 51 single-chip RAM, ROM, etc.

surroundings

1. The programming environment is keil software system, and the selected board is 80C51 of Atmel

Start to take off

1. First, we simply write a program, perform single-step execution, observe the corresponding special registers, RAM space (including working register area, bit addressing area, user RAM area) data changes and program memory instruction codes.

;第一题
ORG 00000H
MOV A,#35H
ADD A,#78H
MOV 36H,#12H
PUSH ACC
INC A
SETB   15H
PUSH ACC
END

Step by step execution of the above code, you can find the following phenomena

--------------Code executed--------------------------------- ---Changed RAM address----------------------------Change-------------- -
--------------MOV A,#35H----------------------- 0E0H (special register ACC Address)---------------00H=>35H------------
--------------MOV A, #78H----------------------- 0E0H (address of special register ACC)---------------35H= >ADH------------
--------------MOV 36H,#12H----------------- -------------- 36H (User RAM area) --------------------00H=>12H------ ------
--------------PUSH ACC------------------------- 08H(stack The default value SP points to 07H)--------------00H=>ADH------------
------------- -INC A--------------------------------- 0E0H (address of special register ACC)------ ---------ADH=>AEH------------
--------------PUSH ACC--------- ---------------- 09H (the default value of the stack SP points to 07H)--------------00H=>AEH------ ------

As for how to look at the changes in the RAM area and ROM area, due to the limited ability of the author, I cannot describe it clearly in a short space. It is recommended to Baidu before starting the operation.
If we successfully see the above changes, we can start to try to write some simple addition and subtraction things.

2. Set 30H and 32H to store two 16-bit unsigned binary numbers respectively (low 8 bits in front, high 8 bits in the back), complete the procedure of adding the two numbers, and put the result into the unit starting with 34H. Send 1122H and 3344H into RAM cell respectively, observe the result and CY mark; then put 8899H and AABBH into RAM cell respectively, observe the result and CY mark again.

ORG 00000H
MOV 31H,#88H
MOV 30H,#99H
MOV 33H,#0AAH
MOV 32H,#0BBH
MOV  A,30H
ADD A,32H
MOV 34H,A
MOV A,31H
ADDC A,33H
MOV 35H,A
END

This is a simple 16-bit binary number addition problem, even the more 32-bit and 64-bit binary additions are the same idea: starting from the lowest bit, adding up successively, except for the lowest bit, the other bits are added. The carry of the previous digit needs to be considered.
And what we can observe is: when 1122+3344 is completed for the first time, the lower 11+33 does not produce a carry that is higher than the higher one, so CY=0; and in the second addition, the lower one generates a carry. , CY=1.

Through the above exercises, we have mastered the use of 51 single chip microcomputer to complete the operation of addition and subtraction, yes, the next step is to multiply and divide.

3. Multiply the 2 BCD numbers in the 30H unit, the product is the BCD number, and send the product to the 31H unit.

ORG 0000H
MOV 30H,#88H
MOV A,30H
MOV B,#10H
DIV AB
MUL AB
MOV B,#0AH
DIV AB
SWAP A
ADDC A,B
MOV 31H,A
END

Idea: Divide two BCD numbers in a 30H by 10H (equivalent to 16 in decimal), then its quotient is the BCD number stored in the upper 4 digits, and the remainder is the BCD number stored in the lower 4 digits.

4. Realize that the unsigned number is expanded 6 times, and the value after 6 times expansion does not exceed 255.

ORG 0000H
MOV 20H,#02H
MOV A,20H
RL A
MOV 21H,A
RL A
ADD A,21H
MOV 22H,A
END

Note: I used the left shift RL operation here. The left shift operation in binary is equivalent to multiplying by 2 in decimal. For example, 00000001 is shifted by one bit to the left to become 00000010, and in decimal is 1=>2.

5. Complete the 0-9 square value look-up table program, it is required to use DPTR and PC as index registers respectively, and compare the similarities and differences between the two.

;DPTR
ORG 0000H
MOV DPTR,#TAB1
MOV A,#01H
MOVC A,@A+DPTR
MOV 20H,A
ORG 2000H
TAB1:DB 0,1,2,4,9,16,25,36,49,64,81
END


;PC指针
ORG 0000H
MOV A,#03H
MOVC A,@A+PC
MOV 20H,A
TAB1:DB 0,1,2,4,9,16,25,36,49,64,81
END

Note: DPTR does not need to consider the offset relative to the executed code, the PC needs to calculate the offset specially.

The author's abilities are limited. There are many concepts and usages without systematic and detailed explanations. You can refer to the narration of other bloggers. The follow-up blog posts will adopt a special narration of one topic.

Guess you like

Origin blog.csdn.net/weixin_44108271/article/details/112985675