This is the seventh day of my participation in the August More text Challenge. For details, see:August is more challenging

In the project often encounter the MCU IO port resources are not enough, so how to maximize the use of THE MCU I/O port, here to share with the MCU two I/O port control three LED light several methods.

In the simulation software through two switches to simulate the MCU IO port output high and low levels.

Method one:

S1 and S2 are connected to two IO ports of the single chip microcomputer, here through a single pole double throw key analog IO port output high and low levels.

When S1 and S2 are low at the same time, all LED lights are off.

When both S1 and S2 are low, the positive and negative terminals of the three diodes are all 0V, so all the leds are off.

When S1 is low level and S2 is high level, LED2 is on.

When S1 is low level and S2 is high level, the tips of R4 and R3 are both 5V, and LED3 is negative and very high level, and positive and 0V,LED3 does not operate. LED2 positive extremely high level, negative extremely 0V, LED2 on. S1 is low level, the transistor Q1 does not operate, so LED1 does not operate.

When S1 is high level and S2 is low level, LED3 is on.

When S1 is high and S2 is low. LED3 positive extremely high level, negative extremely low level, LED3 on. LED2 positive is very low level, negative is very high level, LED2 does not operate. Triodes Q1 and Q3 do not operate, and neither does LED1.

S1 is high level, S2 is high level, LED1 is on.

When S1 is high and S2 is high. The positive and negative terminals of LED3 and LED2 are both high level, so LED2 and LED3 are not on. At this time, Q1 and A3 are on, LED1 is positive very high level, and negative very low level, so LED1 is on.

Method 2:

S3 and S4 are connected to two IO ports of single chip microcomputer respectively. Here, a single-pole double-throw key is used to simulate THE IO port to output high and low levels.

When S3 and S4 are low at the same time, LED4 is on.

S3 is low level, S4 is high level, LED6 is bright.

S3 is high level, S4 is low level, LED5 is bright.

S3 is high level, S4 is high level, LED5 and LED6 are on at the same time.

Method 3:

S1 and S2 are connected to two IO ports of the single chip microcomputer, here through a single pole double throw key analog IO port output high and low levels.

When S1 and S2 are low at the same time, all LED lights are off.

When S1 is low level and S2 is high level, LED3 is on.

When S1 is high level and S2 is low level, LED2 is on.

S1 is high level, S2 is high level, LED1 is on.

Method 4:

S3 and S4 are connected to two IO ports of single chip microcomputer respectively. Here, a single-pole double-throw key is used to simulate THE IO port to output high and low levels.

When S3 and S4 are low at the same time, all LED lights are off.

S3 is low level, S4 is high level, LED6 is bright.

S3 is high level, S4 is low level, LED5 is bright.

S3 is high level, S4 is high level, LED4 is bright.

Through four combinations of high and low levels of two IO ports, combined with external circuits, three LED lights can be controlled on and off.