8051 LED Interfacing with Delay

Home » Blog » 8051 LED Interfacing with Delay

8051 LED Interfacing with Delay

In this tutorial we learn about how the 8051 LED interfacing with delay generation is done . Time delay generation in 8051 architecture is done by the two methods.

  1. Using a simple loop logic
  2. Using internal timer register

Programming Example 1

1.  Write an embedded C program to continuous flashing the LED connected to port 2.

Algorithm:

  • Include the preprocessor directive <reg51.h>
  • Make a delay function with void type and an integer type argument ‘a’.
  • Declare variable ‘i’ with integer type.
  • Start a loop for (i=1; i<a; i++)
  • Start main function with void return type.
  • Start while loop “while(1)”.
  • P2=0xff, i.e…P2 is ON.
  • Call delay function “delay(1000)” i.e >>delay of 1000 micro sec.
  • P2=0x00; i.e…P2 is OFF.
  • Call delay function “delay(1000);
  • End loop.
  • End main.

Program

 

#include<reg51.h>
void delay(int a) //function for delay generation
{
int i;
for(i=1;i<a;i++); //delay through the continuous counting of a number
}
void main()
{
while(1) // logic to run program infinite time
{
P2=0xff; //make the all port high
delay(1000);
P2=0x00; //make the all logic low
delay(1000);
}
}

 

 

Programming Example 2.

2. Write an embedded C program to continuous toggle the LED connected to port 2.

Algorithm:

  • Include the preprocessor directive <reg51.h>
  • Make a delay function with void type and an integer type argument ‘a’.
  • Declare variable ‘i’ with integer type.
  • Start a loop for (i=1; i<a; i++)
  • Start main function with void return type.
  • Start while loop “while(1)”.
  • P2=0x55, i.e…P2 is ON.
  • Call delay function “delay(1000)” i.e >>delay of 1000 micro sec.
  • P2=0xaa; i.e…P2 is OFF.
  • Call delay function “delay(1000);
  • End loop.
  • End main.

Program

 

#include<reg51.h>
void delay(int a) //function for delay generation
{
int i;
for(i=1;i<a;i++);
}
void main()
{
while(1) //logic to run program infinite times
{
P2=0x55; //make the all odd led high and even led low
delay(1000);
P2=0xaa; //make the all even led high and odd led low
delay(1000);
}
}

 

Programming Example 3.

3. Write an embedded  C program to generate a striking pattern connected to port 2

Algorithm:

  • Include the preprocessor directive <reg51.h>
  • Make a delay function with void type.
  • Declare variable ‘i’ with integer type.
  • Start a loop for (i=1;i<a;i++)
  • Start main function with void return type
  • Start while loop “while(1)”> always true.
  • P2=0x81, i.e…P2 is ON.
  • Call delay function “delay(1000)”;
  • P2=0x42, i.e…P2 is ON.
  • Call delay function “delay(1000)”;
  • P2=0x24, i.e…P2 is ON.
  • Call delay function “delay(1000)”;
  • P2=0x18, i.e…P2 is ON.
  • Call delay function “delay(1000)”;
  • P2=0x18, i.e…P2 is ON.
  • Call delay function “delay(1000)”;
  • P2=0x24, i.e…P2 is ON.
  • Call delay function “delay(1000)”;
  • P2=0x42, i.e…P2 is ON.
  • Call delay function “delay(1000)”;
  • P2=0x81, i.e…P2 is ON.
  • Call delay function “delay(1000)”;
  • End loop.
  • End main.

Observation : In this observed pattern is of dancing led’s or striking led. In this with use of eight led we will have a pattern that LED (D1) flash first then flashing goes to d4 led and on other side d8 led flash and goes to d5 this process it repeated again and again and shows a dancing pattern.

2022-09-10T11:13:07+00:00

In this tutorial we learn about how the 8051 LED interfacing with delay generation is done . Time delay generation in 8051 architecture is done by the two methods.

  1. Using a simple loop logic
  2. Using internal timer register

Programming Example 1

1.  Write an embedded C program to continuous flashing the LED connected to port 2.

Algorithm:

  • Include the preprocessor directive <reg51.h>
  • Make a delay function with void type and an integer type argument ‘a’.
  • Declare variable ‘i’ with integer type.
  • Start a loop for (i=1; i<a; i++)
  • Start main function with void return type.
  • Start while loop “while(1)”.
  • P2=0xff, i.e…P2 is ON.
  • Call delay function “delay(1000)” i.e >>delay of 1000 micro sec.
  • P2=0x00; i.e…P2 is OFF.
  • Call delay function “delay(1000);
  • End loop.
  • End main.

Program



 

Programming Example 2.

2. Write an embedded C program to continuous toggle the LED connected to port 2.

Algorithm:

  • Include the preprocessor directive <reg51.h>
  • Make a delay function with void type and an integer type argument ‘a’.
  • Declare variable ‘i’ with integer type.
  • Start a loop for (i=1; i<a; i++)
  • Start main function with void return type.
  • Start while loop “while(1)”.
  • P2=0x55, i.e…P2 is ON.
  • Call delay function “delay(1000)” i.e >>delay of 1000 micro sec.
  • P2=0xaa; i.e…P2 is OFF.
  • Call delay function “delay(1000);
  • End loop.
  • End main.

Program

Programming Example 3.

3. Write an embedded  C program to generate a striking pattern connected to port 2

Algorithm:

  • Include the preprocessor directive <reg51.h>
  • Make a delay function with void type.
  • Declare variable ‘i’ with integer type.

  • Start a loop for (i=1;i<a;i++)

  • Start main function with void return type

  • Start while loop “while(1)”> always true.

  • P2=0x81, i.e…P2 is ON.

  • Call delay function “delay(1000)”;

  • P2=0x42, i.e…P2 is ON.

  • Call delay function “delay(1000)”;

  • P2=0x24, i.e…P2 is ON.

  • Call delay function “delay(1000)”;

  • P2=0x18, i.e…P2 is ON.

  • Call delay function “delay(1000)”;

  • P2=0x18, i.e…P2 is ON.

  • Call delay function “delay(1000)”;

  • P2=0x24, i.e…P2 is ON.

  • Call delay function “delay(1000)”;

  • P2=0x42, i.e…P2 is ON.

  • Call delay function “delay(1000)”;

  • P2=0x81, i.e…P2 is ON.

  • Call delay function “delay(1000)”;

  • End loop.

  • End main.

Observation : In this observed pattern is of dancing led’s or striking led. In this with use of eight led we will have a pattern that LED (D1) flash first then flashing goes to d4 led and on other side d8 led flash and goes to d5 this process it repeated again and again and shows a dancing pattern.

Program

2017-04-18T16:56:26+00:00

New Courses

Contact Info

193B/2, 9th Street, Indirapriyadharshini Nagar, Perumbakkam, Chennai - 600100

Phone: 9350056982

Mobile: 9350056982

Fax: 458 761-9562

Web: EdITS WORLD

Recent Posts

Go to Top