Hello World Program 8051
LED blinking 8051 Family
Now let us do Hello World program for 8051 family of micro controllers. We know that in embedded world , Hello World program is LED blinking.
This program is for blinking LEDs connected to some port pin in a 8051 pin compatible package.
For doing experiment with 8051 family u need a ‘C’ cross compiler that can generate machine code for 8051 architecture. Two most popular compilers are Keil uVision & SDCC (Small device C compiler). SDCC is freeware while evaluation version of Keil uVision is free with simulation code size of limited 2K.
Schematic for which we are going to write our program
LEDs are connected in sinking mode i.e. a logic zero at corresponding pin will lite up that LED and a logic 1 will make LED lit off. It is due fact that 8051 family controllers cant provide that much source current that can drive a LED.
As shown in circuit LEDs are connected to lower nibble of PORT 1.
Here is the program…
#include<at89x52.h> // standard header file for SFR/Macro definitions of AT89S52
void delay(void) // delay function to generate time delay between two events
{
unsigned int i,j;
for(i=0;i<120;i++)
{
for(j=0;j<1300;j++);
}
}
void main(void)
{
P1=0x0F; // initially all LEDs are Off
while(1==1) // infinite loop to do a particular task infinitely
{
P1=0x00; // LEDs On
delay();
P1=0x0F; // LEDs Off 0x0Fh=0b00001111
delay();
}
}


