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:
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.
Previous article:51 microcontroller learning: dynamic digital tube experiment
Next article:C51 microcontroller control design for common anode digital tubes
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- Chinese mobile phones continue to sell well in India, Vivo surpasses Samsung to become the second largest brand
- A huge reward! Looking for someone who can crack the RSA2048 and factory protocol in the ECU!
- Family Pet Health Maintenance System
- HF Antenna Analyzer(3MHz to 30MHz)
- 1. Previous Power Supply Competition Topics
- The "Soul" of the Microcontroller - The Use of Data Memory
- Detailed Explanation of I2C Bus Protocol
- What is the difference between package 0603 and R0603 (or 0603R)?
- [Yatli AT32F421 Review] Doubts from EXTI disconnection
- List of instruments, equipment and main components for the 2019 National Undergraduate Electronic Design Competition