Getting Started with Programming 8051 using Embedded C !
- Suraj Borate
- May 3, 2018
- 2 min read

1.What are Pre-requisites before Starting with 8051?
those who wants more details about 8051 they may refer this datasheet
2. How to start ?
Open the keil Software.
Make all necessary configurations as shown in Video.(Remember all configurations must be made properly before we should start.)
And there you go You are ready to Write the code for 8051.
Lets Start With Basic Example of Led blink using 8051.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <reg51.h> void delay() {int i,j; for(i=0;i<100;i++)
for(j=0;j<100;j++);
} main() {while(1) { P1=0X00; delay(); P1=0XFF; delay(); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
For testing the code just copy the code and paste it to your keil window and build the project.
//////////////////////////////
Now we will be analysing anove code step by step:
line 1:
#include <reg51.h>
this is the header file of our microcontroller 8051 which contains all the instructions which we are going to use.
this is the most important line of code if you missed it project will not be executed.
line 3:
main() {while(1) { P1=0X00; delay(); P1=0XFF; delay(); } }
This is the main function. Dont worry about 2nd line we will cover it after this main function so that it will be easy to understand.
main function is totally responsible for sequential execution of our project.
There is a while loop inside it which is always true which implies that the loop will keep on executing for infinite number of times.
below this line there is word named as 'P1' which tells the 8051 to choose port 1 and send the all low signals to that port. i.e (00000000) this binary number can be written in hexadecimal form as (0x00). The last two digits in hexadecimal system are equivalet to 8 digits in binary system. this signal cuts off the led.
Now the name delay() tells microcontroller to wait for specified time untill it executes next command.
same pattern follows for (0xFF) and delay() after it the only difference is the signal to port this time is high which means that led will glow this time.
This process of making led on and off will be performed by 8051 for infinite number of times because of while loop present in it.
line 2: Now we can easily understand what the delay function was? Now we are aware about its work in code so lets just analyse its syntax.
Basically here we used two integers i and j which are inserted in for loop which means that 8051 will execute the loop 200 times untill next condition is going to be false.
In short 8051 will stuck over there untill that task is completed and then it will jump to next sequential instruction.
///////////////////////
So Guys this is it for todays blog. We hope you enjoyed it with direct practical approach instead of mugging up theory.
Ask in comment section if you have any queries.
Comments