Getting Started with KEIL Software

Getting started with KEIL Software

Tags: Getting Started with µVision IDE,keil tutorials,create a project in keil,debug a project in keil,keil software tutorial,
Overall rating
Introduction of KEIL

The Keil Software P89V51RD2 development tools listed below are programs you use to compile your C code, assemble your assembly source files, link and locate object modules and libraries, create HEX files, and debug your target program.

µVision for Windows™ is an Integrated Development Environment that combines project management, source code editing, and program debugging in one single, powerful environment.

The 8051 ANSI Optimizing C Compiler creates re locatable object modules from your C source code. The 8051 Macro Assembler creates re locatable object modules from your 89XX assembly source code. The Linker/Locator combines re-locatable object modules created by the Compiler and the Assembler into absolute object modules.

The Library Manager combines object modules into libraries that may be used by the linker.

The Object-HEX Converter creates Intel HEX files from absolute object modules.

µVision IDE

When you use the Keil µVision3, the project development cycle is roughly the same as it is for any other software development project.

  • Create a project, select the target chip from the device database, and configure the tool settings.
  • Create source files in C or assembly.
  • Build your application with the project manager.
  • Correct errors in source files.
  • Test the linked application.

Getting Started with µVision IDE

The µVision IDE combines project management, make facilities, source code editing, program debugging, and complete simulation in one powerful environment. The µVision development platform is easy-to-use and helping you quickly create embedded programs that work.

The µVision editor and debugger are integrated in a single application that provides a seamless embedded project development environment.

The µVision IDE combines project management, a rich-featured editor with interactive error correction, option setup, make facility, and on-line help.

Use µVision to create your source files and organize them into a project that defines your target application. MPLAB automatically compiles, assembles, and links your Embedded application and provides a single focal point for your development efforts.

Embedded application and provides a single focal point for your development efforts.

When you use the µVision, the project development cycle is roughly the same as it is for any other software development project.

  • Create a project, select the target chip from the device database, and configure the tool settings.
  • Create source files in C or assembly.
  • Build your application with the project manager.
  • Correct errors in source files.
  • Test the linked application.

C Compiler & Macro Assembler

Source files are created by the µVision IDE and are passed to the C Compiler or Macro Assembler. The compiler and assembler process source files and create re locatable object files.

The Keil µVision/8051 interfaces either to GNU or C51 ADS/Real View™ development tools. µVision/C51 contains many useful sample programs and detailed information on how to create 8051 applications using these tool chains.

Library Manager

The library manager allows you to create object library from the object files created by the compiler and assembler. Libraries are specially formatted, ordered program collections of object modules that may be used by the linker at a later time. When the linker processes a library, only those object modules in the library that are necessary to create the program are used.


The Linker/Locator creates an absolute ELF/DWARF file using the object modules extracted from libraries and those created by the compiler and assembler.

An absolute object file or module contains no re-locatable code or data. All code and data reside at fixed memory locations.

The absolute ELF/DWARF file may be used:

  • To program an Flash ROM or other memory devices,
  • With the µVision Debugger for simulation and target debugging,
  • With an in-circuit emulator for the program testing.

µVision Debugger

The µVision symbolic, source-level debugger is ideally suited for fast, reliable program debugging. The debugger includes a high-speed simulator that let you simulate an entire 8051 system including on-chip peripherals and external hardware. The attributes of the chip you use are automatically configured when you select the device from the Device Database.

The µVision Debugger provides several ways for you to test your programs on real target hardware.

Development Tools

The Keil development tools for 8051 offer numerous features and advantages that help you quickly and successfully develop embedded applications. They are easy to use and are guaranteed to help you achieve your design goals.

The µVision IDE and Debugger is the central part of the Keil 8051 development tools. µVision offers a Build Mode and a Debug Mode.

In the µVision Build Mode you maintain the project files and generate the application. µVision uses either the GNU or 8051 ADS/Real View™ development tools.

In the µVision Debug Mode you verify your program either with a powerful CPU and peripheral simulator.

Operation of µVision

