Assembly language foundation of MCU programming - common instructions and program mode

brief:
The programming language of the one-chip computer programming language can use the single-chip C language programming, and can also use the single-chip assembly language. C language programming has modular management features, high portability, and is suitable for writing large programs. But as a high-level microcontroller design, many advanced microcontrollers, many new products of the microcontroller are also required to have a C language editor after the assembly language compiler. So learning the MCU assembly language is also a very important programming language course.
In addition, the microcontroller has a general purpose and a dedicated type. The special type is a kind of single-chip microcomputer specially developed by the manufacturer for the fixed program. The program has been written during the research and development, and cannot be modified later. The general-purpose single-chip microcomputer is a single-chip microcomputer that we can learn and weave independently. The program needs to be written by itself and can be changed. According to the basic operation of the MCU, the number of bits can be divided into: 1-bit, 4-bit, 8-bit, 16, 32-bit MCU.

text:
Here we mainly explain the 89C51 microcontroller of American ATMEL company.
First, 89C51 single-chip PDIP (dual in-line type) package pin diagram:



Its pin functions are as follows:
P0 port (p0.0-p0.7): It is a bidirectional tri-state port and can be used as an input/output port. However, in practical applications, it is usually used as an address/data bus port, that is, a low 8-bit address/data bus time division multiplexing. The lower 8-bit address is latched into the external address latch on the negative transition of the ALE signal, while the upper 8-bit address is output by the P2 port.
Port P1 (p1.0-p1.7): Each bit can be used as a programmable input or output line.
P2 port (p2.0-p2.7): Each bit can also be used as an input or output line. When the system peripheral is extended, it can be used as the address bus of the extended system with a height of 8 bits, and together with the P0 port, it is composed of 16 bits. Address bus. For the 89c51 microcontroller, the P2 port is generally only used as an address bus, and is not directly connected to the peripheral as an I/O line.
P3 port (p3.0-p3.7): It is a dual function port. When used as the first function, its function is the same as that of P1 port. When used as a second function, each bit function is shown in the table below.

P3 port second function


Rst\Vpd: Power-on reset terminal and power-down protection terminal.
XTAL1 (xtal2): One external crystal oscillator is connected to one end of the crystal oscillator.
Gnd: Power ground.
Vcc: The power supply is positive, connected to +5V.
PROG\ALE: Address latch control terminal
PSEN: Off-chip program memory read strobe signal output, active low.
EA\vpp: Access external program memory control signal, active low. The on-chip memory is accessed when EA is high, and the external program memory is automatically accessed if it is out of range. Only external program memory is accessed when EA is low.

2. Introduction to common instructions and their formats:

1. Instruction format:
[label:] opcode [destination operand] [, operation source] [; comment]
For example: LOOP: ADD A, #0FFH; (A) ← (A) + FFH

2, commonly used symbols:
Ri and Rn: R represent working registers, i denotes 1 and 0, and n denotes 0-7.
Rel: relative address, address offset, mainly used for unconditional relatively short transfer instructions and conditional branch instructions.
#data: 8-bit immediate value contained in the instruction.
#data16: 16-bit immediate value contained in the instruction.
Addr16: 16-bit destination address.
Direct: The address directly addressed.
Bit: The directly addressable address in the internal data memory RAM and the Special Function Register SFR.
@: The prefix of the indirect addressing register or base address register.
(X): indicates the content in X.
((X)): indicates the content in the unit addressed by X, that is, (X) is the address, and the content of the address is represented by ((X)).

3. Commonly used directives:
ORG: Specifies the starting address of the target block or data block. Format: ORG+space+address For example: ORG 0000H
END: End instruction, placed at the end of the program, used alone, one program is used only once.
DB (definition byte): Starting from the specified address unit, define a number of byte locations and assign initial values.

4, commonly used addressing mode:
Direct addressing: MOV A, 30H
Immediate addressing: MOV A, #20H
Register Indirect Addressing: MOV A, @Ri(i=1, 2)
Base address plus index register addressing: MOV A, @A+DPTR
Register addressing: MOV A, Rn (n = 0 - 7)

5, a large collection of instructions:
Transfer class instructions:

Transfer class instructions:

Logical operation class instructions:

Control transfer class instructions:

Bit manipulation class instructions:


Third, the general commonly used program mode:
1. Start the program: ORG 0000H
JMP 0030H
ORG 0030H
...
...
2, software delay subroutine: YANSHI: MOV R7, #25
D1: MOV R6, #50
D2: MOV R5, #200
DJNZ R5, $
DJNZ R6, D2
DJNZ R7, D1
RET
If the 12M crystal oscillator has a delay time of about: 25 & TImes; 50 & TImes; 200 & TImes; 2 & TImes; 10-6s, if it is a 6M crystal oscillator, the delay time is: 25 × 50 × 200 × 2 × 2 × 10-6s
3, hardware delay subroutine: (1) query method:
YANSHI: MOV TMOD, #01H
MOV R0, #20
UP: MOV TH0, #3CH
MOV TL0, #0B0H
SETB TR0
JNB TF0, $
CLR TF0
DJNZ R0, UP
RET
This delay program is 20 (R0) × 50ms, which is one second. If a longer delay is required, only the value of R0 needs to be changed.
4, the first level interrupt program: external timer 0 interrupt ORG 0000H
JMP 002CH
ORG 0003H
JMP ZHONGDUAN
ORG 002CH
MAIN: MOV TCON, #01H
MOV IP, #01H
MOV IE, #81H
...
...
ZHONGDUAN: PUSH A
PUSH PSW
SETB RS0
CLR RS1
...
...
POP PSW
POP A
RETI
If it is not necessary to protect the value of the main program, the interrupted subroutine only needs to directly load the subroutine that needs to be executed to interrupt the main program.

Electrical Wiring Harness

We can follow customers' drawings or design to make Customized wire harness for various industries: game machine, ATM, POS machine, etc.

Customized wire assembly with AVL components from original manufactures. Also harness with local equivalent componets are workable with short L/T and competitive price, also flexible MOQ.

Related Products:cigarrete charging cable,custom audio cables,fiber optic cable,cigarrete lighter cable.

Cigarrete Lighter Cable,Custom Audio Cables,Fiber Optic Cable,High Quality Electrical Wire Harness,Automotive Wiring Harness,Coiled Cable,Wiring Assemblies,Fuse Holder,Auto Plug Cable,Cigarrete Charging Cable

ETOP WIREHARNESS LIMITED , https://www.etopwireharness.com