Questions about reading ports and pins of 51 single-chip microcomputers

Publisher:RadiantSmileLatest update time:2017-01-18 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The 80C51 microcontroller has four P ports, P0-P3. Take P0 as an example:
To understand this problem, you need to understand the internal structure of port P0. Port P0 is connected
to the external pin by a latch through two driving field effect transistors. Reading the pin means directly reading the potential of the external pin of P0, while reading the port (latch) reads the potential of the internal latch connected to the data bus.
The two are different. Generally speaking, reading the data of P0 is reading the pin, the purpose is to obtain the state of the external circuit connected to P0. Reading the port is completed by the CPU itself when executing the following statement:
inc P0; add 1 to p0
When executing this statement, the "read-modify-write" process is adopted, first read the port data of p0, then add 1, and then send it to the latch of p0. Note that this port data is different from the pin state of p0. For example, if you write 69H to p0 in advance, the data in p0 is 69H, and the state on the pin will not enter the latch of p0 because you have not executed instructions such as MOV A, p0. It can be seen that the so-called reading port is not to read the state of p0, but it is completed by the CPU itself when executing instructions such as inc.
Reading the pin is to read the state of the p0 port. When reading the pin, pay attention to: first write FFH to p0 to disconnect its field effect tube T2 from the ground.
Because the field effect tube T2 of the p0 port is grounded at one end and connected to the external pin at the other end, it is controlled by the latch of P0. When writing 1 to the latch, it is disconnected from the ground, and when writing 0, it is connected to the ground, so when writing zero, it is always read at a low level.
Imagine that you want to read the P0 pin now. It stands to reason that P0 is connected to the external circuit, and what the external circuit is in is what you should read. However, if one end of the field effect tube T2 of the p0 port is grounded, it will pull down the potential of the p0 port, and you will always read a low level 0, so you must first write FFH to p0 to disconnect the field effect tube T2 of p0 from the ground, and then read the real state. When the external circuit is disconnected, the actual state of the p0 port (latch) is read again.

Reference address:Questions about reading ports and pins of 51 single-chip microcomputers

Previous article:Example of using 51 single-chip microcomputer to simulate I2C interface
Next article:Single chip microcomputer counter T0 as timing technology (timer design)

Recommended ReadingLatest update time:2024-11-23 19:04

Design of intelligent solar street light based on STC12C2051 microcontroller
简介:太阳能路灯的应用具有重要的现实意义,尤其是靠小规模火力发电或季节性水力发电的地区,更应大力发展太阳能电力。太阳能路灯以其先进、稳定、智能、成熟的控制技术及显著的节能特性、简便的维护方式等特点得到推广。随着太阳能照明灯具产品的普及,很多应用项目存在质量和售后服务问题。 太阳能路灯的应用具有重要的现实意义,尤其是靠小规模火力发电或季节性水力发电的地区,更应大力发展太阳能电力。太阳能路灯以其先进、稳定、智能、成熟的控制技术及显著的节能特性、简便的维护方式等特点得到推广。随着太阳能照明灯具产品的普及,很多应用项目存在质量和售后服务问题。因此,需及时分析原因、规范市场,使太阳能路灯市场健康有序地发展。太阳能是地球上最为直接、普遍、
[Microcontroller]
Design of intelligent solar street light based on STC12C2051 microcontroller
51 MCU receiving array knowledge
Introduction: I am working on a project recently, in which one module needs to communicate with the computer through the serial port. I use C language to program the microcontroller and .net to program the application. One of the requirements is that the computer sends ten data at a time, and an array is defined in th
[Microcontroller]
51 single-chip microcomputer STC12C5A60S2 timer is used as delay function, and the timer realizes accurate delay
/*====================================================================== Using timers to implement precise delay calling functions === ... #include STC12C5A60S2.h typedef unsigned char u8; typedef unsigned int u16; u16 count;   //interrupt count variable bit flag = 0; //Mark time ends //============================
[Microcontroller]
80c51 is several microcontrollers. 80c51 microcontroller has several interrupt sources.
  How many microcontrollers are 80c51?   80C51 is an 8-bit microprocessor, also known as 8051, launched by Intel Corporation. It is one of the earliest commercial microcontrollers and is widely used in many embedded systems because of its simplicity, ease of use, flexibility and reliability. In the 80C51 series, the m
[Microcontroller]
Operation of IO ports of 51 MCU, AVR MCU and PIC MCU
The IO port structures of 51 MCU, AVR MCU and PIC MCU are all different, which leads to different IO port operations. The purpose of operating the MCU IO port is to make the MCU pin output logic level and read the logic level of the MCU pin. Let's take a look at the operation methods of 51 MCU, AVR MCU and PIC MCU IO
[Microcontroller]
Application plan of temperature acquisition and monitoring system based on 8051F350 microcontroller
1 Introduction Temperature is a common and important physical parameter in production processes and scientific experiments. In industrial production, in order to produce efficiently, the main parameters in the production process, such as temperature, pressure, flow, speed, etc., must be effectively controlled. Among t
[Microcontroller]
Application plan of temperature acquisition and monitoring system based on 8051F350 microcontroller
19- Temperature and humidity GSM reporting based on 51 single chip microcomputer
Specific implementation functions: (1) The measurement and display of temperature and humidity values ​​are stable and accurate;  (2) The temperature and humidity alarm thresholds can be set by pressing buttons, and when the measured temperature and humidity exceed the set thresholds, the alarm indicator light fla
[Microcontroller]
19- Temperature and humidity GSM reporting based on 51 single chip microcomputer
Capture and storage of transient signals based on AT90S8515 single chip microcomputer
In many fields of contemporary scientific research, the problem of how to capture single transient signals is often encountered. For high-speed data acquisition systems such as single pulse signal capture and periodic signal spectrum analysis, DMA technology is usually used. Whether it is implemented by the DMA cont
[Microcontroller]
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号