8051 Led Blinking

8051 Ports

8051 has 32-gpio's grouped into 4-Ports namely P0-P3 as shown in the below table.
PORTNumber of PinsAlternative Function
P08 (P0.0-P0.7)AD0-AD7 (Address and Data bus)
P18 (P1.0-P1.7)None
P28 (P2.0-P2.7)A8-A15 (Higher Address Bus)
P38 (P3.0-P3.7)UART, Interrupts, (T0/T1)Counters

Hardware Connections

 

Program:

 


//Program by UdayaPrakashJayaraman

#include <reg51.h>

void delay(unsigned int Count)

{

unsigned int i,j;

for(i=0;i<Count;i++)

{

for(j=0;j<100;j++);

}

}

int main()

{
P2=0xff; //Default HIGH to configure pins in Negative switching

while(1)

{

P2 = 0x00; /* Turn ON all the leds connected to P2 */

delay(500);


P2 = 0x11; /* Turn OFF all the leds connected to P2 */

delay(500);

}

return (0);

}


Example 2

In this example, we will see how to access a single port pin to blink the LED.

//Program by UdayaPrakashJayaraman

#include <reg51.h>

sbit LED = P2^0; // Bling the single LED connected to P2.0


void delay(unsigned int Count)

{

unsigned int i,j;

for(i=0;i<Count;i++)

{

for(j=0;j<100;j++);

}

}


int main()

{

while(1)

{

LED = 1; /* Turn ON the LED connected to P2.0 */

delay(500);


LED = 0; /* Turn OFF the LED connected to P2.0 */

delay(500);

}

return (0);

}

Have an opinion, suggestion , question or feedback about the article let it out here!

Related Posts:

  • Keil Setup For 8051 In this tutorial we see how to setup Keil4 for generating .hex file.Keil software can be downloaded from this link.Download and install the Keil C51 for 8051. Keil Setup Steps Step1: Open the Keil software and… Read More
  • 8051 LED On OFF control with Pushbutton Hardware Connections: Push button switch is connected to the first bit of PORT 0 (P0.0) which is configured as an input pin. Which is connected to a pull up resistor as there is NO INTERNAL PULL UP RESISTORS FOR PORT… Read More
  • 8051 Led Blinking 8051 Ports 8051 has 32-gpio's grouped into 4-Ports namely P0-P3 as shown in the below table. PORTNumber of PinsAlternative Function P08 (P0.0-P0.7)AD0-AD7 (Address and Data bus) P18 (P1.0-P1.7)None P28 (P2.0-P2.7)A8-A15… Read More
  • PIC Microcontroller Software Setup MPlab In this tutorial we will see how to setup a Mplabx project to generate .hex file for Pic16f877a MPLABx Setup Steps Step1: Open the MPLABx software and select the New project from File Menu as shown below. Step2:&nbs… Read More
  • Microcontrollers - 8051 Interrupts Interrupts are the events that temporarily suspend the main program, pass the control to the external sources and execute their task. It then passes the control to the main program where it had left off. 8051 has 5 interru… Read More