The µVision screen provides you with a menu bar for command entry, a tool bar where you can rapidly select command buttons, and windows for source files, dialog boxes, and information displays. µVision lets you simultaneously open and view multiple source files.

µVision has two operating modes:

  • Build Mode: Allows you to translate all the application files and to generate executable programs. The features of the Build Mode are described under Creating Applications.
  • Debug Mode: Provides you with a powerful debugger for testing your application. The Debug Mode is described in Testing Programs.

In both operating modes you may use the source editor of µVision to modify your source code. The Debug mode adds additional windows and stores an own screen layout.

The following picture shows a typical configuration of µVision in the Debug Mode.


  • The tabs of the Project Workspace give you access to: Files and groups of the project; CPU Registers during debugging; Tool and project specific on-line Books.
  • The tabs of the Output Window provides: Build messages and fast error access; Debug Command input/output console; Find in Files results with quick file access.
  • The Memory Window gives access to the memory areas in display various formats.
  • The Watch & Call Stack Window allows you to review and modify program variables and displays the current function call tree.
  • The Workspace is used for the file editing, disassembly output, and several other debug specify information.
  • The Peripheral Dialogs help you to review the status of the on-chip peripherals in the microcontroller.

Select the Toolset

µVision uses the C51 Real View compilation tools, the C51 ADS compiler, the GNU GCC compiler, or the Keil C C51 compiler. When using the GNU GCC compiler or C51 ADS it is required to install the toolset separately.


The toolset that you are actually using is selected in the µVision IDE under Project - Components, Environment, and Books.

  • Use Real View Compiler selects the ARM development tools for this project. The setting Real View Folder specifies the path to the development tools. Examples for the various C51 ADS/Real View versions:
  • Real View Compiler for µVision: BIN\
  • ADS V1.2: C:\Program Files\C51\ADSv1_2\Bin
  • Real View Evaluation Version 2.1: C:\Program Files\C51\RVCT\Programs\2.1\350\eval2-sc\win_32-pentium
  • Use Keil C C51 Compiler selects the Keil C C51 Compiler, Keil AC51 Assembler and Keil LC51 Linker/Locater for this project.
  • Use GNU Compiler selects the GNU development tools for this project. The setting Cygnus Folder specifies the path to the GNU installation folder.
  • The GNU-Tool-Prefix allows using GNU tool chain variants. Examples for the various GNU versions:
  • GNU V3.22 with uclib: GNU-Tool-Prefix: arm-uclibc- Cygnus Folder: C:\Cygnus
  • GNUC51 V4 with standard library: GNU-Tool-Prefix: 8051-elf- Cygnus Folder: C:\Program Files\GNUARM\
  • The setting Keil Root Folder is the base folder of the Keil µVision/C51 installation. For the Keil C51 Tools the paths to the tool components is configured under Development Tool Folders.

Create a Project

µVision includes a project manager which makes it easy to design applications for a C51 based microcontroller. You need to perform the following steps to create a new project:

  • Start µVision and select the toolset
  • Create a project file and select a CPU from the device database.
  • Create a new source file and add this source file to the project.
  • Add and configure the startup code for the C51.
  • Set tool options for target hardware.
  • Build project and create a HEX file for PROM programming.

Start µVision

µVision is a standard Windows application and started by clicking on the program icon.

Create a Project File

To create a new project file select from the µVision menu Project – New Project…. This opens a standard Windows dialog that asks you for the new project file name.

We suggest that you use a separate folder for each project. You can simply use the icon Create New Folder in this dialog to get a new empty folder. Then select this folder and enter the file name for the new project, i.e. Project1. µVision creates a new project file with the name PROJECT1.UV2 which contains a default target and file group name. You can see these names in the Project Workspace – Files.

Select a Device

When you create a new project µVision asks you to select a CPU for your project. The Select Device dialog box shows the µVision device database. Just select the microcontroller you use. We are using for our examples the Philips 89V51RD2 controller. This selection sets necessary tool options for the 89V51RD2 device and simplifies in this way the tool configuration.



  • When you create a new project, µVision may automatically add the correct device specific CPU startup code for you.
  • On some devices, the µVision environment needs additional parameters that you have to enter manually.

