Basics of 8051 Microcontroller Program in Keil Assembly language

Hii guys, I am back with some more exciting topic of Robotics. Today what I am going to discuss with you, It will make you feel genius and also it will improve your knowledge in the Robotics Field.

So Today I am going to cover the following Topics :

What are 8051 Microcontroller and Basics of 8051 Microcontroller .?
What is Embedded System.?
What is the use of Keil Assembly Language.?
How to Interface with Keil Assembly Language.?
How to program on Keil Assembly Language.?
How to convert Binary no. to Hexadecimal form using Keil Software.?
Basics programming of 8051 microcontrollers in Keil Assembly Language.
So Friend keeps concentrate your mind and starts the learning, I am going to elaborate it step by step.


 8051 Microcontroller and Basics of 8051 Microcontroller

  • 8051 Microcontroller chips are used in a wide variety area for controlling the systems, telecom applications, robotics applications, Automation Industries, Medical Industries, Advance agriculture Sector as well as in the automotive industry. By some estimations, 8051 family chips make up over 50% of the embedded microcontroller chip market. 8051 chip is economically very cheap and provides an excellent platform to work in sensitive industries. There are in the market various types of  8051 microcontroller series are available like this available according to its capacity – 8 bit, 16 bit and 32 bit.
  • The Intel MCS-51 (commonly termed 8051) is an internally Harvard architecture, complex instruction highly programmed and set computing (CISC) instruction set. The first microcontroller single chip (µC) series were developed by Intel in 1980 for use in the purpose of embedded systems and robotics fields. The First Intel’s original versions were popular in the 1980s, and very early 1990s and enhanced binary compatible, and derivatives remain popular today in the Global world.
  • MCS-51 Intel’s original family has been developed by using N-type metal-oxide-semiconductor materials (NMOS) technology like its harbinger Intel MCS-48, but on later versions, defined by a letter C in their name (e.g., 80C51) used as metal–oxide–semiconductor material (CMOS).In this technology, it consumes less power than their NMOS. Here performed is more suitable and compatible with powered battery devices.
  • The Microcontroller family was being continued in 1996 with the enhanced 8-bit MCS-151 and the 8/16/32-bit MCS-251 family of binary compatible microcontrollers, and yet this generation continues in search of extensive Technology.

8051 Hardware Structure,  Pin configuration, and its working way Let’s know it.


The 8051 microcontroller chip contains 40 pins separately whose every pin has been designed to perform individual tasks, and all these pins play a vital role to make this chip decision making by itself, and thus it finally delivers a work without any trouble.

Let’s have a look of-of 8051 Pin Description.




  • PIN P1.0-P1.7 : Port 1 contains pin 1 to pin 8.port 1 is connected at these pins. It is an 8-bit port. It can be used as an input or output port. If these pins are high, i.e., one then port 1 act as the input port, and when these pins are low, i.e., 0 then port 1 acts as the output port.
  • PIN 9 :  (reset):-This pin is used reset the controller for resetting the 8051.
  • PIN 10-17 : Port 3 is connected at these pins & it is also an 8-bit input-output port. These pins are multifunctional.
  • PIN 10 (RXD) : External serial data is received at this pin.
  • PIN 11 (TXD) :  This pin is used for transmitting serial data from microcontroller to external device.
  • PIN 12 & 13(INTO/INT1) : The external interrupts from hardware is applied through these pin.
  • PIN 14 & 15 (T0 & T1) : The input of timer and counter is applied through these pins.
  • PIN 16 (WR) : This pin enables external data to be written with data generated by hardware.
  • PIN 17(RD) : The data is read from external memory.
  • PIN 18 (XLT1,XLT2) : The external oscillator is connected to these pin for generating the internal clock signal.
    PIN 20: The pin is connected to ground.
  • PIN 21 to 28 : Port 2 is connected to this pin the output of port 2 is used to access external memory. Port 2 o/p high order byte of external memory.
  • PIN 29 (PSEN) : PSEN stands for program Store Enable. It is active low control signal used to activate the enable signal of external ROM/EPROM.
  • PIN 30(ALE) : ALE stands for Address Latch Enable. Two demultiplex AD0 to AD7 and external latch, and ALE signal of 8051 is used.
  • PIN 31 (EA) : EA stands for external access. When EA is active, all the addresses fetched by the program are given to external ROM/EPROM.
  • PIN 32 to 39 : It can be used as input-output pins.  These pins are used to access external memory. At these pins multiplex, low order address and data lines are present.
  • PIN 40 : This pin is connected to power supply +5v.


