51 MCU Tutorial from Scratch - Part 7 Parallel Port Structure

Publisher:caoxians4589Latest update time:2012-02-15 Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Use applet to understand what parallel port structure is

Last two times we did two experiments, both of which used the pin P1.0 to turn on the light. We can imagine: since P1.0 can turn on the light, can other pins not? Take a look at Figure 1 , which is the description of the pins of the 8031 ​​microcontroller. Next to P1.0 are P1.1, P1.2...P1.7. Can they all turn on the light? In addition to those starting with P1, there are also those starting with P0, P2, and P3. Count them, there are 32 pins in total. We have learned 7 pins before, and with these 32, there are 39. They all start with the letter P, but the numbers after them are different. Is there any connection between them? Can they all turn on the light? On our experimental board, in addition to P10, there are also P11 -> P17, which are all connected to the LED. Let's do an experiment below. The procedure is as follows:

MAIN: MOV P1,#0FFH
LCALL DELAY
MOV P1,#00H
LCALL DELAY
LJMP MAIN
DELAY:MOV R7,#250
D1:MOV R6,#250
D2:DJNZ R6,D2
DJNZ R7,D1
RET
END

Convert this program into machine code and use a programmer to write it into the microcontroller. What is the result? After power is turned on, we can see that all 8 LEDs are flashing. Therefore, P10->P17 can all light up the lamp. In fact, all 32 pins starting with P can light up the lamp, that is to say: these 32 pins can be used as outputs. If they are not used to light up LEDs, they can be used to control relays and other actuators.

Program analysis: This program is different from the previous one in only two places: the first sentence: originally SETB P1.0, now changed to MOV P1, #0FFH, the third sentence: originally CLR P1.0, now changed to MOV P1.0, #00H. It can be seen that P1 is the representative of P1.0->P1.7 as a whole, and one P1 represents all eight pins. Of course, the instruction used is also different, using the MOV instruction. Why use this instruction? Look at Figure 2, we take P1 as a whole, and treat it as a memory unit. To send a number to a unit, we can use the MOV instruction.

2. The fourth experiment

In addition to being used as output, what else can these 32 pins do? Let's do a microcontroller experiment. The source code is as follows:

MAIN: MOV P3, #0FFH

LOOP: MOV A, P3

MOV P1, A

LJMP LOOP

Let's look at the result of this experiment: all lights are off, then I press a button, and the (1st) light comes on, then I press another button, and the (2nd) light comes on, and when I release the button, the light goes off. Let's analyze the program based on this experimental phenomenon and the circuit.

From the wiring of the hardware circuit, we can see that there are four buttons connected to P3 port P32, P33, P34, P35. We can guess the purpose of the first instruction: to make all P3 ports high level. The second instruction is MOV A, P3. As we know, MOV means to send a number. This instruction means to send the number in P3 port to A. We can regard A as an intermediate unit (see Figure 3). The third sentence is to send the number in A to P1 port again. The fourth sentence is a loop, which is to repeat this process continuously. We have seen this. When we press the first button, the (3)th light is on, so P12 port should output a low level. Why does P12 port output a low level? Let's see what is sent to P1 port. Only the number from P3 port is sent to A and then sent to P1 port. Therefore, it must be the number from P3 port that makes P12 output a high level. The button of the P32 bit of the P3 port is pressed, making the level of the P32 bit low. Through the program, the P12 port outputs a low level, so the P3 port plays an input role. Verification: Pressing the second, third, and fourth buttons, and pressing 2, 3, and 4 buttons at the same time can get the same conclusion, so the P3 port does play an input role. In this way, we can see that the pins starting with the letter P can be used not only as outputs, but also as inputs. Can other pins be used? Yes, they can. These 32 pins are called parallel ports. Let's analyze the structure of the parallel port and see how it realizes input and output.

Parallel port structure analysis:

1. Output structure

Click to browse the next page

First, let's look at the structural diagram of one bit of P1 port (only the output part is drawn): As can be seen from the figure, the opening and closing of the switch represents the high and low output of the pin. If the switch is closed, the pin output is low, and if the switch is opened, the output is high. This switch is controlled by a line. This data bus comes from the CPU. Let's recall that the data bus is a common line for everyone. Many devices are connected to it. At different times, different devices certainly need different signals. For example, at a certain moment, we let this pin output a high level and require it to be maintained for a certain period of time. During this period of time, the computer is of course busy and communicating with other devices. The level on this control line may not be able to maintain the original value, and the output will change. How to solve this problem? We learned in the memory section that the memory can store charges. We might as well add a small memory unit and add a switch in front of it. When this bit is to be output, turn on the switch, the signal enters the memory unit, and then immediately turn off the switch. In this way, the state of this bit is saved until the next command to turn the switch on again. In this way, the state of this bit is independent of other devices. We give such a small unit a very vivid name, called "latch".

2. Input structure