You may create a new source file with the menu option File – New. This opens an empty editor window where you can enter your source code. µVision enables the C color syntax highlighting when you save your file with the dialog File – Save As… under a filename with the extension *.C. We are saving our example file under the name MAIN.C.



    #define led1 IOPIN0

    #define tled1 IO0DIR

    void delay(int x);

     void main()


           tled1 = 0x00FF0000;

           led1 = 0x00000000;



                 IOSET0 = 0x00FF0000;


                  IOCLR0 = 0x00FF0000;





void  delay(int x)


      unsigned  int  k,l;

      for(k = x;k > 0;k--)

           for(l = 0;l < x;l++);




Once you have created your source file you can add this file to your project. µVision offers several ways to add source files to a project. For example, you can select the file group in the Project Workspace – Files page and click with the right mouse key to open a local menu. The option Add Files opens the standard files dialog. Select the file MAIN.C you have just created.


Set Tool Options for Target

µVision lets you set options for your target hardware. The dialog Options for Target opens via the toolbar icon or via the Project - Options for Target menu item. In the Target tab you specify all relevant parameters of your target hardware and the on-chip components of the device you have selected. The following the settings for our example are shown.


Build Project and Create a HEX File

Typical, the tool settings under Options – Target are all you need to start a new application. You may translate all source files and line the application with a click on the Build Target toolbar icon. When you build an application with syntax errors, µVision will display errors and warning messages in the Output Window – Build page. A double click on a message line opens the source file on the correct location in a µVision editor window.

Once you have successfully generated your application you can start debugging. After you have tested your application, it is required to create an Intel HEX file to download the software into an EPROM programmer or simulator. µVision creates HEX files with each build process when Create HEX file under Options for Target – Output is enabled. The FLASH Fill Byte, Start and End values direct the OH166 utility to generate a sorted HEX files; sorted files are required for some Flash programming utilities.

You may start your PROM programming utility after the make process when you specify the program under the option Run User Program #1.


Now you can modify existing source code or add new source files to the project. The Build Target toolbar button translates only modified or new source files and generates the executable file. µVision maintains a file dependency list and knows all include files used within a source file.

Even the tool options are saved in the file dependency list, so that µVision rebuilds files only when needed. With the Rebuild Target command, all source files are translated, regardless of modifications.

Test Programs with the µVision Debugger

It describes the Debug Mode of µVision and shows you how to use the user interface to test a sample program. Also discussed are simulation mode and the different options available for program debugging.

You can use µVision Debugger to test the applications you develop using the GNU or ARM ADS/Real View tool chain. The µVision Debugger offers two operating modes that are selected in the Options for Target – Debug dialog.


  • Use Simulator allows configuring the µVision Debugger as software-only product that simulates most features of an ARM7 microcontroller without actually having target hardware.
  • You can test and debug your embedded application before the hardware is ready. µVision simulates a wide variety of peripherals including the serial port, external I/O, and timers. The peripheral set is selected when you select a CPU from the device database for your target.
  • Use Advance GDI drivers, like the Keil ULINK ARM Debugger provide an interface to target hardware. With the Advanced GDI interface you may connect the µVision Debugger directly to emulators, Embedded ICE.

CPU Simulation

The µVision Debugger simulates up to 4GB (Giga Bytes) of memory from which areas can be mapped for read, write, or code execution access.

In addition to memory mapping, the simulator also provides support for the integrated peripherals of the various ARMS based microcontroller devices.

The on-chip peripherals of the CPU you have selected are configured from the Device Database selection you have made when you create your project target.

You may select and display the on-chip peripheral components using the Debug menu.

You can also change the aspects of each peripheral using the controls in the dialog boxes.

Start Debug Mode

You can start the debug mode of µVision with the Debug – Start/Stop Debug Session command. Depending on the Options for Target – Debug configuration, µVision will load the application program and run the startup code.

For information about the configuration of the µVision debugger refer to Set Debug Options. µVision saves the editor screen layout and restores the screen layout of the last debug session. If the program execution stops, µVision opens an editor window with the source text or shows CPU instructions in the disassembly window.