Embedded System

Charles Stark Draper devolved the first embedded system. And the mass production of the system in the year of that time all are used the embedded system, and its production is not stopping, and their uses had increased. Its size is small considerably from its monolithic ancestor. But increase other risk factors.

The embedded systems are used in a massive amount of commercial area because all the time we can’t use a computer that’s why the integration of microcontrollers has increased. The embedded system doesn’t look like a computer, but it has inbuilt processor and software. And the cost of the embedded system is very low as compared to the computer. If we want to do some new task or job than we do the job in the same embedded system. Its size is too small and no need to use extra peripherals devices like computer.

A system is a way of working one or more than one task according to a plan or program. A method is also an arrangement in which all its units assemble and work together according to the program. This system based on Embedded programming where hardware is get interfaced or communicated through the software and here the software make the embedded system sensitive to work correctly, with the help of embedded software we can program anything whatever we want in its field. ROM of the embedded system keeps the software. And it doesn’t need any secondary memory like computer hardware.



Keil Assembly Language

The Keil Assembly Language is medium to communicate to the hardware of 8051, Keil Assembly language comes under the Keil programming software, This software is mostly based on C programming so that also this is called Embedded c programming cause this is most similar to the C language. Keil Language has such a various types of features which make ready to work the 8051 chip in every suitable condition. Whenever we make a program in Keil software, we always to program in binary form but as we know, 8051 chip reads the hexadecimal form. So whenever we make the program for 8051, we always need to convert it first in hexadecimal form and then after the conversion we insert this program to the chip through the USB port of a computer.


Now lets know how to interface with keil Software

First We need to install this software on our computer if you don’t have this software.

Click here to Download Keil Software

Download this software either from this link or somewhere else, but we need to install it on the computer, and after installing the software it will make a shortcut icon on the Desktop as usual every software makes the same.


Step 1

Do double click to run the software as you will open the software it will shows many options.


Basics of 8051 Microcontroller Program in Keil Assembly language


Step 2

Take your cursor to the Project as you are seeing here into the below image then click on close Project.

Project – Close Project

Basics of 8051 Microcontroller Program in Keil Assembly language


Step 3

Now take your to the Project and then click on New micro vision Project.

Project – New micro vision Project

Basics of 8051 Microcontroller Program in Keil Assembly language


Step 4

As you will click on new micro vision project you will get the option to save File Name.

So as according to below image give its File Name Whatever name you want to give, Here I am giving its name “Led”

after inserting the name click on save button.

File Name – Save

Basics of 8051 Microcontroller Program in Keil Assembly language

Step 5

After Clicking on save button a dialog box will be as similar to below image.

Here it will ask to select Device for Target

Now we have to select the Cpu which we will use For Programming

8051 Microcontroller has various types of Microcontroller Cpu like:





ATMEL is the company who build the microcontroller chip.

So, Now here we are using Atmel – At89s52, So first we will click on Atmel and the Click on At89s52


and then click on OK button.

Basics of 8051 Microcontroller Program in Keil Assembly language


Step 6

Now as according to above instruction as you will Click on Ok  button, A dialog box will open as similar to below image.

So, now you have to click on yes.

As you will click on yes button a another dialog box will open and ask to overwrite then again you have to click on YES button.


Basics of 8051 Microcontroller Program in Keil Assembly language


Step 7

Now Take your cursor File then click on New

as you will click on New a fresh Text screen will open .

Basics of 8051 Microcontroller Program in Keil Assembly language


Step 8

Now again go to the File and click on save button.

Basics of 8051 Microcontroller Program in Keil Assembly language


Step 9

Here write the same name, What you named in Step 4

But here after giving the name you have to also include  .c

Like : Led.c , 8051.c , Enamul.c , Rahul.c etc …

so i am writing here Led.c . and then click Save button.

Basics of 8051 Microcontroller Program in Keil Assembly language

Step 10