This is a schematic diagram of the output structure of a parallel port. In addition to the output, there are two lines, one connected from the external pin and the other connected from the output of the latch, marked as read pin and read latch respectively. These two lines are used to receive signals from the outside, why two? It turns out that there are two ways to input in the 51 microcontroller, called "read pin" and "read latch". The first way is to use the pin as input, which is to actually read the input value from the external pin. The second way is that when the pin is in the output state, sometimes the state of this bit needs to be changed. In this case, it is not necessary to actually read the pin state, but only read the state of the latch, and then make some changes before outputting.

Please pay attention to the input structure diagram. If this lead is used as an input port, we cannot guarantee that we can get the correct result at any time (why?). Refer to the input diagram in Figure 2. If the switch connected to the outside is open, it should be input 1, and if the switch is closed, it should be input 0. However, if the switch inside the microcontroller is closed, then no matter whether the external switch is open or closed, the data received by the microcontroller is 0. It can be seen that in order to use this port as an input, a "preparation" must be done first, that is, to disconnect the internal switch first, that is, to let the port output "1". Because of this preparation, we call it a "quasi-bidirectional I/O port".

The above is the structure of one bit of port P1. The structures of the other bits of port P1 are the same. The other three ports: P0, P2, and P3 have other uses besides input and output, so the structure is slightly more complicated, but the structure for input and output is the same. See the figure (). For us, these additional functions do not need to be controlled by us, so we don't care about it.

Keywords:MCU Reference address:51 MCU Tutorial from Scratch - Part 7 Parallel Port Structure

Previous article:51 MCU Tutorial from Scratch - Part 6 Delay Program Analysis
Next article:51 MCU Tutorial from Scratch - Part 8 Special Function Registers

Recommended ReadingLatest update time:2024-11-16 15:50

AVR microcontroller assembler pseudo instructions
  Pseudo-instructions do not belong to the instruction system of the microcontroller , but are instructions provided by the assembler, which are used to adjust the location of the program in the memory , define macros, initialize the memory, etc. The assembler of the AVR microcontroller provides a total of 18 pseudo-i
[Microcontroller]
AVR microcontroller assembler pseudo instructions
51 MCU general assembly delay subroutine
: General delay subroutine : 7FEBH - FFEBH : Delay : The delay constant is placed in the R2 register. The delay time corresponding to the time constant N (hexadecimal) (6MZH crystal oscillator) is shown in the following table: : R2=0 : R2 : None Example: Delay 1 second subroutine MOV R2,#18H LC
[Microcontroller]
The concept of timer/counter in MCS-51 microcontroller
1. Concept of timer/counter of MCS-51 microcontroller In a single-chip microcomputer, the relationship between pulse counting and time is very close. Each time a pulse is input, the value of the counter will automatically accumulate by 1, and the time taken is exactly 1 microsecond. As long as the time interval betwe
[Microcontroller]
The concept of timer/counter in MCS-51 microcontroller
Performance comparison of C51, PIC and AVR microcontrollers
Traditional 51: suitable for beginners, easy to use, and average price (in terms of cost performance). Keil is recommended as the IDE environment. Disadvantages: Decryption is easy and general functions are also available, but functions such as AD and eeprom need to be expanded, which increases the burden on hardware
[Microcontroller]
Design of harmful gas infrared detection and voice warning system based on AVR microcontroller
The infrared sensing system is used to sense whether there are harmful gases nearby. When the infrared sensing system senses that harmful gases are approaching, it sends a high level that lasts for a period of time; the single-chip microcomputer starts the voice chip by opening the interrupt, and the single-chip microc
[Microcontroller]
Design of harmful gas infrared detection and voice warning system based on AVR microcontroller
Adjustable PWM output based on stm32 microcontroller
Target: 1. Press button 1 to switch the PWM frequency. 2. Press button 2 to switch the PWM duty cycle. 3. Note: The hardware schematic is not attached, but the pin connections are briefly introduced through description. Hardware principle description: 1. Detect 16 buttons through 3 IO ports. 2. No further de
[Microcontroller]
Renesas Electronics Announces Full Support for ISO/SAE 21434 Standard for Future Automotive MCUs and SoCs
Renesas Electronics Corporation announced on October 8 that its automotive-grade microcontroller (MCU) and system-on-chip (SoC) solutions will fully comply with the ISO/SAE 21434 international standard for cybersecurity engineering for road vehicles in new developments starting in January 2022. This move by Renesas is
[Automotive Electronics]
Renesas Electronics Announces Full Support for ISO/SAE 21434 Standard for Future Automotive MCUs and SoCs
The first in China! The domestically produced, independently controllable, high-performance automotive-grade MCU DF30 chip is released
On November 10, according to the introduction released by Wuhan Economic and Technological Development Zone, on November 9, the 2024 Annual Conference of Hubei Automotive-Grade Chip Industry Technology Innovation Consortium was held in Wuhan Economic and Technological Development Zone. At the meeting, the
[Automotive Electronics]
The first in China! The domestically produced, independently controllable, high-performance automotive-grade MCU DF30 chip is released
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号