51 Microcontroller LED Chaser Experiment

1. Experiment Task Achieve the effect of sequentially lighting up LED lights to create a chaser effect.2. Experiment Principle When the anode of the LED is at a high level and the cathode is at a low level, the LED will light up; by connecting multiple LEDs to the output pins of the 51 microcontroller, we can program the microcontroller to output signals of 0 or 1 to light up the corresponding LEDs, achieving the chaser effect.3. Experiment Wiring Diagram, with some circuits simplified51 Microcontroller LED Chaser ExperimentCode:

void delay(void)//Delay function   {      unsigned char i,j;       for(i=0;i<250;i++)         for(j=0;j<250;j++)           ;    }
void main(void)//Main function{   while(1)      {           P3=0xfe;   //First LED on          delay();   //Call delay function          P3=0xfd;   //Second LED on          delay();           P3=0xfb;            delay();           P3=0xf7;            delay();           P3=0xef;                delay();               P3=0xdf;                delay();               P3=0xbf;                delay();               P3=0x7f;                delay();               } }

51 Microcontroller LED Chaser Experiment

Leave a Comment