How to program for 8051 microcontroller

Tools you need for writing 8051 micro controller:

Here are the some of tools used for 8051 microcontroller programming and simulation

  • A51-Assembler
  • Code editor -Syntax highlighting Notepad.
  • Simulator-windows based Smart n Small Simulator.
  • Baud -Timer value calculators for various baud rates.
  • C compiler for 8051.
  • RIDE software – simulation Click here
  • Keil uVision – 8051/ARM simulation Click here (most preferred)
  • Proteus – Fully embedded simulation software  Click here


Here we will work on Keil Uvison4 simulation software to make our simulation before burning program into 8051 chip.

  • Install sofware on your system
  • Click Project -> New Uvision Project
  • Save your project
  • Select Target Device (8051 – AT89s51)
  • File -> New

New text-editior will be opened. Here you need to write your code:

In this tutorial we will see blink LED program as beginners

#include<reg52.h>
sbit en=P0^0;
void delay();
void delay()
{
    int i,j;
    for(i=0;i<1000;i++)
	for(j=0;j<500;j++);
}

main(){
    while(1){
        delay();
        en = 0;
        delay();
        en = 1;
    }
}


LED will get ON/OFF depending on delay function as specified in the about program

After typing this program save this file (with file extension *.c).
Right click source Group add files to source group. Choose your saved file wit extension “.c”.
After adding your code file to source group.
Go to “project” menu click “Build Target”
You should get zero errors after compile it.
Once you done with your compilation click “Debug” Menu click “Run”

Now your simulation will run where you can see the port0 which will be blinked depending on delay specified in your code.

Thats it!! You’re done with your simulation. In next article article will teach you how to burn code into the 8051 microcontroller chip. Please make your doubts in the comments section.

About Jagadesh Boopathi

I am tech savy spending more time on technology, learning about web, making time to find new stuff always. Also I am Entrepreneur, Blogger and an Engineer. Open Source - Matters.

View all posts by Jagadesh Boopathi →

119 Comments on “How to program for 8051 microcontroller”

  1. How to burn the hex file in the microcontroller. Any circuit diagram For programmer for AT89C51 microcontroller please tell me……..

    1. HI Sanket, You will be having mircocontroller AT89C series burning kit for to burn the hex file to your microcontroller. You can burn using the kit.. If you need to design own means kit you should go for AT89S series microcontroller, kit can be designed in home itself using Parallel port connection.

  2. i have an 8051 kit which comes with atmega16 , a serial rs232 port with max 232 ic and necessary connections for Vcc , gnd and oscillator . How do i burn hex code into mCU using this rs232 port , i use keil uVision4 for simulation and creating hex files . Do i need other softwares for dumping the code ?

  3. can u pls specify me a software name to dump a program in 8051.i have the kit but i dint get the cd along with it

  4. I have a AT168 development board (Arduino Uno). I want to program a AT89C2051 micro-controller using that board. And burn the code using Keil into it. Is this possible?

  5. i am a student ,abhishek.i am working on project rf remote controle robote car using ic at89c2051how to burn the hex code on ic if i dont have any kit ………..what would i require to do so……i need to know is there any module using that i can burn an ic .is there if it is please tell me ……..and send me your email id so i can contact u for guidence as i am new family member of micro family

    1. Hi Abhishkek.. Are you sure wanna use AT89C2051? You can use AT89SXX series controllers which will come with ISP (In-system programming) which do not require any kit to burn the IC. Because AT89C2051 does not have ISP functionality.

      AT89CXX and AT89SXX will have similar functions.

      Here is the link for Burning code on controller without using any kit on AT89SXX series:

      http://ece.jagansindia.in/2012/01/isp-programming-kit-for-at89s952-and-avr-seires/

  6. Hi, I am a student doing a project using AT89C2051. Please tell me which programmer (software + hardware kit) is required for burning the hex files in the AT89C2051.. Please tell about AT89C2051 only..

    1. Hi Shubham, Get it touch with the electronics shop where you bought the AT89C2051 microcontroller chip. They will be able to provide the hardware burning kit and software in the package.

  7. sir, i m b.tech student & working on 8051 project. i want to known that how can i loaded microcontroller with my program. which type of hardware & software need for this

    1. What your microcontroller series? Its AT89CXX or AT89SXX series? If AT89CXX series you need to buy programmer of AT89CXX series. If you want built own kit then you can go AT89SXX series controllers.

      1. how can i used the alexan atmel 89cx051 programmer?can i need a software to used that prommer sir please help…..

        1. Yes You need the software which is compatible for your 89cx051 programmer. Once the software you need to find your controller and select the HEX file. Once the HEX file selected click burn/write button and wait to get it completed. Then you’re done. After burning controller test it with your kit.

      2. Is there need of any type of software to burn program in AT89SXX or AT89CXX. Which circuit is capable for my own kit

  8. hi i have alexan 89cx051 programmer but i dont have any idea how to use it to burn an hex file into atmel 89c2051 please help me..

  9. Hi Jagan! Good explanation. I would like to get an idea about the coding for various projects. So, I am expecting few more this kind of posts from you.

  10. hi jagan sir,
    I have hex file for AT89C2051. How can I check that my program will run on microcontroller.

  11. sir can you pls send me at89c51 programming kit circuit diagram cause i want to make it ......pls send me on my email address :vairagijayesh@gmail.com thank you........ says:

    sir can you pls send me at89c51 programming kit circuit diagram cause i want to make it ……pls send me on my email address :vairagijayesh@gmail.com thank you……..

  12. i am a student from sierra leone. I want to design an auto intensity street light control sytem. But from research, it it advisable to use an 8051 microcontroller with a keil compiler. But am having problem getting these items in my country. I want to order them, but honestly i having being seaching and reading a lot. I need a complete kit to do that project. From my own undastanding i no i need an AT89CXX series and a keil compiler software. But i just cant figure d hardware programmer to use inorder to programme d microcontroller. Can you please help me with all the details of what i should get to do the project. Can i also use a PIC to do it ?

  13. Hello Sir,
    Pl. help me. I’m new to microcontrollers. & To start, U hv given the following list of things that are needed:-
    [A51-Assembler; Code editor; Simulator ; Baud ;C compiler for 8051;
    Then U give :- RIDE software; simulation ; Keil uVision – 8051/ARM simulation; Proteus – Fully embedded simulation software.]
    …Now, I understand that, I hv to download only the three software given at end of the above list, which will include all the above things like AS1, Simulator etc.,?
    But the download site has many options. It is v. confusing for a beginner, as to what to download? Can u give me a guide & steps to download these softwares? Hv U given links in ur tutorial which can show me the STEPS required to be able to download these softwares?
    Thanks,
    Regards,
    Navin Datt

    1. Hi Navin,

      Download C51 Version of Keil uVision – 8051/ARM simulation from the above steps. That will be useful for your coding, compilation and simulation of controller projects (To test the output of ports without hardware based on your program).

      Regards,
      Jagan

  14. Hi.. I wana to get perfection in coding for controller so help me out. For more now i’m working on 8051 microcontroller.
    please tell the websites which provide codes for several- led,dc motor,stepper motor etc….
    Also suggest some points how yo improve coding.

  15. I am just a beginner . I dnt know how to program a micro controller. Can you suggest me a website/book through which i can study how to use a microcontroller?

    1. You need to compile using Uvision software. Write your program in Uvision and compile on the software which will give you HEX file as output. This HEX file will be used for burning the code into microcontroller using kit.

  16. I want tu use a microcontroller as a transmitter and a receiver…. is tis possible? Am a beginner… if possible i want tu know if there r any programs for tat? Can u pls help me wit it? its a little urgent pls

  17. I am a third yr student of electrical engg. I don’t know anything about microcontroller, please tell me things I required to control motion of dc motor.

  18. Hi Jagadesh,
    I want to burn a hex code into ATMEGA32 micro-controller. Can u please tell me what would be the best hardware to burn it. Please suggest me some name. Also please tell me how many times i can burn the hex code into the same micro-controller.

    1. Just ask for ATMEGA Programmer kit in market. They will give you hardware it costs around Rs.1200 to 2000 depends on market. You can burn hex codes based on erase cycle times specified on your microcontroller datasheet. Approx 10000 times. For accurate information, please verify the datasheet. Thanks

  19. hey Jagan,

    I want to display P C M E
    12 11 10 09
    K H E C
    05 06 07 08
    My LEd Matrix is 16*12,i am using MSP430G2231 Launchpad.
    Can you help me out.
    it has a delay of 3 hrs after three 3hrs in place of P C M E we get K H E C….
    and after 24hrs we get this thinng C M E P
    11 10 09 12
    H E C K
    06 07 08 05

    will be displaying.
    The crystal freq is 32Mhz.

      1. PLZ, HELP mr.Jagan i download a software of keil c51 and i install it but it was a evaluation version i want to get license number i did not have PSN number of keil software , anybody know please help from where i get product serial code of keil

      2. mr jagan give me a source a contact who is dealing with microcontroler 89s52
        at west bengal ,dist-burdwan, durgapur,bidhannagar

  20. Hello!

    I’m new with this controller. I have to complete a project at school using it. My problem is that I can only use assembly language. Can you help me out with some links? I googled but couldn’t find usefull stuff for beginners and the time is running. Many thanks and greetings from Hungary!

  21. Hi jagadesh! I badly need your help very fast.. I’m doing a project( Contactless digital tachometer using 8051 micro controller) on AT89S51. I just don’t know how to dump program into that microcontroller. I please request you to suggest the software as well as software dumping hardware like pocket avr programmer or usb tinyISP and also please give procedure or instructions to dump into that microcontroller. You can have a look on my project in http://www.circuitstoday.com.
    . Thanking you in advance…

    1. PLZ, HELP i download a software of keil c51 and i install it but it was a evaluation version i want to get license number i did not have PSN number of keil software , anybody know please help from where i get product serial code of keil

    2. Go to “project” menu click “Build Target”
      You should get zero errors after compile it.
      Once you done with your compilation click “Debug” Menu click “Run”

      Check for Hex file

  22. PLZ, HELP mr.Jagan i download a software of keil c51 and i install it but it was a evaluation version i want to get license number i did not have PSN number of keil software , anybody know please help from where i get product serial code of keil

      1. hello sir,
        i need your contact
        your mail ID and contact number will be very helpful for me
        i am a ECE student from trichy tamilnadu
        seeking for you reply soon thanks in advance

      2. I am just a beginner . I dnt know how to program a micro controller. Can you suggest me a website/book through which i can study how to use a microcontroller?

      3. please help me mr.jagan i am doing project on auto intensity street light controller but i have some problem with to write a programm can u help me…

  23. my project is bluetooth controlled home automation by using android application….so help in coding my microcontroller…….i am thnkful to u

  24. I want to learn programming micro-controller 8051. I am a hobbysist .
    I like to make electronics projects….

    please tell me how I can learn this. I am a B.sc graduate ….and I know the programming of microprocessor 8052.. by kit….

    so please tell me the steps that how can I learn programming uc8051….

    1. I want to practice at home, by my own burning kit…..please help me …

      Please tell me the steps…for that…..

  25. hi this is vinay, im working on a project of security system using at89c51 i want to use a simple camera, which should start recording on opening a door or when a security is breached,please suggest me which cam and microcontroller, should i use and how to process and store the video in memory i dont know any thing about camera,microcontroller interfacing,and storing…..as i need to show a demo storing of even 5mb video of any resolution is acceptable……….

  26. sir,i am doing project on embedded systems and i did not know how to write program for” speed checker to detect rash driving on highways using microcontroller AT89S52″.
    plz help me ….

    1. Install two ir sensor a part frome some distance.
      and use first sensor to trigger the timer of microcontroller and
      use second sensor to stop the timer of micro controller.
      now you can easily calculate speed by = distance between two sensor / timer value

  27. hello jagan iwant the program of embedded c or assembly language for speed checker to detect rash driving on highways using microcontroller at89s52 plz

  28. sir can u tell me that is c and c++ is sufficient for microcontrollar coding or i need to learn assembly language for that specially………..

  29. I need the program of RFID Based Security System Project .Can you please tell me the link where i get the program.

  30. Hi Jagan
    I am enthusiastic to learn about embedded systems.Can you help me in learning.?
    I want to start form basics,so would you like to guide me?

  31. sir i have max 232 ic base programer , DB9 connector and usb to serial cable db9 sir my programer is not connet with pc i intall cable driver but programer is not connected and i use flash magic and sir which software use for at89s52
    thank you

    1. Actually flash magic is philips product, so only those controller made by Philips can be program through it.
      89s52 is Atmel product so check Atmel official web site and download microcontoller ISP software. .

    1. I too new for Embedded C. so if u get any materials send to my mail id it will be useful for me, because nw i am working in embedded based company

  32. i hav subjct on microcontroller but i dont understand anything not even basic so i wanna learn n know about it…plz help me..

  33. hi……… sir m a student n working on a project on auto intensity street light control ,using atmega 8 i bought a nano built in kit for atmega8 and i need to do programming regarding street light control sir can you help me in writing a program…….!!!!!!!!!!!!!!!!!!!!! i have no idea on what codeing i need to be doing

    1. Go for AVR Studio. Simulate your program in avr studio 5.2 or 6.
      Before Simulating Design a Schematic Capture of your Project on Proteus 8.2 and run your program in Schematic.

  34. i want the coding and proteus simulation of pick and place robotic arm controlled by android smart phone using blue control app.

  35. i want the coding and simulation for pick and place robotic arm controlled by android smart phone using blue control app

  36. hi,
    I am work with atmel at89c51rc2 controller but here i try to dump the programming through ISP by software of FLIP it shows an time out error i Don’t kw what to do, so please can you suggest me any solution for that..

    1. Hi, First can you check whether board/chip detected on your system on parallel port?

      Alternative way is to have 89C51 programmer board to dump your hex code on chip.

  37. sir i need to improve my both electronics hardware and software. can u suggeat any idea to improve my knowledge on both harware and software in electronics please help me .. i neeed a good guide

  38. I want to know one thing sir. Is AT89Sxx programmer is feasible for
    AT89Cxx? Or source code of AT89Sxx & AT89Cxx will
    be same for any project.
    Bcoz I m doing Automatic railway gate controller project.

  39. Dear Sir,
    With due respect I would like to express that we are pursuing our project on electronics
    as a final year B.Tech student of Electrical & Electronics Engineering. The main aim of of the
    project is to make a circuit of streetlight that glows on detecting the vehicle movement.
    The components that we are using are:
    • ATmega8 microcontroller
    • DS1307 IC
    • PIR sensor
    • LDR
    • LCD
    • LED array
    The questions that I want to ask are these:
    1.Can we use the AVR board that contains the AT mega8 microcontroller and a bread board separately for adding some of other components to that AVR board?
    2.How can we fuse our program in the AVR board containing the ATmega8 controller?
    3.Can you send a sample copy of the program that we will be using to implement the circuit?
    Waiting for your early response .

    from Subhrajit Dey

  40. i want to know that if i want to get any output from a particular port of microcontroller then should i send 0 or 1 to that port’s pin. i am using AT89S52.
    please help me.
    thank you.

  41. Dear sir,
    we are pursuing our project. we want to load program in intel p8051ah microcontroller. we found many ways to program in controller but we cant find the way. its helpful to send the programmer circuit & programming software for our required controller. kindly send to my mail id. thank you

  42. Hi Jagan,
    Do you have a tutorial on NRF24LE!? I want to learn how to send and receive a character and print it on the terminal.
    Thank you.

  43. hi i am a 11th std student very must interested in embedded system i can’t understand the following things:
    A51-Assembler
    Code editor -Syntax highlighting Notepad.
    Simulator-windows based Smart n Small Simulator.
    Baud -Timer value calculators for various baud rates.
    C compiler for 8051.
    RIDE software – simulation
    Keil uVision – 8051/ARM simulation Click here (most preferred)
    Proteus – Fully embedded simulation software 
    what does all this things refer can u show me in picture are some video plz?

  44. Sir ,
    As a collage mini project i would like to do homesecurity system using gsm(8051)
    The problem is that i have no idea about 8051 program coding….now a days i concentrated on studying 8051 …can help me..for coding program…. plz give me your whatsapp number…..

  45. good morning sir,i am finished diploma in mechatronics i have intrest to make a small robot ihave no idea choose the type microcontroller ic pls help me and guide me

  46. need to write on display (memory mapped on 0x8000 adress) ,every second only numbers in strig which are dividing with 3.

    I must use timer an counter for writing on dislpay.

    I attached code file . Something is wrong in my code ..

    If someone know, pleas help me.

    #include
    #include

    typedef unsigned char byte;

    const byte code a[5]= {9,6,5,8.12};
    sbit switcher = P2^0;
    byte counter, frequency;
    int i=0;
    int x;

    byte xdata display _at_ 0x8000; // memory mapped display

    void Inic(void) {
    EA=1;
    ET0=1;
    TMOD=1;
    TH0=0x5E;
    TL0=0xE0;
    TR0=1;
    counter=1;
    frequency=0;
    }

    void timer0(void) interrupt 1 using 2 { // TIMER initialization

    TR0=0;
    TH0=0x5E;
    TL0=0xE0;
    TR0=1;
    if(!(–counter)) {
    counter=frequency;
    display=a[i];

    void main(void) {
    Inic();
    while(1) {

    if (switcher) {

    for (i=0;i<5;i++) {
    x=a[i];
    if(x/3==0) {

    frequency=1;

    } } } } }

  47. hi sir i need a program using 8051 microcontroller for underground cable fault distance locator can u please help me.

  48. hello sir, i m a student of electronics and communication engineering. Sir, i m doing a project of vehicle based street light controller and i m using At89c51 series microcontroller. sir can u please provide the source code for this project ???

  49. i am new one with programming, as i think it is difficult for me to learn c is there any easy way to programme the micro-controller please tell me any easy way

  50. i just copy paste your LED blinking program to my simulator new file. Build project ,that found no errors. where can get output file means how will i find it is working or not?? when i give run, it is not working. kindly reply me because i am a beginner

  51. I know programming, and am good with FORTRAN, BASIC, and Pascal, and a little bit of C. I have learned use of ATmega368. How long will it take to learn 8051 ?

  52. There is an “error” in your code.
    It is not necessary to declare the prototype of the “delay” function:
    void delay();
    if you write the body of the function before the main function.

    You can remove that line and the program will work.
    The prototype declaration is useful only if you write the source code of the declared function after the main function.

    Thanks for doing this tutorial!

    Regards,
    Luca

  53. I have noticed you don’t monetize jagansindia.in, don’t waste your traffic, you
    can earn additional bucks every month with new monetization method.
    This is the best adsense alternative for any type of website
    (they approve all websites), for more details simply search
    in gooogle: murgrabia’s tools

Leave a Reply

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