8051 Programming Using Keil UVision IDE

by xanthium-enterprises in Circuits > Microcontrollers

49156 Views, 5 Favorites, 0 Comments

8051 Programming Using Keil UVision IDE

keil-8051-8052-embedded-c-tutorial.jpg

In this short Instructable we will learn

  • How to setup the Keil uvision IDE,
  • Compile a C program
  • and generate hex code for the 8051/8052 architecture.

You can find the original article on 8051 programming using Keil uVision IDE here.

Downloading Keil UVision IDE

download-keil-uvision-ide-5-for-8051.png

Keil provides a code limited (2K bytes) evaluation version for 8051 architecture (C51) which is sufficient for learning purposes.

The main limitations of the evaluation version are the following.

  • 8051 compiler, assembler, linker, and debugger are limited to 2 Kbytes of object code
  • Programs that generate more than 2 Kbytes of object code will not compile
  • The debugger supports programs that are 2 Kbytes or smaller
  • No hardware support for multiple DPTR registers is provided

Keil uVision IDE (Evaluation Version) can be downloaded using this link.

On Clicking the above link you will be redirected to Keil Website Download section.

Please click on the C51 icon to download 8051 development tools (above Figure) .
and download your Windows Executable.

More Info here.

Creating a 8051/8052 Project Using Keil Uvision IDE

create-new-8051-keil-uvision-project.png

After you have installed the Keil uVision tools for 8051 ,Double click on the Keil icon on your Windows Desktop to launch the IDE.

To create a new 8051 project using Keil IDE, Click on the ' Project ' item on the IDE Menu bar and select ' New uVision Project... ' as shown in the above image.

Now create a Folder to store your project and give a name to your Project files (*.uvproj), for eg Test (Test.uvproj).

Selecting an 8051 Device in Keil

select-8051-derivative-kiel.png

You will then be taken to the device selection dialog, where you can select the 8051 derivative for which you want to develop software.

Keil has support for a wide variety of 8051 derivatives on its IDE.The 8051 derivatives are organised according to their manufacturer's.

On selecting the particular microcontroller the Keil IDE also displays the features of the selected microcontroller on its left pane .You can Click OK to confirm your choice.

copy-startup-a51-keil-uvision.png

After selecting your 8051 derivative,

You will get another dialog as shown Above.Asking to copy STARTUP.A51

Click ' Yes '

startup-a51-added-keil-project.png

Now your Project pane on the Kiel IDE would look something like this (above image)

Adding C Files to Keil Project

add-new-item-keil-uvision.png

Now you can add C files to you Project.

Right Click on the Source Group 1 folder on your Project pane and select Add New Item to Group 'Source Group1'...

add-c-file-keil-uvision-ide.png

Now you can select the type of file you want to add to your project using the top pane.

Select C File(.c) and give it a name (here main.c) and Click Add.

Now you can type a small program into the main.c to blink the LED's connected to Port 1 of 8051 .You can find the sourcecode below.

#include <reg51.h>
void delay(void);
 
void main(void)
{
    while(1)
    {
         P1 = 0xFF; // Turn ON all LED's connected to Port1
         delay();
         P1 = 0x00; // Turn OFF all LED's connected to Port1
         delay();
    }
}
 
void delay(void)
{
    int i,j;
    for(i=0;i<0xff;i++)
         for(j=0;j<0xff;j++);
}

Building a C Project Using Keil UVision IDE

compiling-c-file-kiel-uvision-ide.jpg

After you have typed out the above c program to your main.c file,You can compile the C file by pressing F7 key or by going to ' Project -> Build Target ' on the IDE menu bar.

keil-build-output.jpg

If there are no errors the code will compile and you can view the output on the Build Output pane.

Generating 8051 HEX File Using Kiel IDE

hex-file-creation-keil.jpg

Inorder to download the code into the 8051 microcontroller we have to generate the corresponding hex code .

In Keil uVision IDE you can generate hex file for your 8051 derivative by, Right Clicking on the ' Target 1 ' Folder and Selecting Options for Target 'Target1'....

8051-hex-file-creation.jpg

Then on the Options for Target ' Target 1' Dialog ,

Select the Output tab and check the Create Hex File option and Press OK.

Now rebuild your project by pressing F7.
Kiel IDE would generate a hex file with same name (here Test.hex) as your project in the Objects folder .

Viewing the Generated Hex File

notepad-hex-file.jpg

You can open the Test.hex file with notepad to view the contents after creation.

Downloading HEX Code Into 8051

Uploading hex code is specific to the 8051 derivative you are using.For example some microcontrollers like P89V51 and Nuvoton W78E05D have build in boot loader which can upload hex code through their serial port.

Do visit the original article here