I have been looking at single-chip microcomputers for a long time, so I want to make a summary. In fact, single-chip microcomputers are not as complicated as imagined in terms of chips! 89C51 has only 40 pins. Among them, P0~P3 ports occupy 32 pins. One is connected to the ground and the other is connected to the power supply, two oscillation pins. An EA pin is the starting address selection terminal of the ROM. An ALE/Vpp off-chip address latch serves as the pin/line programming power input terminal. PSEN is the off-chip ROM enable terminal. Of course, there is also a reset REST pin. Among them, all P3 ports have a second function multiplexing: timer interrupt serial port interrupt. When the P0~P3 port writes #FFH, the on-chip latch is set to 1. This is a single port for bidirectional input and output. This is from the outside of the chip.
From the inside of the chip, there are two main independent memories, ROM and RAM. One is for program indication, and the other is for data processing and storage. ROM and RAM are distinguished by addressing mode during programming. They both have a capacity of 64KB. The ROM has a 4KB storage space on the chip. EA indicates whether the program is executed from outside the chip or from inside the chip. The RAM on the chip is 256 bytes, that is, FFH is divided into 4 parts. 00H~1FH is the working register group. 20H~2FH is the addressing space. 30H~7FH is the user RAM area. 80H~FFH is the special register area. There are 22 SFRs (not introduced here).
Let's talk about the instruction system. MOV, MOVX, MOVC are the three transfer instructions, and the off-chip memory cannot be directly transferred. The three call instructions AJMP, LJMP, SJMP are used for different call ranges. The logic arithmetic instructions ANL, ORL, XRL, as well as ADD, SUBB, MUL, and DIV. There are also many instructions such as exchange, jump, loop, bit addressing, Boolean processing instructions, etc.
For example, the following loop-jump instruction
MOV R0,#00H
MOV R1,#AAH
MOV R7#0BH
loop: MOV A ,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R7,loop
END
This program is used to perform the on-chip transfer function.
Let's talk about the general flow of a program. It can be divided into sequence, branching, looping, and combined nesting. The example above is a type of loop.
Write a branching program example
MOV A,R1
RL A
MOV DPTR,#data
JMP @A +DPTR
data: AJMP KK1
AJMP KK2
.
.
AJMP KKn
This instruction is a branch transfer with data as the starting address and R1 as the offset. Because AJMP is a two-byte instruction, RLA must be executed.
Let's talk about interrupts and timing.
The registers involved in the interrupt are TCON, IE, IP, and SCOM.
The interrupt request is executed by setting the interrupt flag bit. The interrupt has 5 entry addresses: 03H 0BH 13H 1BH 23H.
For example, the entry of external interrupt 1 is set to the highest priority in default mode
SETB PX1
STEB EX1
STEB EA
It's very simple, a bit like a level-breaking game where you have to complete every step before you can execute the interrupt.
Below is the timer, which is widely used in microcontrollers. There are 4 working modes: 0, 1, 2, and 3.
I will use the typical timer 0 mode 2 at 12MHZ to program a sine wave output XXMS at P1.0. The initial value is replaced by KKH.
MOV P1 ,#FFH
MAIN: MOV TMOD , #02H
MOV TH0 ,#KKH
MOV LHO ,#KKH
STEB ET0
STEB TRO
STEB EA
AJMP $
Interrupt procedure TIME0: CLR TF0
CPL P1.0
RETI.
There is also serial port transmission. 89C51 has 4 modes of transmission, among which the baud rate setting is particularly important.
The registers involved are TCOM TDOM SCOM SDOM PCON.
In fact, 89C51 can also use software to simulate bus interfaces, such as SPI, I2C, etc. There are too many external expansions for key program settings. I will write and post them later when I have time.
Previous article:What is 51 MCU addressing
Next article:MCU decoding 315M pt2262 encoded c51 program
Recommended ReadingLatest update time:2024-11-16 16:43
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [April 23 | Suzhou] High-speed digital and optical communication test seminar invites you to meet
- Award-winning live broadcast: Application of TI millimeter-wave radar in cars is now open for registration~
- Modelsim10.4 installation and adding crack files error solution
- TI - MCU - MSP430 User Guide 1 -> MSP430 Introduction and Selection Guide
- [BearPi-HM Nano, play Hongmeng "Touch and Go"] -1- Unboxing and preliminary data collection
- Adding your own C functions to MicroPython
- PCB production
- Sharing 10 common formulas for switching power supply design
- Battery Management System BMS Technical Data Transfer
- [Raspberry Pi Pico Review] LCD1602 4-bit mode display driver