8051 LED Interfacing with Delay

/, Electronics, Programming 8051/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

 

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

By |2017-05-29T01:36:24+00:00April 18th, 2017|8051 Projects, Electronics, Programming 8051|0 Comments

You May Like




Author

Posted by
This author has not yet filled in any details.
So far the author has created 7 blog entries.
April 18th, 2017

Recent Posts

Categories

For You

%d bloggers like this: