Home » Embedded Systems

8051 Microcontroller programming using Keil Uvision IDE

In this tutorial, we will learn how to do programming on an 8051 microcontroller in a stepwise manner? First, we will learn how to setup the Keil uvision IDE, then we will move on how to compile a simple C program and finally generating hex code to burn in the microcontroller?
Submitted by Sudarshan Paul, on June 17, 2018

Step 1: Download the Keil Uvision IDE

For learning purposes, you can try the evaluation version of Keil which has code limitation of 2K bytes. You must download the C51 version for programming on 8051 microcontroller architecture.

8051 Microcontroller programming using Keil Uvision IDE - download

Step 2: To initiate the programming you must create a project using the keil Uvision IDE

The option to create a new project will be available under the project tab in the toolbar. Next, you have to store the project in a folder and give a suitable name to it.

8051 Microcontroller programming using Keil Uvision IDE - create new

Step 3: Selecting the type of device you are working with

The device selection dialog provides you with the option to select the 8051 derivatives for which you want to develop the program. If you are not sure about your device you can refer to the description of the devices which is displayed on the left pane of the dialog. Accordingly, select your device and click OK to confirm.

8051 Microcontroller programming using Keil Uvision IDE - select device

Step 4: Adding C files to your project

You must add C file to your project before you begin coding. This can be done by right-clicking on your project from the project pane and selection “Add a new item to source group 1”. In the next dialog box, you will be given with the choice on what type of file you want to add such as C, C++, header, text etc. Since here we are dealing with Embedded C programming, select C File (.c) option. Provide the necessary name, location and click on add.


8051 Microcontroller programming using Keil Uvision IDE - add new c file

8051 Microcontroller programming using Keil Uvision IDE - add new c file

Step 5: Coding in C

The main part has finally arrived, so now you can go along with programming in C with your respective microcontroller.

Let's take an example of a small C program to blink the LED connected to Port 1 of 8051.

#include <reg51.h>

//delay function declaration
void delay(void);

void main(void)
{
	//an infinite loop
	while(1)
	{
		// Turn ON all LED's connected to Port1
		P1 = 0xFF; 
		delay();
		// Turn OFF all LED's connected to Port1
		P1 = 0x00; 
		delay();
	}
}

//delay function definition
void delay(void)
{
	int i,j;
	for(i=0;i<0xff;i++)
		for(j=0;j<0xff;j++);
}

Step 6 : Compiling and building the C project using Keil Uvision IDE

In order to build your recently created C program go to Project tab and click on Build Target on the menu bar. An alternate way to do this is by pressing the F7 key. If the code that you have written is correct, the code will successfully compile without any errors. You can check your output in the Build Output pane.

8051 Microcontroller programming using Keil Uvision IDE - build

8051 Microcontroller programming using Keil Uvision IDE - build output

Step 7: Generating the hex file using Keil Uvision IDE

The code you compiled cannot be directly fed to the microcontroller, it is not possible. For that purpose, you have to generate the hex code for your respective file.

In order to generate the hex code, right click on the ‘Target 1’ folder and select options for target ‘Target 1’. Select the Output tab in the target ‘Target 1’ dialog box. Make sure Create Hex File option is checked and the HEX format should be HEX-80. Click OK.

Again rebuild your project by pressing F7. Your required hex file would have been generated with the same as your project in the Objects folder.

If you wish you can also view your hex code by using a notepad.

8051 Microcontroller programming using Keil Uvision IDE - generate hex file

Step 8: Burning the hex code into 8051 microcontroller

In order to burn the hex code to your microcontroller, there are two ways which are specific to the device you are working with. Some devices, for example, P89V51 they have their own built-in bootloader and you can burn the hex code directly through the serial port. Mostly you will require a specific programmer for your 8051 microcontroller through which you can easily upload your hex code by connecting the programmer via normal USB port.

Read next: How to upload HEX code to microcontrollers?






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.