#

8051 MicroController

Getting Started with 8051 and Keil IDE

Introduction

8051 microcontroller can be programmed in two languages

  • Assembly language
  • C language

8051 microcontroller popular development IDE is MCU 8051 IDE and µVision to develop code.

Keil µVision IDE consists,

  • C Compiler - C51.Exe
  • Assembler - A51.Exe
  • Linker/Locator - BL51.Exe
  • Librarian - LIB51.Exe
  • Hex Converter - OH51.Exe

Let’s develop simple LED blinking program using Keil µVision IDE with C51 compiler. here we are using AT89S52 microcontroller from 8051 family.

  1. Download Keil µVision and install it.

Now open Keil µVision

open keil

 

Click on Project menu and select New µVision Project…

New Project Keil

 

“Create New Project” window will pop up, type a project name and location for project and save.

Select destination and name for new project

 

 “Select Device for Target” window will pop up, select your device (here we selecting AT89S52)

Select target device

 

“µVision” window will ask for copy STARTUP.A51 to project folder and add file to project (here it not necessary so we have selected No)

Startup file add notification

 

Now select New file from File menu and type your program code (here we have typed LED blinking program)

New file and type code

 

LED Blinking Program

#include<reg52.h> /* Include header file */

void delay(k)  /* Delay for msec. (here Xtal freq. is 11.0592 MHz) */
{
	int i,j;
	for (i=0;i<k;i++)
		for (j=0;j<112;j++);
}

void main()
{
	while(1)
		{
			P1 = 0x00;  /* Make Port 1 (P1) Low for 200 msec.*/
			delay(200);
			P1 = 0xFF;  /* Make Port 1 (P1) High for 200 msec.*/
			delay(200);
		}
}

 

Save program code with “ .c “ extension (In case if you are using assembly language then save program code with “ .asm “ extension)

Save with extension

 

Right click on Source Group 1 folder from Target 1 and select “Add existing files to Group ‘Source Group 1’”

Add existing file to source group

 

Select program file saved with “.c “or “.asm” (in case of assembly language) and add it. Then close that window. You can see added file in “Source Group 1” folder in left project window

Select file to add

 

Now select Project menu and click on “Build target”, it will build project and give status in Build output window with Error and Warning count if any.

Build target

 

To create Hex file right click on Target 1 and select Option for Target ‘Target 1’

Option for target

 

Target window will pop up, enter Xtal (MHz) frequency (here we used 11.0592 MHz) and tick mark in front of “Use On-chip ROM” tag.

Target pop up define frequency

 

Within same window select “Output” option and tick mark in front of “Create Hex File” tag and click on OK.

Create hex

 

Now again select build target from Project menu or simply hit F7 shortcut key for same, it will build target and also create Hex file. You can see creating Hex file in Build output window

Output window

 

Created Hex file is burned into microcontroller flash memory using various programming method based on programmer or programmer developed by manufacturer itself.

For example, Flash magic is used for NXP Philips microcontrollers only and is developed by NXP itself. Other manufacturers use serial programmer like ISP programmer to flash their controllers.

Now load generated Hex file in one of any programmer available and flash it in your 8051 Microcontroller.

Find below hex file snap.

Hex file


LED blinking