Graduation feedback - GPIO usage of 89C51

The STC89C51 series microcontrollers have the following types of GPIO ports:

(1) P0.0-P0.7:

Corresponding to pins 39-32 of DIP40 package: P0 port can be used as input/output GPIO port or as address/data multiplexing bus.

a) When the P0 port is used as an input/output IO port , P0 is an 8-bit quasi-bidirectional IO port, which is in open-drain mode after power-on reset. And there is no pull-up resistor inside the P0 port, when it is used as I/O, an external pull-up resistor of 4.7K-10K must be connected;

b) When the P0 port is used as an address/data multiplexing bus, it is the lower eight-bit address line [A0-A7] and the data line [D0-D7], no external pull-up resistor is required

(2)P1.0-P1.7:

Corresponding to pins 1-8 of DIP40 package: all can be used as standard IO ports. For 90 series 51-core microcontrollers, P1.0 and P1.1 have secondary functions, and P1.0 can be used as timer/counter 2 (Timer2/Count2) external input; P1.1 can be used as the trigger control of the capture/reload mode of timer/counter 2 (Timer2/Count2).

(3)P2.0-P2.7:

Corresponding to the pins 21-28 of the DIP40 package: there is a pull-up resistor inside, which can be used as an input and output port or as a high-order 8-bit address bus (A8-A15); when used as an input and output port, the P2 port is a standard two-way port

(4)P3.0-P3.7:

Corresponding to pins 10-17 of DIP40 package: can be used as standard IO ports. In addition, both have a second function;

P3.0—RXD: Serial data receiver

P3.1—TXD: Serial data transmitter

P3.2—INTO: External interrupt 0, falling edge interrupt or low level interrupt (active low)

P3.3—INT1: External interrupt 1, falling edge interrupt or low level interrupt (active low)

P3.4—T0: External input of timer/counter 0

P3.5—T1: External input of timer/counter 1

P3.6—WR: External data memory write pulse (active low)

P3.7—RD: External data memory read pulse (active low)

Introduction to GPIO mode:

51 MCU IO ports all have quasi-bidirectional port/weak pull-up, and open-drain output mode; P1, P2, P3 are quasi-bidirectional port/weak pull-up after power-on reset, and P0 port is open-drain output after power-on reset.

Among them, the maximum sink current of the P0 port of the 5V microcontroller is 12mA, and the maximum sink current of other IO ports is 6mA;

The maximum sink current of the P0 port of the 3V microcontroller is 8mA, and the maximum sink current of other IO ports is 4mA;

image

Before the quasi-bidirectional port reads the external state, it must be latched as '1' before the external state can be read;

image

When the port latch is 0, the open-drain output turns off all pull-up transistors; when used as a logic output, this configuration must be pulled up externally. Generally, it is externally connected to VCC through a resistor. If there is an external pull-up resistor, the open-drain IO port can also read the external state.

Experiment - LED on and off and blinking

image

Working principle of LED: When there is a forward voltage drop greater than 0.7V between its anode and cathode, the LED is turned on and then brightens;

The connection with the microcontroller is as follows:

image

The formula for calculating the current limiting resistor is as follows:

LED (light-emitting diode), that is, light-emitting diode, commonly known as LED light, ordinary SMD light-emitting diode. The forward conduction voltage of this kind of diode is usually between 1.8V and 2.2V, and the working current is generally between 1mA and 20mA.

image

Therefore, for the sake of safety in engineering, a 200-3k resistor is generally selected.

Pin Definition:

image

The IO port is initialized as follows:

image

The main function is as follows:

image

Through the above procedures, the LED lights can be turned on;

The blinking of the LED light is realized as follows:

The principle of flickering is to add a certain delay function in the middle of switching on and off. We modify the LED light lighting program as follows:

image

The delay() function is defined as follows:

image

Since then, LED1 can be flashed, and LED2 can be always on.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324611036&siteId=291194637