How to program for 8051 microcontroller

August 31, 2011 — 119 Comments

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

sbit en=P0^0;
void delay();
void delay()
    int i,j;

        en = 0;
        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.



119 responses to How to program for 8051 microcontroller

  1. I have noticed you don’t monetize, 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

  2. This text is worth everyone’s attention. Where can I
    find out more?

  3. Luca Mannella July 4, 2018 at 10:31 pm

    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!


  4. why void delay function is usedfor two times


  6. 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 ?

  7. sir how to do program in 8051 microcontroller for solar grass cuter

  8. please give me the embedded c program for detection of fault in underground cable using 8051 microcontroller

  9. 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

  10. 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

  11. gaurav upadhyay March 17, 2016 at 4:42 pm

    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 ???

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

  13. 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.


    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) {

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

    if(!(–counter)) {

    void main(void) {
    while(1) {

    if (switcher) {

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


    } } } } }

  14. sir,
    do you have tutorial for save the recorded in camera (codings embeded).

  15. 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

  16. 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…..

  17. hi i am a 11th std student very must interested in embedded system i can’t understand the following things:
    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?

  18. 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.

  19. 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

  20. 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.

  21. 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

  22. 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.

  23. 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

  24. 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..

    • 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.

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

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

  27. 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

    • Hozefa kanchwala November 11, 2014 at 3:10 pm

      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.

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

  29. sir…i hav a kit 8051 with RS232..keil software…suggest me projects with it

  30. i just start now learning embedded c,please give a reference books for learn embedded c.please reply me as soon as possible.

    • 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

  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

    • 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. .

  32. please tell me how to burn code into the 8051 microcontroller chip.

  33. 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?

  34. AT 89C51 how to program,i want control of 24vDC 8 value controlling

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

  36. 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………..

  37. hello sir my name is chandru plz send 8051 microcontroler program for wirless led display using gsm modem

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

  39. 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 ….

    • 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

  40. 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… i need to show a demo storing of even 5mb video of any resolution is acceptable……….

  41. how can i learn to write a program code own for micro controller

  42. 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 graduate ….and I know the programming of microprocessor 8052.. by kit….

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

  43. Hey, the only thing happens is that stays on the whole time, but it doesn’t blink.

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

  45. 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

    • Try evaluation version by providing contact information on Keil website

      • 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

      • 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?

      • 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…

  46. how to generate hex file using Keil Uvison?

    • 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

    • 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

  47. 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
    . Thanking you in advance…

  48. 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!

  49. sir i need to know how to program a tilt sensor in 8051 microcontroller…..

  50. 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.

  51. Palash Chakraborty September 2, 2013 at 12:50 am

    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.

    • 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

  52. 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.

  53. 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

  54. hi,i would like to know how to burn program into rom of mc.

  55. sir,how to compile a program in microcontroller 8051

    • 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.

  56. 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?

  57. Himanshu singh July 20, 2013 at 10:36 am

    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.

  58. 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?
    Navin Datt

    • 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).


  59. everything worked but when pressed create hex file then nothing happened..
    why is this so?

  60. 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 ?

  61. sir can you pls send me at89c51 programming kit circuit diagram cause i want to make it ……pls send me on my email address thank you…….. May 15, 2013 at 11:12 pm

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

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

  63. Hi….I m using BASCOM for programming ….how i can burn the program to the micro-controller…….

  64. 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.

  65. harold macaranas February 26, 2013 at 2:54 pm

    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..

  66. sir, i m 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

    • 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.

      • harold macaranas February 26, 2013 at 6:21 pm

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

        • 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.

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

  67. 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..

    • 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.

  68. 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

  69. 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?

  70. 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

  71. Where can i find the next article ? Please send or post a link ! i need it urgently ! Thank you !

  72. patel manoj j July 9, 2012 at 11:18 am


  73. 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 ?

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

    • 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.

    • Hi sanket. There is a downloader for the program. You can make it by own.

Trackbacks and Pingbacks:

  1. 8051 Microcontroller - Programming Tutorials, Simulators, Compilers and Programmers - April 5, 2013

    […] How to Program For 8051 Microcontroller – short tutorial with tools and steps to program the microcontroller in order to blink an LED. The tutorial can be useful for beginners. […]

Leave a Reply

Text formatting is available via select HTML. <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>