【51 MCU】I/O port

Publisher:和谐的24号Latest update time:2024-07-26 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Summarize

  • P0: Open-drain bidirectional I/O port without built-in pull-up resistor, can be used as a high-impedance input terminal.
    When P0 port is used as a normal I/O, an external 10KΩ pull-up resistor is required. When used as a low 8-bit address/data bus, no external pull-up resistor is required.

  • P1 ~ P3: Bidirectional I/O ports with built-in pull-up resistors. Each port buffer can receive and output 4 TTL gate circuits.

  • When P0 ~ P3 are used as input terminals, the P0 ~ P3 ports must be set to 1 first, so that the internal field effect tube is cut off, thus not affecting the input level.

  • P0 ~ P3 can all be bit-operated.

The following picture is for fun. If you don't have any basic knowledge, this thing looks like self-castration.

1. P0

insert image description here
1 output latch (D-type flip-flop)
2 tri-state buffers (control read pins or read latches)
1 output drive circuit (composed of a pair of field effect transistors FET)
1 output control terminal (composed of an AND gate, an inverter, and a switch MUX)

1.1 Make an input port

The input signal of the P0 port is sent to both the tri-state buffer below and the drain of V2. If the latch is previously latched as 0, that is, Q=0, Q'=1, then V2 is turned on, and the P0 port is clamped at the 0 level through the external pull-up resistor of the P0 port, and 1 cannot be sent to the P0 port. Therefore, before data is input to the P0 port, 1 must be written to the latch through the internal bus, that is, Q=1, V2 is turned off, and the 1 input from the P0 port can be sent to the input of the tri-state gate. At this time, a read control signal (high level) is sent to the read pin of the tri-state gate, and 1 can be sent to the internal bus through the tri-state gate.

1.2 Make output port

At this time, the CPU inside the single-chip microcomputer will send a 0 to the control end of the AND gate. The 0 at the control end closes the AND gate on the one hand, so that the signal sent by the address/data bus cannot pass through the AND gate; on the other hand, it controls the electronic switch to connect the electronic switch to the Q' end of the latch. At this time, if a write pulse signal is sent to the write latch end CP, the data sent by the internal bus can enter the latch through the D end and output from the Q and Q' ends. If the D end inputs 1, the Q' end outputs 0, which turns off the field effect tube V2. Through the external pull-up resistor of the P0 port, the P0 port can output a high level 1.

2. P1

insert image description here
1 output latch
2 tri-state input buffers
Output drive circuit

2.1 Input Function

At this time, Q=0, non-Q=1, the field effect tube is turned on, and through the internal pull-up resistor of P1 port, P1 port is clamped at 0 level, and 1 cannot be sent to P1 port. So like P0 port, before data is input to P1 port, 1 must be written to the latch through the internal bus to make non-Q=0, the field effect tube is turned off, and the 1 input from P1 port can be sent to the input end of the input tri-state buffer. At this time, a read control signal is sent to the read pin of the tri-state gate, and 1 can be sent to the internal bus through the tri-state buffer.

2.2 Output Function

First send a write pulse signal to the CP end of the latch, and the data sent by the internal bus can enter the latch through the D end and be output from the Q and non-Q ends. If DUAN input is 1, non-Q = 0, 0 is sent to the gate of the field effect tube, the field effect tube is cut off, and 1 is output from P1.

3. P2

insert image description here
1 output latch
1 switch MUX
2 three-state input buffers
1 inverter
Output drive circuit

3.3 Input Function

Similarly, it is necessary to write 1 to the latch through the internal bus first, so that Q=1, the field effect tube is turned off, and the 1 input from the P2 pin can be sent to the input end of the three-state gate. At this time, send a read control signal to the read pin, and 1 can be sent to the internal bus through the three-state gate.

3.2 Output Function

At this time, a write pulse signal is sent to the CP end of the latch, and the data on the internal bus is latched into the latch and output from the Q end, and then output from the P2 port through the MUX switch, NOT gate and field effect transistor.

4. P3

insert image description here
1 output latch
3 input buffers
Output drive circuit (including 1 NAND gate, 1 field effect transistor T, pull-up resistor R)

4.1 Input and Output

The usage is similar to P1 and P2.

4.2 Multiplexing Function

At this time, the port can input the interrupt request signal sent by the external device.


Reference address:【51 MCU】I/O port

Previous article:【51 MCU】Interrupt system
Next article:Simple digital voltmeter + ADC0832 + serial SPI mode to achieve 1-way data conversion

Recommended ReadingLatest update time:2024-11-15 17:47

I2C bus learning and EEPROM
1. Introduction to I2C Bus 2. Preliminary understanding of I2C bus 3. I2C bus timing I2C communication is divided into the start signal Start, the data transmission part (can be multiple bytes), and the stop signal Stop I2C bus data transmission is 9 bits at a time, 8 data bits and one ACK bit. Data is trans
[Microcontroller]
I2C bus learning and EEPROM
stm32F103 simulates I2C read and write 24c02
/*********File name: i2c_ee.h**********/ /* Define to prevent recursive inclusion ------------------------------------ */ #ifndef __I2C_EE_H #define __I2C_EE_H /* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" /* Exported macro -------------------------------
[Microcontroller]
STM32 as I2C host, read and write 24C02 EEPROM
1. Transmission of clock and data: start and stop conditions, data is valid during the high level of SCL and changes during the low level of SCL. 2. Start condition: During the high level of SCL, SDA generates a falling edge 3. Stop condition: During the high level of SCL, SDA generates a rising edge 4. Response: Succ
[Microcontroller]
I2C Bus Detailed Notes
1 Introduction The I2C bus is the de facto world standard and is now implemented by more than 1,000 different ICs manufactured by more than 50 companies. In addition, the versatile I2C bus is used in a variety of control architectures such as the System Management Bus (SMBus), Power Management Bus (PMBus), Intelligent
[Microcontroller]
I2C Bus Detailed Notes
EEPROM 24c02 [I2C code package-save to realize running lights]
Here, EEPROM 24c02 is encapsulated and can be directly called in the future. Its connection method is: SDA-P2.1; SCL-P2.0; WP-VCC _ :i2c.c   1 /*-----------------------------------------------   2 Name: IIC Protocol    3 Content: The function uses software delay method to generate SCL pulse, so it is necessary to mak
[Microcontroller]
pic's I2C settings
Setting up i2c in pic: The pins cannot be set to open-drain output during initialization, otherwise the levels of the two pins will be pulled low when the module is enabled. In register I2CxION, directly set bit 15 to 1, set the baud rate, and refer to the following references;
[Microcontroller]
Xiaoi Robot won the "9th Wu Wenjun Artificial Intelligence Science and Technology Progress Award"
Recently, the list of winners of the Wu Wenjun Artificial Intelligence Science and Technology Award, known as the "highest award for intelligent science and technology in China", was officially announced, with more than 80 scientific and technological achievements emerging from the final defense. Xiaoi Robot won the
[Embedded]
Xiaoi Robot won the
I2C deadlock causes and solutions
The deadlock bus is manifested as: SCL is high and SDA is always low Phenomenon: The MCU uses hardware i2c to read E2PROM. When the MCU is reset, there is a probability that it can no longer communicate with E2PROM. At this time, SCL is high and SDA is always low. Reason: When the MCU is communicating with the E2P
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号