当前位置:网站首页>Blue Bridge Cup Guoxin Changtian single chip microcomputer -- led lamp module (V)

Blue Bridge Cup Guoxin Changtian single chip microcomputer -- led lamp module (V)

2022-07-03 21:52:00 C don't laugh

LED Etc

 Insert picture description here
The whole idea
adopt 74HC138 Chip and 74HC02 Chip input high and low level , To control Y4C by 1 or 0. When Y4C by 1 when , To be approved P0 Port to control LED The light goes on and off . When Y4C by 0 when , beyond control LED The light goes on and off . Such as : Make P27 by 1、P26 by 0、P25 by 0, The output Y4 by 0, Re pass 74HC02 chip , take Y4 by 0 Input , be Y4C Output is 1. Re pass P0 by 0xfe namely Q8-Q1, by 1111 1110, control L1 bright . Can also order P0 by 0x00 namely Q8-Q1, by 0000 0000, control L1~L8 On at the same time .

LED Control step decomposition :
Step one :
from CT107D Found in the schematic diagram of single chip microcomputer comprehensive training platform LED modular
 Insert picture description here
According to the schematic diagram , We can know , The anode of this group of light-emitting diodes , A high level has been given , So as long as we give a low level at the cathode , You can make the diode light up .
Did you learn 51 Our friends all know , To give a low level , We just need to make IO The mouth is 0, That's all right. . namely

P0 = 0x00; // Light all LED

But what? , This board , You directly ordered P0 The mouth is 0, It cannot be lit IO Oral . stay P0 There is a chip between the port and the LED 74HC573( Latch ). Module detailed view Blue Bridge Cup Guoxin Changtian MCU – A detailed explanation of the schematic diagram ( Four )
Step two :
There is... On the board 4 slice 74HC573 chip , Enable one Y4C port ( Setting high level can control the chip ), utilize 138 The decoder sets the high and low level of the port .
 Insert picture description here
 Insert picture description here
 Insert picture description here

138 The function of the decoder here is to use P25,P26,P27, That is to say P2 The upper three digits of the mouth control the selected position .
 Insert picture description here

Can make P27-p25 Zero clearing , Reorientation Y4C operation

P2 = P2 & 0x1F | 0x80; //P27-p25  Zero clearing , Reorientation Y4C
P2 &= 0x1F;            //P27-p25  Zero clearing 

IO Programming lights up LED The core code is as follows :

P2 = ((P2&0x1F)|0x80);
P0 = 0x00; // Light all LED
P2 = P2 & 0x1F;

Case study :
LED flashing

#include "reg52.h" // Definition 51 MCU special function register 

// The time delay function 
void delay(void)
{
    
    unsigned char i,j,k;
    for(i=0; i<20; i++)
    {
    
        for(j=0; j<20; j++)
        {
    
            for(k=0; k<248; k++);
        }
    }
}
// The main function 
void main(void)
{
    
    while(1)
    {
    
        P2 = ((P2&0x1f)|0x80);
        P0 = 0xff;  //LED Extinguish 
        P2 &= 0x1f;
        delay();

        P2 = ((P2&0x1f)|0x80);
        P0 = 0x00;  //LED Lighten up 
        P2 &= 0x1f;
        delay();
    }
}
原网站

版权声明
本文为[C don't laugh]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202142256052316.html