Lanqiao Cup MCU (1) Turn on the LED light


Preface

   Introduction to the Blue Bridge Cup MCU:
1. Qualifications: full-time undergraduate and higher vocational students with formal student status
2. Competition time: Preliminary duration: 5 hours Final time duration: 5 hours
3. Test question format: Competition test questions are objective It consists of two parts, the programming and debugging questions based on a unified hardware platform.
4. Hardware platform: Guoxin Changtian MCU competition training platform (The MCU model is IAP15F2K61S2)


Tip: The following is the content of this article, the following cases are for reference

1. LED principle

       LED (Light Emitting Diode), a light-emitting diode, is a solid-state semiconductor device that can convert electrical energy into visible light. It can directly convert electricity into light. The heart of the LED is a semiconductor chip, one end of the chip is attached to a bracket, one end is the negative pole, and the other end is connected to the positive pole of the power supply, so that the entire chip is encapsulated by epoxy resin.
       The semiconductor wafer is composed of two parts, one part is a P-type semiconductor, in which holes dominate, and the other end is an N-type semiconductor, where electrons are mainly used. But when these two semiconductors are connected, a PN junction is formed between them. When the current acts on the chip through the wire, the electrons will be pushed to the P area, where the electrons and holes recombine, and then emit energy in the form of photons, which is the principle of LED light emission. The wavelength of light is the color of light, which is determined by the material forming the PN junction.

2. Light up the LED lights

1. LED module

Insert picture description here
   The diode characteristics show that when Q1=0, L1 is on. Use this to control the LED lights to turn on and off.

2.74HC138 chip and 74HC02 chip

       74HC138 is a high-speed CMOS device, 74HC138 is pin compatible with low power Schottky TTL (LSTTL) series. The 74HC138 decoder accepts 3-bit binary weighted address input (A0, A1 and A2), and when enabled, provides 8 mutually exclusive low-effective outputs (Y0 to Y7).
      74HC138 has 3 unique enable inputs: two low-active (E1 and E2) and one high-active (E3). Unless E1 and E2 are set low and E3 is set high, 74HC138 will keep all outputs high.
Insert picture description here
The truth table of 74HC138 chip is shown in the figure below: The
Insert picture description here
function table of 74HC02 chip is shown in the figure below:
Insert picture description here

3. Overall thinking

       Through 74HC138 chip and 74HC02 chip input high and low level, to control Y4C to 1 or 0. When Y4C is 1, the LED light can be turned on and off through the P0 port. When Y4C is 0, the LED light cannot be controlled on and off. For example, if P27 is 1, P26 is 0, and P25 is 0, then output Y4 is 0, and then input Y4 as 0 through 74HC02 chip, then Y4C output is 1. Then pass P0 to 0xfe, Q8~Q1, which is 1111 1110, and control L1 to light up. You can also set P0 to 0x00, that is, Q8~Q1, to 0000 0000, and control L1~L8 to light up at the same time.

Three, code implementation

The code is as follows (example):

#include <STC15F2K60S2.h>	//定义头文件

#define uchar unsigned char
#define uint unsigned int

#define Y4 P2=(P2&0x1f)|0x80;	//Y4C为1

void main()
{
    
    
	while(1)
	{
    
    
		Y4;P0=0x00;	//全部LED灯一直亮
	}
}

to sum up

       I have learned a lot of knowledge by participating in the 11th Blue Bridge Cup MCU competition, so I will share it here. This tutorial is only suitable for beginners to learn. Everyone, don’t spray if you don’t like it. This tutorial only explains the use of a single module, and does not explain the implementation of multiple modules. After all, I have limited energy. Please forgive me! ! !

Do not reprint without my permission!!!

Guess you like

Origin blog.csdn.net/weixin_44935259/article/details/111564881