Creating & Debugging a Project in KEIL

Creating and Debugging a Project in KEIL

Tags: Introduction of KEIL, Getting Started with KEIL, Create a Project using Keil, How to debug a project in Keil,Tutorials for creating a project using keil, Tutorials for Debugging a project using keil,, Start µVision in Keil, Step by step guide for creating project in Keil, µVision Debugger in Keil, Keil Sample Programs
Overall rating
Introduction of KEIL

The Keil Software LPC2148 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 ARM7 ANSI Optimizing C Compiler creates re locatable object modules from your C source code. The ARM Macro Assembler creates re locatable object modules from your LPC21XX 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.

Development Tools

The Keil development tools for ARM 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 ARM 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 ARM ADS/Real View™ development tools.

In the µVision Debug Mode you verify your program either with a powerful CPU and peripheral simulator that connects the debugger to the target system.

The ULINK allows you also to download your application into Flash ROM of your target system.

Getting Started

The µVision IDE from Keil 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 (Integrated Development Environment) is the easiest way for most developers to create embedded applications using the Keil development tools. To launch µVision, click on the icon on your desktop or select Keil µVision which version you are using from the Start Menu.

Create a Project

µVision includes a project manager which makes it easy to design applications for an ARM 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 ARM.
  • 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.



Here we are using Philips LPC2148 controller. This selection sets necessary tool options for the LPC2148 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. Please carefully read the information provided under Description in this dialog, since it might have additional instructions for the device configuration.

A window will open up asking for add up some startup files. Now we don’t want that, therefore Press NO.

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.

µVision creates HEX files with each build process when Create HEX file under Options for Target – Output is enabled.

Select the Toolset

µVision uses the ARM Real View compilation tools, the ARM ADS compiler, the GNU GCC compiler, or the Keil C ARM compiler. When using the GNU GCC compiler or ARM 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 ARM ADS/Real View versions:
  • Real View Compiler for µVision: BIN\
  • ADS V1.2: C:\Program Files\ARM\ADSv1_2\Bin
  • Real View Evaluation Version 2.1: C:\Program Files\ARM\RVCT\Programs\2.1\350\eval2-sc\win_32-pentium
  • Use Keil CARM Compiler selects the Keil CARM Compiler, Keil AARM Assembler and Keil LARM 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
  • GNUARM V4 with standard library: GNU-Tool-Prefix: arm-elf- Cygnus Folder: C:\Program Files\GNUARM\
  • The setting Keil Root Folder is the base folder of the Keil µVision/ARM installation. For the Keil ARM Tools the paths to the tool components is configured under Development Tool Folders.

Create New Source Files

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.



Therefore you just creating a C file for add with the project. If you have already created C file then you just added that C file into Project file.



Now, you must rebuild the project file for generating HEX file. When you build the project then only the HEX file is generated by using the C Compiler.

Build the Project

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.

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.

The final output will look like this...

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 (On-chip Debug System) for example with the Keil ULINK USB-JTAG Adapter.

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. The µVision simulator traps and reports the illegal memory accesses.

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.

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 ...\ARM\Examples (for Keil toolset), \ARM\GNU\Examples (for GNU), and...\ ARM\ 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 ARM C Program

The HELLO sample program is located in C:\KEIL\ARM\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 …\ARM\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 command.

Using On-chip Peripherals

The on-chip peripherals of ARM 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 ARM device in use.
  • Parallel Port I/O: usage of standard I/O ports.
  • Interrupts: explains the different interrupt variants on ARM 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.
  • Pulse Width Modulation: may be used to generate analog output voltages.
  • A/D Converter: convert an analog input voltage to a digital value.
  • Power Reduction Modes: put the ARM device into IDLE or POWER DOWN mode.

Join the World's Largest Technical Community

we respect your privacy.