Introduction To KEIL
Introduction To KEIL
•
Keil is a cross compiler. So first we have to understand the concept of
compilers and cross compilers. After then we shall learn how to work with keil.
Concept of compiler: -
Compilers are programs used to convert a High Level Language to object code.
Desktop compilers produce an output object code for the underlying
microprocessor, but not for other microprocessors. I.E the programs written in
one of the HLL like ‘C’ will compile the code to run on the system for a
particular processor like x86 (underlying microprocessor in the computer). For
example compilers for Dos platform is different from the Compilers for Unix
platform
So the definition of cross compiler is a compiler that runs on one computer but
produces object code for a different type of computer. Cross compilers are
used to generate software that can run on computers with a new architecture
or on special-purpose devices that cannot host their own compilers. Cross
compilers are very popular for embedded development, where the target
probably couldn't run a compiler. Typically an embedded platform has
restricted RAM, no hard disk, and limited I/O capability. Code can be edited
and compiled on a fast host machine (such as a PC or Unix workstation) and the
resulting executable code can then be downloaded to the target to be tested.
Cross compilers are beneficial whenever the host machine has more resources
(memory, disk, I/O etc) than the target. Keil C Compiler is one such compiler
that supports a huge number of host and target combinations. It supports as a
target to 8 bit microcontrollers like Atmel and Motorola etc.
Now after going through the concept of compiler and cross compilers lets we start
with Keil C cross compiler.
8051 project development cycle: - these are the steps to develop 8051 project
using keil
1. Create source files in C or assembly.
2. Compile or assemble source files.
3. Correct errors in source files.
4. Link object files from compiler and assembler.
5. Test linked application.
now let us start how to work with keil.
to open keil software click on start menu then program and then select keil2 (or
any other version keil3 etc. here the discussion is on keil2 only). Following window
will appear on your screen
you can see three different windows in this screen. 1) project work space window
2) editing window 3) output window.
Project workspace window is for showing all the related files connected with your
project.
Editing window is the place where you will edit the code
Output window will show the output when you compile or build or run your
project.
Now to start with new project follow the steps
• when you click OK, you will be asked to add startup code and file to your
project folder. click yes. Now on your screen expand target1 list fully. You
will see following window.
•
• now click on file menu and select new file. editor window will open. Now
you can start writing your code.
• as you start writing program in C, same way here also you have to first
include the header file. Because our target is 8051 our header file will be
"reg51.h"
• after including this file. just right click on the file and select open
document <reg51.h>. The following window will appear
•
• if you scroll down cursor you will see that all the SFRs like P0-P3, TCON,
TMOD, ACC, bit registers and byte registers are already defined in this
header file. so one can directly use these register names in coding
• now you can write your program same as c language starting with void
main()
• after completing the code save the file in project folder with ".c" extension.
• now right click on "source group 1" in project workspace window. select "add
files to source gorup 1"
• select the C file you have created and click add button
•
• you will see that the c file has been added in source group
• now to compile the program from project menu select "build target". In the
output window you will see the progress
• if there is any compilation error then target will not be created. Remove all
the errors and again build the target till you find "0 Error(s)"
• now you are ready to run your program. from debug menu select "start/stop
debug session"
• you will see your project workspace window now shows most of the SFRs as
well as GPRs r0-r7. also one more window is now opened named "watches".
in this window you can see different variable values.
•
• to add variable in watch window goto "watch#1" tab. then type F2 to edit
and type the name of your variable
• if you want to see the output on ports go to peripheral menu and select I/O
ports. select the desire port. you can give input to port pins by checking or
unchecking any check box. here the check mark means digit 1 and no check
mark means 0. the output on the pin will be shown in same manner
• to run the program you can use any of the option provided "go", "step by
step", "step forward", "step ove" etc.
• now after testing your program you need to down load this program on your
target board that is 8051. for this you have to create hax file
• to create hex file first stop debug session. Again you will be diverted to
project workspace window.
• right click on "target 1" and select "option for target 1". Following window
will appear.
•
So here I have described the procedure to create a project in keil for 8051 micro
controller. To see some sample programs for 8051 in keil just go through the link
"sample programs in keil" so that you can get the idea how to write a program for
8051 in keil C.