The next executable statement is marked with a yellow arrow.

During debugging, most editor features are still available. For example, you can use the find command or correct program errors. Program source text of your application is shown in the same windows.

The µVision debug mode differs from the edit mode in the following aspects:

  • The Debug Menu and Debug Commands are available. The additional debug windows are discussed in the following.
  • The project structure or tool parameters cannot be modified. All build commands are disabled.

Vision lets execute your application program in several different ways:

  • With the Debug Menu and Debug Commands.
  • With the Run till Cursor line command in the local context menu. The local context menu opens with a right mouse click on the code line in the Editor or Disassembly window.
  • In the Output Window – Command page you can use the Go, Ostep, Pstep, and Tstep commands.

Set Debug Options


µVision provides several windows and dialogs that aid during the debugging phase. The windows and dialogs open via toolbar buttons or the µVision menu.

Cache Options

These options improve the performance of the µVision Debugger during target debugging by caching target memory areas in the PC memory. By default, all options are enabled to get maximum performance.

  • Cache Code informs the debugger that the downloaded program code will not change. µVision will therefore never read the program code from the target system. Disable this option if you are using self modifying code or if you have the impression that the program code is overwritten in your application.
  • Cache Memory selects that the memory content is considered to be unmodified during a program stop until the next single step; procedure step or go command is executed. Disable this option if you want to see the actual memory content even if the debugger is halted.

Download Options

  • Verify Code Download when enabled, the µVision compares the content of the target memory with the application program loaded to the Debugger.
  • Download to Flash when enabled, the Debugger download code to all memory regions. When disabled, the Debugger does not download code to Memory Address Ranges defined under Flash Download Setup.

Misc Options

  • Use Reset at Startup enables a CPU Reset at the debugger startup.
  • When enabled, the Debugger performs a device specific reset at startup.
  • When disabled, the Debugger only stops the CPU (at the current executed instruction). This allows you to interrupt the current program execution.

Flash Programming

µVision integrates Flash Programming Utilities in the project environment. All configurations are saved in context with your current project.

Configure the Flash Programming Utilities under Project - Options - Utilities. You may use external command-line driven utilities (usually provided by the chip vendor)

Flash Programming may be started from the Flash Menu or before starting the µVision Debugger when you enable Project - Options - Utilities - Update Target before Debugging.

RAM for Algorithm specifies the RAM that is used to download the programming algorithm. Typically this is on-chip RAM space of the Microcontroller.

  • Start is the start address of the RAM area.
  • Size is the memory size of this RAM area.

Programming Algorithm defines attached Flash ROM devices and configuration parameters. The list shows the attached Flash ROM programming algorithms. Select the algorithm to change:

  • Start address of the Flash Address Range.
  • Size of the Flash ROM which will be reflected in the Flash Address Range.

Use Add to attach other Flash ROM devices or Remove to delete the selected device algorithm. This opens a list that shows the available algorithms. You may add own algorithms to this list as described under Define Flash Algorithms.

Define Flash Algorithms

The µVision environment allows you to define additional Flash programming algorithms.

Define a New Flash Programming Algorithm

You should perform the following steps to configure a new Flash Programming Algorithm:

  • Create a new empty sub-folder in..\C51\Flash.
  • Copy the content of an existing Flash algorithm (for example ...\C51\Flash\LPC_IAP_256) to this new folder as a template for new device algorithms.
  • Rename the project file P89V_IAP_256.UV2 to represent the new Flash ROM device name, for example: 29F400.UV2 and open this new project with the µVision IDE.
  • In the dialog Project - Options for Target - Output replace all output names (i.e. 89V_IAP_256) to the new device name.
  • Edit the file FlashPrg.C and define the function code for EraseChip, EraseBlock and ProgramBlock. The Init and UnInit function allows you to write initializations and de-initialization code required for the algorithm.
  • Define the device parameters in the struct FlashDevice in the file FlashDev.C.
  • Build the new Flash programming algorithm. The output file with the extension *.FLX contains the new programming algorithm. Use the Add button in the Configure Flash Download dialog to add this programming algorithm file to the µVision project of target application.