Now take your cursor on Target 1 and Click on Target 1.

Basics of 8051 Microcontroller Program in Keil Assembly language


Step 11

As you will click on Target 1. A another box will open like below image.

Basics of 8051 Microcontroller Program in Keil Assembly language


Step 12

Now Take your cursor on Source Group 1 and do right click on it.

As you will do right click on it you will get many options like below images.

so just go down and Click on Add Files to Group Source File 1 ..


Basics of 8051 Microcontroller Program in Keil Assembly language


Step 13

As you will click on Add Files to Group Source File 1 ..  a dialog box will open and will ask to add the File name You want to add here in this source group.  then Select the same name you what you gave the name in Step 9 that is Led.c.

Select it and then Click on Add Button then Click on Close button.


Basics of 8051 Microcontroller Program in Keil Assembly language

Step 14

Now you have a Screen like this and now you are ready to Program on Keil Software.

Write the Program here Whatever program you want to write for your Microcontroller.

Basics of 8051 Microcontroller Program in Keil Assembly language


8051 Microcontroller Programming

Now Lets understand it in a more easier way.

I ma going to make a program on Led blinking Here we will control the use of led according to our need.

we can make a Dancing Led Program, Traffic Light Program, Dealy Blinking Program and many mores.

So lets Start the Program

Basics of 8051 Microcontroller Program in Keil Assembly language


Here in the above image you can see i have written a program for led blinking. so program will be like this.

As we know micro controller has divided on 4 ports that is 0,1,2,3

Here in every ports it contains 8 Pin. this pin start from 0,1,2,3,4,5,6 tp 7 .

So, Here we are programming on port 1 .

#include<regx51.h>   this is a header file of microcontroller we always use it on the top of the program whenever we write the program.

#include<delay.h> this is also a header file but we use it according to our need . Here this header file is being used to provide the delay to the output that how much delay we want to provide this has been set through the delayy header file.

void main()  After inserting all the Header file we write it and go to the main program.

{     This thing defines that we opened the bracket for program and we program under this open bracket.

p1_0==0    This one defines that we are programming on Pin 0 of Port 1 of micro controller .

delay(100)    This is define that we are using delay of 100 ms (micro second).

}    After writing the all program we close the program by giving close curl bracket.

Your program is ready now do compile it .

And now your Led Blinking Program is Complete.

Convert 8051 program on Hexadecimal form

Whenever we will write the Program after program we need to convert it on Hexadecimal form then we can load it on chip by using boot loader Hardware.

So, here lets know how to convert Keil Program on Hexadecimal Form.

Basics of 8051 Microcontroller Program in Keil Assembly language

As Here in the above image is showing an option to convert into hexadecimal form.

So firstly take your cursor to the Flash then go to the Configure Flash. As you will click on Configure flash, a option will show like this.

In this box Click on Output and then mark on Create Hex File and the Click on Ok Button.

Now you have successfully converted it to Hex File. Now load the program on-chip and Enjoy You First LEd Blinking Program on 8051 microcontrollers.


So, Friends, I hope you understand this project very well. In upcoming Tutorial,  I will be back with some new exciting Projects, and we will discuss some useful development topics. Here if you want to recommend that what I should write in upcoming Tutorial, then please leave your comments. And if u need any help or query, please don’t hesitate to discuss with me. Thank You 🙂

(Visited 2,587 times, 1 visits today)

5 thoughts on “Basics of 8051 Microcontroller Program in Keil Assembly language

    1. Hello Dear, Definitely I will help you.
      Do message me in my fb or Whatsapp for any kind of confusion.
      and please must like and share our Fb page.
      Thanq 🙂

        1. Dear aarish qureshi,

          If you want to see the output of 8051 except Proteus,then you can see its o/p on 8051 Board Directly.
          if you are a Beginner then first of all start learning on Hardware with Blinking Led Program.

          We also Provide 8051 Startup Hardware Kit With Hardware and Software Step by Step Guideline Book for Beginners.
          if you want you can also Purchase this Startup Kit It will be Perfect for you.

          If still have any doubt you can also ask me in any regard.
          You can also discuss with me your Problem by Posting your Problem on Fb Page –

          Thank you 🙂

Leave a Reply

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