Introduction to single chip microcomputer - basic control of LED indicator light

Publisher:温柔之风Latest update time:2022-06-13 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Implementation process

74HC138 decoder (38 decoder) -> 74HC02 NOR gate -> 74HC573 latch


38 decoder


Three inputs control eight mutually exclusive low-effective outputs (three P2 ports control eight Y ports, controlling Y4 to output a low level)


74HC02 NOR Gate


After Y4 outputs a low level, it passes through the NOR gate. At this time, WR is a low level (using the I/O expansion method), and Y4C inputs a high level, that is, LE is a high level (equivalent to making the latch work). Only then can the LED light up. As for the encoding form of the P0 port, I will not write it (this is very simple)


74HC573 Latch


OE: Output Enable

LE: Latch Enable

(I haven't learned these two yet, so it won't affect my study)

Come to update,

D is the input terminal and Q is the output terminal

Note that there is a horizontal bar on OE, which means that the low level is valid (that is, the circuit will work only when the level is low), so OE is connected to the GND terminal

When Y4C inputs a high level, that is, LE is a high level, the state of the Q terminal is determined by the state of the D terminal; when LE is a low level, at this time, no matter what state D is, Q maintains the previous data state.


as the picture shows:


74HC573 Latch

insert image description here

74HC138 decoder (38 decoder) and 74HC02 NOR gate

insert image description here

Different pin connections of J5, J2, and J13 jumper caps (I will update the pin connections later when I learn more)


Jumper cap connection method (connection method of this program): J5 connects to KBD terminal J13 connects to I/O port J2 connects to 2-4 1-3 terminal


code show as below:


#include

//sbit HC138_C=P2^7;

//sbit HC138_B=P2^6;

//sbit HC138_A=P2^5;


void Delay(unsigned int t){//delay function

while(t--);

    while(t--);

}


void LEDrunning() //The LED light flashes three times, then runs in the form of a running light, and repeats the above operation continuously

{

  unsigned char i;

// HC138_C=1;

  //HC138_B=0;

// HC138_A=0;

//The commented code has the same effect as the code for opening and closing registers

  P2 = (P2&0x1F|0x80); //Open register

  for(i=0;i<3;i++)

{

P0=0x00; //LED lights fully on

Delay(60000);

Delay(60000);

P0=0xff; //LED lights are all off

Delay(60000);

Delay(60000);

}

//The following two for loops form the LED light water light form

for(i=1;i<=8;i++){

P0=0xff< Delay(60000);

Delay(60000);

}

for(i=1;i<=8;i++){

P0= ~(0xff< Delay(60000);

Delay(60000);

}

P2 &= 0x1F; //Close register

}


void cls_buzz(void) //Turn off the buzzer

{

P2 = (P2&0x1F|0xA0);

P0 = 0x00;

P2 &= 0x1F;

}


void main()

{

cls_buzz();

while(1){

LEDrunning();

}

}


This is basically how you control the display of LED lights. I will update this later when I learn more.


Come to update,


Turn off peripherals


void cls_buzz(void) //Turn off the buzzer

{

P2 = (P2&0x1F|0xA0);

P0 = 0x00;

P2 &= 0x1F;

}


P2 = (P2&0x1F|0xA0);

0x1F is written as 0001 1111 in binary. The default state of P2 port is 1111 1111. P2&0x1f is to clear the upper three bits to 0, because we only need to control the three ports P7-5 in the current register. 0xA0 is 1010 0000. This code is to make Y5 low level, and make Y5C input high level through the NOR gate to control the Y5C latch (as shown in the figure)


P0 = 0x00;

ULN2003, equivalent to a NOT gate, turns off the buzzer and relay (see the buzzer and relay in this column for details)


P2 &= 0x1F;

Close, the use of this register ends


Open the register to use the LED


P2 = (P2&0x1F|0x80); //Open register


This is to open the Y4C latch


P2 &= 0x1F; //Close register


Close the Y4C latch

Keywords:MCU Reference address:Introduction to single chip microcomputer - basic control of LED indicator light

Previous article:51 MCU Introduction - Buzzer and Relay
Next article:Introduction to 51 MCU - UART serial communication

Recommended ReadingLatest update time:2024-11-16 19:43

Programming of automatic testing device for furniture door drawer durability based on 51 single chip microcomputer
#include #define uint unsigned int #define uchar unsigned char #define ZKB 6               //duty cycle initial value setting #define max_time 100       //Set the timeout   sbit gd1=P1^0;             //The photoelectric switch is blocked and the level is high, and it is not blocked and the level is low
[Microcontroller]
Design of motor speed measurement system based on single chip microcomputer
This article mainly measures the speed of the motor, and then uses a digital tube to display the speed of the motor. This device mainly consists of two parts: the photoelectric speed measurement part, the measured pulse processing and the display part. The photoelectric speed measurement part is mainly composed of a p
[Microcontroller]
Design of motor speed measurement system based on single chip microcomputer
Analyze the three data transmission methods of 8051 microcontroller
There are usually several ways to exchange information between the microcontroller CPU and external devices: unconditional transmission, query transmission and interrupt transmission. We use the interface between a microcontroller and a microprinter as an example to describe these three methods. Assume that the user w
[Microcontroller]
Analyze the three data transmission methods of 8051 microcontroller
How to use PIC16F628A microcontroller to read DHT11 temperature and humidity sensor
This article mainly introduces how to use PIC microcontroller to read humidity and temperature from DHT11 and display it on LCD display. In this example, the microcontroller model we use is PIC16F628A. Required Content To complete this project, you will need the following:  ● Use a computer with Microchip MPLAB X ID
[Microcontroller]
How to use PIC16F628A microcontroller to read DHT11 temperature and humidity sensor
STMicroelectronics' ultra-low-power MCU supports Dracula organic photovoltaic technology
Dracula Technologies has announced that its LAYER organic photovoltaic (OPV) technology is now fully compatible with STMicroelectronics' latest ultra-low-power microcontrollers. To improve the energy efficiency and autonomy of microcontroller units (MCUs), LAYER uses ambient indoor light to enable sustain
[Microcontroller]
What are the delay methods of single chip microcomputer?
There are usually two ways to achieve delay: one is hardware delay, which requires the use of timers/counters. This method can improve the CPU's working efficiency and achieve accurate delay; the other is software delay, which mainly uses loops. 1 Using timers/counters to achieve accurate delay Single-chip microcomp
[Microcontroller]
51 microcontroller basics GPIO output
Code: #include reg52.h //Reference the header file of the 51 microcontroller, including registers and other operations sbit LED=P2^0;                    //Define the P2^0 pin, which is a bit operation and will be used to output high and low levels later to light up the LED. void delay(unsigned int u16) //un
[Microcontroller]
51 microcontroller basics GPIO output
Automatic Control of Rice Milling and Polishing Machine Using Single Chip Microcomputer
1 Introduction After multiple milling processes, the rice bran has been stripped, but the surface of the rice grains is relatively rough. In order to ensure the quality and appearance of the rice, the last process of rice processing is required: polishing. The polishing of rice grains is completed by a rice milling an
[Microcontroller]
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号