1. Teaching purpose: Master the pin functions of microcontroller
2. Teaching focus: The use and differences of the P0, P1, P2, and P3 ports of the microcontroller
3. Teaching steps:
(1) Appearance of microcontroller (AT89S51)
(2) Pin function diagram of microcontroller (AT89S51)
(3) The 51 series microcontrollers 8031, 8051 and 89c51/89s51 all adopt a 40Pin packaged dual-row direct DIP structure. The picture above is their pin configuration: among the 40 pins, there are two positive power and ground wires, two clock lines for the external quartz oscillator, 4 groups of 8 bits totaling 32 I/O ports, and the interrupt port line is P3 port line reuse. Now we explain the functions of these pins:
1. Power pin
The Vcc40 pin is the positive power supply pin, and the working voltage is 5V. The working voltage of AT89LV51 is 2.7-6V, and the pin functions are the same.
GND20 ground terminal
2. External crystal pin
Pin19: Clock XTAL1 pin, Pin18: Clock XTAL2 pin,
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 RST9
When the oscillator is running, when a high level for more than two machine cycles (24 oscillation cycles) appears on this pin, the microcontroller will be reset. As long as this pin remains high, the 51 chip will be reset cyclically. 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 0000H of ROM. The commonly used reset circuit is shown in the figure below.
The reset operation has no effect on the internal RAM. When the 8051 is powered on, the clock circuit starts to work, and a high level appears on the RESET pin for more than 24 clock cycles, and the system is initially reset. What is reset? Reset means that the microcontroller re-executes the program code.
The reset mode of 8051 can be automatic reset or manual reset, see the figure below. In addition, RESET/Vpd is also a multiplex pin. During Vcc power-down, this pin can be connected to the backup power supply to ensure that the data in the internal RAM of the microcontroller is not lost.
Input and output (I/O) pins:
Pin39-Pin32 are the P0.0-P0.7 input and output pins, called P0 port, which is an 8-bit open-drain bidirectional I/O port. There is no internal pull-up resistor. When an external pull-up resistor is connected, port P0 can drive eight LSTTL load circuits by absorbing current. Usually, an external pull-up resistor is used to drive multiple digital tubes. When accessing external programs and external data memory, the P0 port is a time-sharing converted address (lower 8 bits)/data bus, and does not require an external pull-up resistor.
Pin1-Pin8 are the input and output pins of P1.0-P1.7, called the P1 port. It is an 8-bit bidirectional I/0 port with an internal pull-up resistor. Port P1 can drive 4 LSTTL loads. Usually, no external pull-up resistor is required during use, and the light-emitting diode can be directly driven. When the port is set to 1, the internal pull-up resistor pulls the port to a high level for input.
Let’s talk about its output function now. When the microcontroller is working, we can control the pins of the microcontroller to output high level or low level by using instructions. For example: Instruction CLR means clearing.
CLR P1.0; Let the microcontroller output low level from the first pin.
The instruction SETB means setting 1.
SETB P1.0; Let the microcontroller output high level from the first pin.
How to write the instruction to make the 8th pin output low level?
Pin21-Pin28 are the input and output pins of P2.0-P2.7, called the P2 port. It is an 8-bit bidirectional I/O port with an internal pull-up resistor. The P2 port can drive 4 LSTTL loads. 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.
Pin10-Pin17 are the input and output pins of P3.0-P3.7, called the P3 port. It is an 8-bit bidirectional I/O port with an internal pull-up resistor. The P2 port can drive 4 LSTTL loads. These 8 pins Also used for specialized second functions. 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.
When the P1-3 port is used for input, due to the internal connected resistor, the pin that is externally pulled low will output a certain current.
In addition, the P3 port is also used for some specialized functions. Please see the table below for details.
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 |
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 AT89S51 to only access external program memory (address 0000H-FFFFH), this pin must be kept low at this time. Used to apply Vpp programming voltage when programming Flash memory.
Seeing this, you should have a certain understanding of the functions of the AT89S51 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.
Previous article:Reset operation and reset circuit design of AT89S51 microcontroller
Next article:Decryption principle of AT89C51 microcontroller
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- msp430f149 microcontroller serial port C program
- Pulse meter based on 51 single chip monitors pulse rate and draws electrocardiogram
- EEWORLD University - How to repair damaged printed lines
- [Environmental Expert's Smart Watch] Part 17: Watch Modeling and Animation
- Thank you for your partnership
- EEWORLD University ---- Texas Instruments SimpleLink? Wi-Fi Solution
- Motor stroke control problem
- Help with the angle, acceleration conversion and accuracy of LSM6DSM
- Urgently looking for chip model
- ESP32-S3 KORVO-2 2.4'' ARDUINO TFT Unboxing Report