LED running lights, the realization process from left to right

The reference for this experiment is "Teach you to learn 51 MCU (Song Xuesong)", the programming software is Keil uVision5, and the simulation software is Proteus 8 Professional.

This time, the implementation process from left to right is implemented. The next article implements the implementation process from right to left. Welcome to browse!

We know that control pin P0.0 controls DB0 through 74HC245, P0.1 controls DB1...P0.7 controls DB7. We also learned that a byte is 8 bits, if we write a P0, it represents all 8 bits from P0.0 to P0.7. pictures to illustrate

Simulation diagram:

Source code:

After creating a new 51 project, you can refer to this program. I hope you can benefit from it and use C language for programming.

reg52.h:

#include<reg52.h>
sbit LED = P0^0;
void main()
{
  LED = 0;
	while(1);

}

xx.c (xx is your filename):

#include<reg52.h>

void Delay (unsigned long nCount)
{
    for(;nCount!=0;nCount--);
}

sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;

main()
{
    unsigned int i=0;
    ENLED = 0;
    ADDR3 = 1;
    ADDR2 = 1;
    ADDR1 = 0;
    ADDR0 = 0;
  while(1){
    while(1){
    for(i=0;i<8;i++){
    Delay(5000);
    P0=~(0x01<<i);
    Delay(5000);
    
}
    
    
    for(i=0;i<8;i++){
    Delay(5000);
    P0=~(0x01<<(7-i));
    
    Delay(5000);
}
    
  }}
}

If there is a problem with your experiment, please double check your project, the code is correct.

If you want to implement the implementation process from right to left, you can read this article

LED running water lamp, the realization process from right to left - Blog Channel - PROG3.COM

Like forward comment

Guess you like

Origin blog.csdn.net/qinluyu111/article/details/123521216