keil tutorial

13
Software Keil uVisio Flash Mag Keil uVi on IDE uVision ID embedde It integra (for assem editor, de gic A tool for p sion IDE DE (Integra ed applicatio ates a projec mbling, com ebugger and programming ted Develop ons using th ct manager mpiling, and d simulator g flash based pment Envir e Keil devel (to create a linking emb into one env microcontrol ronment) al opment too and maintai bedded app vironment. llers lows develo ols. n projects), lications), s opers to crea , make utilit source code ate ty

Upload: anishgoel

Post on 25-May-2015

8.051 views

Category:

Education


5 download

TRANSCRIPT

Page 1: Keil tutorial

Software 

Keil uVisio

 •

 Flash Mag

Keil uVi

 

 

on IDE 

uVision IDembeddeIt integra(for assemeditor, de

gic  

A tool for p

sion IDE

DE (Integraed applicatioates a projecmbling, comebugger and

programming

ted Developons using thct manager

mpiling, and d simulator

g flash based 

pment Envire Keil devel (to create a linking embinto one env

microcontrol

ronment) alopment tooand maintaibedded appvironment.

llers 

lows develools.  n projects),lications), s

opers to crea

, make utilitsource code

ate

ty

Page 2: Keil tutorial

Keil Softw

The proje

 

1. Create 

2. Create 

3. Build ap

4. Debug 

5. Downlo

 

Procedure

1. C

  C

  Th

   

   

      

 

2. C 1

ware Develop

ct developme

a project, sel

source files in

pplication wit

and correct e

oad code to F

es 

reate Directo

reate a worki

his directory 

*.uvpr

*.c – C

*.hex –to the 

reate New Pr

. Launch KeStart Menu

pment Cycle 

ent cycle is si

ect the targe

n C 

th Project Ma

errors in sourc

lash ROM or 

ory 

ing directory,

will include t

roj – the main

C code; an inp

– contains mamicroproces

roject 

il uVision IDEu.  

milar to any o

t device from

anager 

ce files, verify

SRAM and te

, such as C:\S

he following f

n project file t

put to the uVi

achine code; sor board  

 by clicking o

other softwar

m the Device D

y and optimiz

est the linked 

 

ITE Program\

files: 

to manage all

sion IDE prog

an output fro

n the icon on

re developme

Database, and

ze application

application

\UV Project, t

l files associa

gram 

om uVision ID

n your deskto

ent project. 

d configure th

to save all you

ted with curr

DE program th

p or by select

he tools setti

ur work. 

rent project 

hat is downlo

ting it from th

ngs 

oaded 

he 

Page 3: Keil tutorial

2. To create a new project file, click on Project from the menu bar and select New uVision Project. Under the Create New Project window, give your project a name and save it in the folder you created.       

 

   

3. Select the device type by expanding NXP (founded by Philips) and choosing LPC2148. Notice that the description section lays out the details of the LPC2148 microcontroller, including the on‐chip peripherals and memory options. Click OK.  

 

(This step is very important since uVision customizes the tool settings, peripherals, and dialogs for that particular device.) 

Page 4: Keil tutorial

 **You may invoke this screen through the menu Project ‐> Select Device for Target … Menu in order to change the device type. 

 

4. A dialog box will appear asking if you want to include a startup code for this device. Click YES.  

 

(All embedded programs require some kind of microcontroller initialization or startup code. The startup code specifies the starting configuration of your hardware. All Keil tools include chip‐specific startup code for most of the devices listed in the Device Database.) 

 

5. Once you have created a new project successfully, the Project Window shows the targets, groups, and files of your project. By default, the target name is set to Target 1, while the group’s name is Source Group 1.  

Page 5: Keil tutorial

  

3. Create Source Files  Source files are …    

1. To create a new source code, use the button on the File Toolbar or click on File in the menu bar and select New. This action opens an empty Editor Window to enter your source code.  

2. Type in your C language code. (Note: See C Programming)  

3. Save the new source file using the button on the File Toolbar or click on File in the menu bar and select Save.  

 

4. Add Source Files  

1. In the Project Window (on the left), expand the Target 1 folder. Right click on the Source Group 1 folder, then choose Add Files to Group ‘Source Group 1’ … .  

Page 6: Keil tutorial

   

2. Select the source file (.c file) you just created and saved. Click Add and then Close.   

 

  

 

Page 7: Keil tutorial

5. Compiling The compiler allows you to write in the C language and compile code to run on the LPC2148 microcontroller.  

 

1. First, you need to set the option to create a HEX file by clicking on Project from the menu bar and selecting Options for Target ‘Target 1’… .   

   

2. On the Output Tab, check the option to Create HEX File. Click OK.  

Page 8: Keil tutorial

  

3. Click on Project from the menu bar and select Build Target or Rebuild all target files. A Build Output window will show the source code getting compiled into a HEX file.   

  

4. In the Build Output Window, a message of 0 Errors and 0 warnings signifies that your program compiled successfully. (Warnings do not prevent the program from running correctly. However, you should consider solving them to eliminate unwanted effects).    

Page 9: Keil tutorial

  

6. Downloading Program to Microcontroller We need to download the machine code (HEX file) into the physical memory locations of the microcontroller.  

 

  Setting Options 

1. Select Flash from the menu bar and click on Configure Flash Tools… . On the Utilities tab, choose Use External Tool for Flash Programming. In the command line, select FlashMagic.exe.  

Page 10: Keil tutorial

  

2. In the Arguments line, modify the COM port number so that it corresponds to the port number assigned by the Windows Device Manager.   To find the COM port number, follow these steps:  1. Click on Start in the lower left corner of your PC screen. Then, click on Control Panel. 2. Go to Hardware and Sound. Under Devices and Printers, select Device Manager. A 

dialog box will pop up. Click OK.  3. In the Device Manager Window, expand Ports (COM & LPT) to see the port number 

of the USB connection that is connected from the microcontroller to the PC.   

Page 11: Keil tutorial

   4. On the Target tab, check Use MicroLIB.  

  

Downloading Program The program will be downloaded to the micontroller using FlashMagic. FlashMagic is a utility to download the HEX file to the LPC2148 processor.  

Page 12: Keil tutorial

1. Click on Flash from the menu bar and select Download. Wait till the downloading process is finished.  

 

  2. In FlashMagic, select LPC2148 as the device, the correct COM port number, Baud Rate of 

9600, None (ISP) for Interface and 12MHz for Oscillator. Then, check Erase blocks used by Hex File.  

Page 13: Keil tutorial

  

 3. Select the HEX file that was just created by clicking Browse. Then, click Start.  

 4. The program will be downloaded to the on‐chip FLASH memory when Finished is 

displayed in the status box at the bottom of the window.