Our first project in the previous lesson was completed. Friends who know C language may say, "This is not much different from the C language on PC." There is really not much difference. C language is just a general term for a programming language. There will be some detailed changes in C language related to different processors. When writing a C program for a PC, if you want to program the hardware, you must have a certain understanding of the hardware. This is especially true for 51 microcontroller programming, because its development and application cannot be separated from the hardware, so we must first make a preliminary Get to know the structure and pin functions of the 51 rim chip. There are many types of MSC51 architecture chips, with different specific features and functions (a data list of some commonly used 51 chips will be added to the appendix written in the future). In the following tutorials, Atmel's AT89C51 and AT89C2051 will be used as the central objects. For learning, both are typical representatives of the AT89 series. They are widely used among enthusiasts. They have a lot of application materials and are cheap. They are the first choice chips for beginners to learn 51. Hehe, the saliva is a bit like selling advertising.
Figure 2-1 AT89C51 and AT89C2051 pin function diagram
AT89C51 | AT89C2051 |
4KB programmable Flash memory (can be erased and written 1000 times) | 2KB programmable Flash memory (can be erased and written 1000 times) |
Level 3 program memory confidentiality | Two-level program memory security |
Static operating frequency: 0Hz-24MHz | Static operating frequency: 0Hz-24MHz |
128 bytes internal RAM | 128 bytes internal RAM |
2 16-bit timers/counters | 2 16-bit timers/counters |
a serial communication port | a serial communication port |
6 interrupt sources | 6 interrupt sources |
32 I/O leads | 15 I/O leads |
On-chip clock oscillator | 1 on-chip analog comparator |
Table 2-1 Main performance table of AT89C51 and AT89C2051
Figure 2-1 is the pin function diagram of AT89C51 and AT89C2051. Table 2-1 is their main performance table. It can be seen from the above that they are roughly the same. Since AT89C2051 has very few IO lines, it cannot add RAM and program ROM, and there is also less on-chip Flash memory. However, its size is much smaller than AT89C51. You can customize it according to actual needs in the future. Select. They each have their own characteristics but their core is the same. Let’s take a look at the specific pin functions of AT89C51.
1. Power supply pin
Vcc 40 Power supply terminal
GND 20 Ground terminal
* The working voltage is 5V, and the working voltage of AT89LV51 is 2.7-6V. The pin functions are the same.
2. External crystal pins
Figure 2-2 External crystal pins
XTAL1 19
XTAL2 18
XTAL1 is the inverting amplifier input terminal of the on-chip oscillator, and XTAL2 is the output terminal. When using an external oscillator, the external oscillation signal should be directly added to XTAL1, while XTAL2 is left floating. In internal mode, the clock generator divides the oscillation pulse by two. For example, if the crystal oscillator is 12MHz, the clock frequency is 6MHz. The frequency of the crystal oscillator can be selected from 1MHz to 24MHz. The capacitance is about 30PF.
*The chip model is also AT89C51, and there is a frequency number behind it, which is available in 12, 16, 20, and 24MHz. Everyone should pay attention when purchasing and selecting. For example, AT89C51 24PC is an ordinary commercial chip with a maximum oscillation frequency of 24MHz and a 40P6 package.
3. Reset RST 9
When the oscillator is running, when a high level of more than two machine cycles (24 oscillation cycles) appears on this pin, it will reset the microcontroller. As long as this pin remains high, the 51 chip will Cycle reset. After reset, the P0-P3 ports are all set to 1 and the pins show high level, and the program counter and special function register SFR are all cleared. When the reset pin changes from high level to low level, the chip starts running the program at 00H of ROM. A commonly used reset circuit is shown in Figure 2-3.
*The reset operation will not affect the internal RAM.
Figure 2-3 Common reset circuit
4. Input and output pins
(1) P0 port [P0.0-P0.7] P0 is an 8-bit open-drain bidirectional I/O port. When the port is set to 1 (write 1 to the port), it acts as a high-impedance input terminal. When used as an output port, it can drive 8 TTL.
When programming the internal Flash program memory, the instruction byte is received; when verifying the program, the instruction byte is output, requiring an external pull-up resistor.
When accessing external programs and external data memory, P0 port is the address (lower 8 bits)/data bus of time-sharing conversion, and the internal pull-up resistor works during the access.
(2) P1 port [P1.0-P1.7] P1 is an 8-bit bidirectional I/0 port with internal pull-up resistor. Can drive 4 TTL on output. When the port is set to 1, the internal pull-up resistor pulls the port to a high level for input.
When programming the internal Flash program memory, the lower 8-bit address information is received.
(3) P2 port [P2.0-P2.7] P2 is an 8-bit bidirectional I/0 port with internal pull-up resistor. Can drive 4 TTL on output. When the port is set to 1, the internal pull-up resistor pulls the port to a high level for input.
When programming the internal Flash program memory, the upper 8 bits of address and control information are received.
When accessing external programs and 16-bit external data memory, the P2 port sends the high 8-bit address. When accessing an external data memory with an 8-bit address, the contents of its pins will not change during this period.
(4) P3 port [P3.0-P3.7] P2 is an 8-bit bidirectional I/0 port with internal pull-up resistor. Can drive 4 TTL on output. When the port is set to 1, the internal pull-up resistor pulls the port to a high level for input.
When programming the internal Flash program memory, control information is received. In addition, the P3 port is also used for some specialized functions. Please see Table 2-2 for details.
*When the P1-3 port is used as input, due to the internal connected resistor, the pin that is externally pulled low will output a certain current.
P3 pin | Combined functions |
P3.0 | Serial communication input (RXD) |
P3.1 | Serial communication output (TXD) |
P3.2 | External Interrupt 0 (INT0) |
P3.3 | External interrupt 1 (INT1) |
P3.4 | Timer 0 input (T0) |
P3.5 | Timer 1 input (T1) |
P3.6 | External data memory write strobe WR |
P3.7 | External data memory write strobe RD |
Table 2-2 P3 port pin-shared function table
call! I’ve said so much in one breath, let’s stop for a moment. Well, what? What is a pull-up resistor? Simply speaking, the pull-up resistor pulls the level high, usually a 4.7-10K resistor is connected to the Vcc power supply, while the pull-down resistor pulls the level low, and the resistor is connected to the GND ground line. The specific explanation is not what is discussed here. Let’s look at other pin functions next.
5. Other control or multiplexing pins
(1) ALE/PROG 30 When accessing external memory, the output of ALE (Address Latch Enable) is used to latch the low-order byte of the address. Even if the external memory is not accessed, the ALE terminal still outputs a pulse signal at a constant frequency (this frequency is 1/6 of the oscillator frequency). When accessing external data memory, an ALE pulse occurs. When programming the Flash memory, this pin is used to input the programming pulse PROG
(2) PSEN 29 This pin is the strobe signal output terminal of the external program memory. When the AT89C51 fetches instructions or constants from the external program memory, it outputs 2 pulses per machine cycle, which is effective twice. But when accessing external data memory, there will be no pulse output.
(3) EA/Vpp 31 External access permission end. When this pin accesses external program memory, it should be input low. To enable the AT89C51 to only access the external program memory (address 0000H-FFFFH), this pin must remain low, and when the on-chip program memory is to be used, this pin must remain high. When programming the Flash memory, this pin is used to apply the Vpp programming voltage. There are two types of Vpp voltages. Similar to the chip, the maximum frequency value is determined based on the attached number or the characteristic word in the chip. The details are listed in Table 2-3.
Vpp = 12V | Vpp = 5V | |||
Model number printed on the chip surface | AT89C51 xxxx YYW | AT89LV51 xxxx YYW | AT89C51 xxxx-5 YYW | AT89LV51 xxxx-5 YYW |
Feature words in the film | 030H=1EH | 030H=1EH | 030H=1EH | 030H=1EH |
031H=51H | 031H=61H | 031H=51H | 031H=61H | |
032H=FFH | 032H=FFH | 032H=05H | 032H=05H |
Table 2-3 The relationship between Vpp, chip model and on-chip signature words
Seeing this, you should have a certain understanding of the functions of the AT89C51 pins. We will not discuss the timing of the pins in programming and verification in detail here. Under normal circumstances, we do not need to hold it. Unless you want to develop your own programmer. In the following course, we will start to use some simple examples to explain the syntax and writing methods of C programs, interspersed with related hardware knowledge such as serial ports, interrupt usage, etc.
Previous article:How to use Keil to verify how many bytes a microcontroller variable occupies
Next article:ISD4004 voice chip C51 driver source code
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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- The data read by BMI088 spi is always 0xFFFF
- EEWORLD University Hall----T-Box System and Solution Introduction
- What are OTP sheets and mask sheets? What is the difference between them?
- Lichee RV 86 PANEL Review (5) - Game streaming on Lichee RV-86
- Download "Five Factors Affecting Oscilloscope Test Accuracy" to learn how to improve test accuracy
- DIY some electronic devices to make daily life more intelligent
- What are the differences between DK251 CA251 A251 on KEIL website, with pictures
- RT-Thread4.0 is officially released, and also supports SMP (source code download address included)
- Smart speakers are more than just listening - TI DLP Pico technology creates an excellent smart display experience
- What about emoticons?