How to create and burn HEX file for 8051 microcontroller in keil:
Hello friends, today I am going to tell you how to create a microcontroller program file (.HEX format) and how to burn HEX program file in our 8051 microcontroller for any desired project.
Let me tell you one thing in this tutorial I am not going to learn you ‘C’ program, I am just telling you how to create and burn .hex program file in a 8051 microcontroller (assuming that you have c program with you).
For programming a microcontroller we are going to use one of the best microcontroller programming software called “Keil”. Using this software you can compile your ‘C’ program and can check is their any errors in your program or not. After removing all errors (if any), you can create program file also known as .hex file which we are going to use for our microcontroller programming.
So let us learn – How to create a hex file for 8051 microcontroller using Keil software step by step:
(Before proceeding to our main tutorial make sure that you have your c program file (.c format or in word document), which we are going to convert into .hex file using ‘Keil’ software)
Step 2: Open the Keil software, you will see following window.
Step 3: Now be ready for your first microcontroller project using keil software. Now we are going to do our new project, this can be done by by using following steps:
- Click on ‘Project’ then ‘New project’. A new window will appear on the screen (Create new project). Simply type your project name (in my case it is ‘my first keil project’) and click ‘Save’.
- When you click on save button, a new window will appear (Select Device for Target ‘Target 1’) here we are required to tell – which microcontroller we are going to use? (For example, if we are using famous 8051 family or AT89C51, then double click on ‘Atmel’ here you will see all the microcontrollers made by ‘Atmel’. Click on any one (in my case it is AT89C51) which you are going to program). Then click on OK.
- After that another window will appear asking for “Copy Standard 8051 Startup Code to Project Folder and Add File to Project?” Click on ‘yes’.
If you observe ‘Project workspace’ which is located at the left side, you will see ‘STARTUP.A51’ file is their. It means it is the file which contains the assembly language commands of 8051 microcontroller.
Step 4: Now we are required to configure option value of our microcontroller project. For doing this click on ‘Project’ then “Option for Target ‘Target 1’”.
- Select Tab of Target to configure value of MCU Target as : Configure X-TAL to be 12 MHz (which is initially 24 MHz)
- Select Tab of Output and click on checkbox of “Create HEX file”. Click OK.
Step 5: Now we are ready for writing a first C program.
- Click on ‘File’ and then click on ‘New’. A new window will appear in which we are going to write our C program. If you already have, simply paste it in this window. After completing your C program click on ‘File’ and then ‘Save’ (Shortcut ‘Ctrl+S’) . We are required to save this file with extension ‘.c’ Don’t forgot to write .c after name of c program. Figure is shown below:
- Add Files into Project File, click command Project ? Components, Environment, Books…, select Tab Project Components and then select desired Add File to add into Project File.
- In the first time, we must select Files of type to be “C Source files (*.c)” and it will display Files name that is C Language Source Code. Click icon of File named “my first keil project.c” and then click Add then close then OK.
- Now if there is ‘my first keil project.c’ file present in the Project workspace which is at upper left of the screen, you are on your way!
Step 6: Now this is our last step of this tutorial. Here in the last step we are going to check is everything is fine without errors or not. We are checking our c program and converting it into hex file. So for doing this click on ‘Project’ and then click on ‘Rebuild all target files’ (There is also shortcut for this command on upper left). So when you click on this button you will see that your program is being compiled. If there is massage like “my first keil project” – 0 Error(s), 0 Warning(s)”. it means you have not any errors in your program and you can use its HEX file for your microcontroller.
Now close the software and open the directory where you save your project. Generally it is in (C:KeilC51Examples……). So there is one file containing .hex format this is your program file. You can burn this program in your microcontroller using microcontroller kit.
tags: how to program a 8051 microcontroller. how to write a program for 8051 microcontroller. keil – microcontroller programming software. step by step tutorial for programming a microcontroller. How to burn program in a 8051 microcontroller. How to create hex file in keil software for 8051 microcontroller.
If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!