Sei sulla pagina 1di 17

Embedded System Fundamentals

(SVE-511)

Work Load Assignment 1

Submitted by
Ashish Kumar
31611122

Masters of Technology
In
Embedded Systems

National Institute of Technology, Kurukshetra

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

Programming the ARM Based Micro-controller with KEIL


Compiler
Introduction:
Programming micro-controller is dependent on the compiler and the language chosen for the
programming. If the Low level language e.g assembly language is used the knowledge of
micro-controller block diagram, architecture, pins diagram, addressing modes, instruction set, timing,
frequency are essential. This makes the code of small size but increases the programmer effort
regarding Design knowledge. The compiler choice is dependent upon the supported micro-controllers
by it. In this discussion we needed to program a ARM Cortex-M based microcontroller so the choice of
the complier and programming language must be done accordingly. The first task is simple as the ARM
already describe the compatible complier program as KEIL. The language of the program is chosen as
High level language C for not going into deep of the ARM controllers.

About KEIL and ARM


The Keil products from ARM include C/C++ compilers, debuggers, integrated development and
simulation environments, RTOS and middleware libraries, and evaluation boards for ARM, Cortex-M,
Cortex-R4, 8051, C166, and 251 processor families.Keil implemented the first C compiler designed from
the ground-up specifically for the 8051 microcontroller.In October 2005, Keil was acquired by ARM.
Since the acquisition, ARM has continued the development and support of Keil products for existing
8051, 251, and C166 markets. In addition, we have driven innovation to support and significantly
improve software development around ARM processor-based devices.

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.

KEIL Support for ARM


The Keil Microcontroller Development Kit (MDK) helps you to create embedded applications for ARM
Cortex-M processor-based devices. MDK is a powerful, yet easy to learn and use development system.
MDK Version 5 consists of the MDK Core plus device-specific Software Packs, which can be downloaded
and installed based on the requirements of your application.

MDK-Professional contains extensive middleware libraries for sophisticated embedded


applications and all features of MDK-Standard.

MDK-Standard supports Cortex-M, selected Cortex-R, ARM7 and ARM9 processor-based


microcontrollers.
MDK-Cortex-M supports Cortex-M processor-based microcontrollers.

MDK-Lite is code size restricted to 32 KB and intended for product evaluation, small projects, and
the educational market.

Prerequisite to write a code

1. Choice of the Microcontoller IC:


The choice of IC is dependent on the application and its availablity in the market. Some other factors
like cost, area and supports may also be considered. In this project we used The LPC213x and

LPC213x/01 microcontrollers based on a 16/32 bit ARM7TDMI-S CPU. This is choosen as it is


supported by Keil Complier and also by the simulation software Proteus.

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 Legacy Support from www.keil.com/mdk5/legacy. This adds support for


ARM7, ARM9, and Cortex-R processor-based devices.

4. Header Files/Startup files:

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.

5. Basics of Micro-controller IC:


In this discussion I would like to add, while checking the IC as programmer we need not to worry much
about the controller internals. One would always prefer that in case of any double check the
programming manual once again while getting issue in compilation or operation during the reviews.

Figure 2: Micro-controller User manual volume

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.

5.1 Block Diagram:

Figure 3: LPC213x/01 Micro-controllers Block diagram

5.2 On-chip Flash memory system


The LPC213x incorporates a 32, 64, 128, 256 or 512 kB Flash memory system. This

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

Register is used to get the status of the pins.


Register is used to set the direction of the pins, when set to 1 means output and when 0 means input.
Register is used to set the GPIO pins.
Register is used to clear the GPIO pins.

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.

Figure 5: Opening the KEIL Compiler

2. Click on the Project>New uvision Project. Select name and folder for the Project.

Figure 6: Create a New Project and Store it at required Folder location

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

Figure 7: Choosing the software package

3. If you find the correct IC for your controller then proceed further.

Figure 8: Using the legacy support

11

4. Create a new empty document and save it as desired format, e.g. it is chosen as .c file.

Figure 9: Creating the C file document

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;
}

//P0.0 to P0.7 are high


//P0.0 to P0.7 are low

//Now we will read the status of the Pin P0.8


//and Clear the Ports when Button is Pressed, otherwise Ports are High

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.

Figure 10: Add files to Source Group

13

6. Choosing Options for target Micro-controller:

Figure 11: Choosing Crystal frequency

Figure 12: Choosing HEX export

14

Compile and creating Hex file.

Figure 13: Create and Build Target

15

Debug:

Figure 14:Debugging Screen

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

Figure 16: OUTPUT of the Circuit using PROTEUS simulation

17

Potrebbero piacerti anche