Why should the P0-P3 ports of the 89C51 microcontroller be set to 1 for input?

Publisher:xrmilkLatest update time:2023-02-07 Source: elecfansKeywords:89C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The P0~P3 ports of the 89C51 microcontroller are not bidirectional ports in the standard sense. They are only quasi-bidirectional ports. You can read this paragraph according to the structure diagram of the P0 port. Writing 1 to the port means writing 1 to the latch, which means that Its port outputs FF, why, it is like this, write 1 to the latch, then the reverse end of the latch will output 0, then the MOS tube connected to it will be in the cut-off state, that is, in a high-impedance state , so that the data on the P0 port will be correctly input from the three-state buffer of the read pin. If 1 is not written, then the last latched value of the latch may be 0, then 1 may appear on the reverse end, so and The MOS tube connected to the reverse end will be reversed, that is, it will be pulled directly to the ground. Then no matter what signal you input on the P0 port, it will be pulled to a low level. If the input is wrong, set it to 1, otherwise if the previous bit is If the level of the latter input is high, the MOS tube cannot be pulled up, causing an error. There is no need to do this for a two-way port because the two-way port has a suspended state. The quasi-bidirectional port can only effectively read 0, but for 1, it uses the method of reading non-zero, that is, when reading, you must first write 1 to the interface, and then read. The true two-way port is just like its name, that is, the true two-way IO does not require any pre-operation and can be read in and out directly.


Compare the channel structure of MCS-51:

Why should the P0-P3 ports of the 89C51 microcontroller be set to 1 for input?

Why should the P0-P3 ports of the 89C51 microcontroller be set to 1 for input?

Why should the P0-P3 ports of the 89C51 microcontroller be set to 1 for input?

Why should the P0-P3 ports of the 89C51 microcontroller be set to 1 for input?

The I/O port has three operating modes: output data mode, read port data mode, and read port pin mode.

Output data method:

As long as one data operation instruction is needed, the output data can be written into the port latch of P0~3, and then sent to the port pin through the output driver.

eg. MOV P0, A

MOV P0, #data

How to read port data:

It is an operation mode that only reads the data in the latch. The data read is not the data input by the port pin. The CPU can read the data in the port latch into accumulator A or internal RAM with just one transfer instruction.

e.g. MOV A, P1

MOV R1, P1

How to read port pins:

Read information from the port pin lines. The CPU must first set the latch corresponding to the port pin to be read in order to drive the T2 tube (T tube of other ports) to turn off; then open the input tri-state buffer so that the signal on the corresponding port pin is input to the MCS- 51 internal data bus. Therefore, two instructions are needed to complete reading the port pins.

eg. MOV P1, #0FH

MOV A, P1; First set the lower four bits of P1 port, then read the fourth bit pin line signal of P1 port and send it to A.


Keywords:89C51 Reference address:Why should the P0-P3 ports of the 89C51 microcontroller be set to 1 for input?

Previous article:51 microcontroller learning: dynamic digital tube experiment
Next article:C51 microcontroller control design for common anode digital tubes

Latest Microcontroller Articles
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号