Basic Software Applications in KEIL

Basic Software application using KEIL

Tags: Keil development tools for ARM, Basic Applications in KEIL,Introduction of KEIL, How to create HEX file in µVision
Overall rating
basic-software-application-using-keil
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 with μVision

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.


Sample Applications

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.


Start μVision

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




u-vision-3-keil


LED DELAY: ARM C Program

The led delay sample program is enabling or disabling LED (I/O port line) in a certain time period. The entire program is contained in a single source file led_delay.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 I/O port. You do not actually need a target CPU because µVision lets you simulate the hardware required for this program.


LED_DELAY Project File

In μVision, applications are maintained in a project file. A project file has been created for LED_DELAY in the name of LED_DELAY.


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


μVision creates a new project file with the name LED_DELAY.UV2 which contains a default target and file group name.




u-vision-creates-new-project




u-vision-create-new-project

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.




u-vision-device-database


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.


Note

  • 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.




open-up-asking-for-add-file


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.




set-tool-options-for-target


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




create-hex-file-under-options-for-target

Select the Toolset

This toolset is used for checking the compiler settings already installed in your computer.


μ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.




select-the-toolset


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


Create source file

You may create a 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 led_delay.C.




create-source-file-of-u-vision


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.




add-file-to-source-group


The option Add Files opens the standard files dialog. Select the file led_delay.C you have just created.




build-the-project-for-u-vision


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

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.


The final output will look like this...




build-the-project-for-u-vision


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.


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.




u-vision-debugger


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-1 Open Serial Window #1 that displays the serial output of the application with the Serial Window #1 command from the View menu.


debug-menu-or-toolbar 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-1 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.


insert-remove-breakpoints-1 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.


reset-cpu-1

Use the Reset CPU command from the Debug menu. If you have halted the program execution with Run. μVision will stop the program at breakpoint.


debug-toolbar-1

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.


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



start-stop-debug-session-1 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.

Start the Debug Mode

You can start the debug mode of μVision with the Debug – Start/Stop Debug Session command.




start-debug-mode-2




start-debug-mode


Now you just run the Debug Mode of μVision with Debug Run command. Depending on the Options for Target – Debug configuration, µVision will load the application program and run the startup code.




u-vision-with-debug-run-command


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.


Peripherals Output

Now you just see the output in Debugging Mode with Peripherals GPIO Slow Interface Port0 command.




gpio-slow-interface-port0


During debugging µVision will show the following output




during-debugging-u-vision


LED in enabling condition as shown in below,




led-in-enabling-condition


LED in disabling condition as shown in below,




led-in-disabling-condition


Join the World's Largest Technical Community

we respect your privacy.