8051 Based LED Blinking program

The first thing we do when we bought a new development board is running the Blinking LED program. In this blog we will see how to blink the LED. Actually we blink a full port, so that means we will be switching on/off 8 LEDs. If you want to know how to create a project in keil for 8051 see this, for loading hex file to the controller see this.

To control the port , we can just write the required level (0 or 1) to the corresponding port register directly as shown below.


/*
Blinking LED program

Connect LED's to PORT 2
*/
#include <reg51.h>

void delay(int d){
int i,j;
for(i=0;i<d;i++){
  for(j=0;j<256;j++);
  }
}

int main(){
P2=0x00;
while(1){
  P2=0xFF;
  delay(1000);
  P2=0x00;
  delay(1000);
 }
}

Tags:,

Add a Comment

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