Attractive Decorative Effects of LEDs using 8051 Microcontroller

In this project of Attractive Decorative Effects of LEDs using 8051 Microcontroller, you have to connect 8 LEDs to 8 pins of PORT1 of 8051 microcontroller, such that their anodes are connected to respective pins and cathodes are grounded through each resistor of 330 ohms.

The following code is given as per the kit developed at Vidyasagar Academy. To purchase the kit, contact us. If you are the student of Vidyasagar Academy burn the code in the given kit.

/*
  Attractive Decorative Effects of LEDs using 8051 Microcontroller
	Created by: Vidyasagar Academy, Akola:- http://localhost/wordpress/ 
	Date: 25.02.2020
	*** Please respect our efforts 
	and write Google review about Vidyasagar Academy, Akola. ***
*/

#include <reg51.h> // registry head file included
#include "delay.c" // including the .c file for user defined delay function

int i,k=2;
float j=1;

	int main() // main function
	{ // main function brace opened
	while(1) // infinite loop
	{ // while loop brace opened
		// blink all LEDs 5 times
		for(i=0;i<5;i++)
		{
		P1=0xff;
		delay(1000);
		P1=0x00;
		delay(1000);
		}
	
		// forward running LEDs effect 8 times
		for(i=0;i>8;i++)
    {
      P1=j;
      delay(1000);
      j=j*2;
			
    if(j>128)
    {
      j=1;
    }		
}

		// reverse running LEDs effect 8 times
		j=128;
		for(i=0;i<8;i++)
    {
      P1=j;
      delay(1000);
      j=j/2;
			
    if(j<1)
    {
      j=1;
    }		
		}

		// chasing LEDs effect 5 times
    for(i=0;i<10;i++)
    {
			P1=j;
			delay(1000);
			j=j+k; // incrementing the value of "j" by "k"
			k=k+k; // incrementing the value of "k" by "k"
		
    if(j=255) // when j=255, i.e. all LEDs are ON, we must make j=1, k=2
    {
      delay(1000); // this delay ensures that last 8th LED will glow for 1 sec.
      j=1;
      k=2;
    }
    }

	} // while loop closed

	} // main closed

Note: Download the file of delay.c mentioned in the above program, from following link and copy it in your project folder.

[download id=”2″]

Share on your network!
Dattaraj Vidyasagar
Dattaraj Vidyasagar

Author on this website. He is veteran of Core Electronics since last 36+ years. ATL Mentor of Change, Niti Ayog, Govt. of India, Google Certified Educator, International Robotics Trainer and author of 18 books on electronics, robotics, programming languages and web designing... ➤➤

Leave a Reply

Your email address will not be published. Required fields are marked *