Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
(SVE-511)
Submitted by
Ashish Kumar
31611122
Masters of Technology
In
Embedded Systems
Table of Contents:
Programming the ARM Based Micro-controller with KEIL Compiler......................................... 3
Introduction:.................................................................................................................................. 3
About KEIL and ARM.................................................................................................................... 3
KEIL Support for ARM.................................................................................................................. 4
Prerequisite to write a code........................................................................................................ 4
Writing a C Code:........................................................................................................................... 9
Compile and creating Hex file................................................................................................... 15
Debug:........................................................................................................................................... 16
Simulation of Output:................................................................................................................. 17
Today, the Keil development tools are used by a wide range of developers building software
applications for end products targeting diverse vertical markets such as Aerospace, Banking, Healthcare,
Automotive, Transportation, Manufacturing, Consumer, Military and Telecommunications.
MDK-Lite is code size restricted to 32 KB and intended for product evaluation, small projects, and
the educational market.
2. Software Package:
While downloading the MDK lite version of KEIL software from its website
https://www.keil.com/demo/eval/arm.htm, it offers a easy to describe applications as user-form and
software package is then created according to the preference filled.
Figure 1: Choosing the Device and the device architecture before downloading the compiler software.
3. Support Files:
For older verion of compiler the legacy support is useful.
MDK Version 5 is capable of using MDK Version 4 projects after installation of
The header files of some of the controller are not found in package. In such a case the header files
can be downloaded separately and then put them in the same folder where the project code is written
and add them in source.
However there are some basics that must be always known. These are essentially the memory space
and clock frequency. In this, while we are programming the PORTs we need deep knowledge about the
Ports and there prograaming instructions.
The LPC213x and LPC213x/01 microcontrollers are based on a 16/32 bit ARM7TDMI-S CPU with
real-time emulation and embedded trace support that combines the microcontroller with embedded
high speed Flash memory ranging from 32 kB to 512 kB. 128-bit wide memory interface and a unique
accelerator architecture enable 32-bit code execution at maximum clock rate. For critical code size
applications, the alternative 16-bit Thumb Mode reduces code by more than 30 % with minimal
performance penalty. Due to their tiny size and low power consumption, these microcontrollers are
ideal for applications where miniaturization is a key requirement, such as access control and
point-of-sale. With a wide range of serial communications interfaces and on-chip SRAM options of
8/16/32 kB, they are very well suited for communication gateways and protocol converters, soft
modems, voice recognition and low end imaging, providing both large buffer size and high processing
power. Various 32-bit timers, single or dual 10-bit 8 channel ADC(s), 10-bit DAC, PWM channels and 47
fast GPIO lines with up to nine edge or level sensitive external interrupt pins make these
microcontrollers particularly suitable for industrial control and medical systems.
memory may be used for both code and data storage. Programming of the Flash memory. he application
program, using the IAP functions, may also erase
and/or program the Flash while the application is running, allowing a great degree of
flexibility for data storage field firmware upgrades, etc
5.3 On-chip Static RAM (SRAM): The LPC213x provide 8/16/32 kB of static RAM. The LPC213x SRAM
is designed to be accessed as a byte-addressed memory.
5.4 Frequency of Operation:
While an input signal of 50-50 duty cycle within a frequency range from 1 MHz to 50 MHz can be used
by the LPC213x if supplied to its input XTAL1 pin, this micro-controllers on board oscillator circuit
supports external crystals in the range of 1 MHz to 30 MHz only.
If the on-chip PLL system or the boot-loader is used, the input clock frequency is limited to an exclusive
range of 10 MHz to 25 MHz.
5.5 Introduction to GPIO Pins
The LPC213x has Input/Output Pins know as GPIO Pins (General Purpose Input Output Pins), on reset
Pin Connect Block configures all the peripherals as GPIO pins.
The GPIO pins are controlled by four Registers:-
Figure 4: IO registers and there feature, Capture from the User manual.
IOPINIODIRIOSET
IOCLR
Note:- When IOSET = 1 it will set the particular pin, but it doesn't means that to clear the pin you will use IOSET = 0 or IOCLR =
0, this is different in case of ARM, to set the pin we have to use IOSET=1 and to clear we have to use IOCLR=1.
Writing a C Code:
Here are the set of screen-shots that describe well how to Use the compiler.
1. First Open the downloaded KEIL software and install it, it installs in the C: drive by default. You can
access is directly, or by the preferred method to search it on the start menu.
2. Click on the Project>New uvision Project. Select name and folder for the Project.
10
3. Here is important step to check the software pack, if you do not found the controller IC name in
the software pack you can download the legacy support and header files separately
3. If you find the correct IC for your controller then proceed further.
11
4. Create a new empty document and save it as desired format, e.g. it is chosen as .c file.
Code:
#include <LPC213X.H>
int main()
{
unsigned char i;
unsigned status;
//Port-0.0 tp Port-0.7 pins as Output Pin
IODIR0 = 0x000000FF;
//Do Pin Toggling 8-times
for(i=0;i<8;i++)
{
IOSET0 = 0x000000FF;
IOCLR0 = 0x000000FF;
}
while(1)
{
status = IOPIN0;
status = status & 0x00000100;
if(status == 0x00000100)
{
IOSET0 = 0x000000FF;
}
else
{
IOCLR0 = 0x000000FF;
}
}
5. Add the file in the source group 1. Here I have also added the desired header files.
12
5. Adding to Source Group 1: All the code files and support files like header file and support file must
be in the source group 1.
13
14
15
Debug:
16
Simulation of Output:
The program written and compile is
imcomplete to show the operation
without the develpoment kit or a
simulator. Here in order to compromise
with the deveploement board need we
have used the simation and designing
tool PROTEUS 8 which support the
microcontoller schematic and its hex
File. The design an simulation Output is
shown in Fig.
Figure 15: Proteus 8 LOGO
17