Test a New Flash Programming Algorithm

The folder...\C51\Flash\89V_IAP_256\Test contains a project that allows you to test a new Flash Programming Algorithm.

Sample Programs

The sample programs are ready for you to run. You can use the sample programs to learn how to use our tools. Additionally, you can copy the code from KEIL samples for your own use.

The sample programs are found in...\C51\Examples (for Keil toolset), C51\GNU\Examples (for GNU), and...\C51\ADS\Examples (for ADS).

Each sample program is stored in a separate folder along with project files that help you quickly build and evaluate each sample program.

HELLO: Your first C51 C Program

The HELLO sample program is located in C:\KEIL\C51\GNU\EXAMPLES\HELLO. HELLO does nothing more than print the text “Hello World” to the serial port. The entire program is contained in a single source file HELLO.C.

This small application helps you confirm that you can compile, link, and debug an application. You can perform these operations from the µVision for Windows using the provided project file.

The only on-chip peripheral used is the serial port. You do not actually need a target CPU because µVision lets you simulate the hardware required for this program.

HELLO Project File

In µVision, applications are maintained in a project file. A project file has been created for HELLO.

To load this project, select Open Project from the Project menu and open HELLO.UV2 from the folder …\C51\GNU\EXAMPLES\HELLO.


Editing HELLO.C

You can now edit HELLO.C. Double click on HELLO.C in the Files page of the Project Workspace. µVision loads and displays the contents of HELLO.C in an editor window.

Compiling and Linking HELLO

When you are ready to compile and link your project, use the Build Target command from the Project menu.

µVision begins to translate and link the source files and creates an absolute object module that you can load into the µVision debugger for testing. The status of the build process is listed in the Build page of the Output Window.


Testing HELLO

Once the HELLO program is compiled and linked, you can test it with the µVision debugger. In µVision, use the Start/Stop Debug Session command from the Debug menu or toolbar. µVision initializes the debugger and starts program execution till the main function.


Open Serial Window #1 that displays the serial output of the application with the Serial Window #1 command from the View menu.


Run HELLO with the Go command from the Debug menu or toolbar. The HELLO program executes and displays the text “Hello World” in the serial window.


Stop Running HELLO with the Halt command from the Debug menu or the toolbar. You may also type ESC in the Command page of the Output window.

During debugging µVision will show the following output:


Single-Stepping and Breakpoints


Use the Insert/Remove Breakpoints command from the toolbar or the local editor menu that opens with a right mouse click and set a breakpoint at the beginning of the main function.


Use the Reset CPU command from the Debug menu or toolbar. If you have halted HELLO start program execution with Run. µVision will stop the program at the breakpoint.


You can single-step through the HELLO program using the Step buttons in the debug toolbar. The current instruction is marked with a yellow arrow. The arrow moves each time you step.


Place the mouse cursor over a variable to view their value.


You may stop debugging at any time with Start/Stop Debug Session comman

Using On-chip Peripherals

The on-chip peripherals of 8051 microcontrollers are quite sophisticated and offer numerous configuration options. The code examples only present one or two methods of using each peripheral.

The status of the on-chip peripherals can be review in the µVision Debugger using the Peripherals menu. The menu items are device specific and configured based on information from the Device Database™.

It contains generic information about:

  • Startup Code: initialize the CPU and transfers control to the main function.
  • CPU Header Files: define the Peripheral Registers of the 8051 device in use.
  • Parallel Port I/O: usage of standard I/O ports.
  • Interrupts: explains the different interrupt variants on 8051 devices.
  • Vectored Interrupt Controller: explains the usage of a vectored interrupt.
  • General Purpose Timers: discusses the usage of standard timers.
  • Serial Interface:tells how to implement serial UART communication.
  • Watchdog Timer: usage of a watchdog timer for recovery from hardware or software failures.
  • A/D Converter: convert an analog input voltage to a digital value.
Find to

Join the World's Largest Technical Community

we respect your privacy.