0% found this document useful (0 votes)
255 views

Lab Report2 Keil Simulator

This document describes using Keil MicroVision (Keil μVision) integrated development environment to write, compile, debug and simulate programs for microcontrollers. It discusses creating a new project in Keil, programming in assembly language, debugging code using the simulator, and loading programs onto a microcontroller to read and write data from ports. The objectives were to learn simulation and debugging in Keil and performing I/O with an 8051 microcontroller by reading a port and outputting the data to another port.

Uploaded by

Khubaib Waqar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
255 views

Lab Report2 Keil Simulator

This document describes using Keil MicroVision (Keil μVision) integrated development environment to write, compile, debug and simulate programs for microcontrollers. It discusses creating a new project in Keil, programming in assembly language, debugging code using the simulator, and loading programs onto a microcontroller to read and write data from ports. The objectives were to learn simulation and debugging in Keil and performing I/O with an 8051 microcontroller by reading a port and outputting the data to another port.

Uploaded by

Khubaib Waqar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

xy

Microcontroller Based Systems


(MTS-310)
DE-39 Mechatronics
Syndicate –B

Group Members : Khubaib Waqar Khan


: Saad Bader
Lab Report 2 : Keil Simulator and Debugger
Submitted to : LD Muhammad Qasim
Lab2 Keil Simulator & Debugger Khubaib & Saad

1
Lab2 Keil Simulator & Debugger Khubaib & Saad

Keil Simulator and Debugger


Keil MicroVision (Keil µVision) is a free software which is used for an embedded program
developing. Keil is an integrated development environment (IDE), which consists of
1. Text editor to write programs in C/C++ or Assembly Language
2. Compiling and Assembling
3. Debugger to test and debug
4. Converter to covert source code to hex file for loading/burning in Proteus (or any other
simulation environment)

Figure 1 Keil Window (If text editor is present, go-to PROJECT, CLOSE PROJECT)

Objectives:

 To learn simulation and debugging in Keil


 Loading code on micro-controller (µC) and simulation in Proteus and perform
o Inputting data from port micro-controller 8051
o Outputting data on port of micro-controller 8051
These objectives were completed using Demo Task 1, 2 and 3.

1
Lab2 Keil Simulator & Debugger Khubaib & Saad

Demo Task1 Creating a New Project

1. After opening Keil uV4, go-to PROJECT in main toolbar and select NEW.
2. Browse to save the project
3. In dialog box SELECT YOUR DEVICE MODEL as 89C51 by browsing in ATMEL or using
the SEARCH tab given. Cancel ADD STARTUP FILE OF YOUR DEVICE as we do not
need it
4. Now in PROJECT WINDOW, TARGET, SOURCE GROUP one can add NEW or
EXISTING project
5. Add ASM FILE for assembly language

Figure 2 Making a new project

Figure 4 Cancel Adding of Start-up file

Figure 3 Selecting 89C51

2
Lab2 Keil Simulator & Debugger Khubaib & Saad

Figure 5 Maknig ASM file

6. Now write your program and save it CTRL+S.

Figure 6 Ready to Work

3
Lab2 Keil Simulator & Debugger Khubaib & Saad

Demo Task2 Programing and Debugging in Keil

We learned programing in Assembly Language in Keil

Figure 7 Understanding the Basics

General Syntax

General format of an instruction is


mnemonics (commands) operand (, operands) ; comments after semicolon
Destination (, Source)

Keil is not case sensitive and ignores white spaces

Commands

ORG 0: Organize Memory. Start of program. Memory starts from the specified location. If ORG
5 than memory 0 to 4 wasted
Main: Label is optional if desired can be added after ORG
MOV: as MOV destination, source. Sets the value of destination=source, Overwrites the
destination
MOV A, P0 ; A=P0
ADD: Can only be used with special register A. Performs arithmetic addition operation.
ADD A, operand ; A = A + operand i.e. addition result stored in A
SETB: Sets bit to 1
CLR: Resets bit to 0
END: after END everything ignored. It shows END of prgram

4
Lab2 Keil Simulator & Debugger Khubaib & Saad

Registers

General Purpose Registers


They are used to store data. Data allocation starts according to ORG (number specified). They
are R0 to R7 having 2-bytes each. Also there are 4 BANKS for extra memory, therefore 32
registers in total. Use SETB and CLR, of RS0 and RS1 to change BANKS
Table 1 Register Bank Changing

RS1 RS0 BANK


0 0 0
0 1 1
1 0 2
1 1 3

Special Purpose Registers


Table 2 Special Registers

A Arithmetic & logic. Must for ADD


B Multiplication and Division
sp Stack pointer
dptr data points 16-bit usually
PC $ program counter
sec time for execution
psw program states work

Memory Window

Shows all memory of 89C51. Use D:00 to see data-memory at 00 to see code-memory use
C:00. Code memory has Op-codes while data memory stores data values.

Debugging and Step-into

1. After writing program , SAVE, TRANSLATE and BUILD. If error code wont
BUILD.

2. Debug by or START STOP DEBUG SESSION (CTRl+F5). Debug window appears


3. Use STEP-INTO to execute statement one by one

5
Lab2 Keil Simulator & Debugger Khubaib & Saad

4. If program involves port seeing, go-to PERIPHERALS and use the port needed. Also in
memory see FF they are port locations in memory

Figure 8 Debugger

Figure 9 Port View

6
Lab2 Keil Simulator & Debugger Khubaib & Saad

Demo Task3 Input/Output Data from 89C51

Loading program into a control is called Burning program into controlling

Q. Read Port 1 and give output at Port2

1. Write the code


a. Can be done in two steps or one

Figure 10 Code in Keil

Hex file is machine version of code

2. Make HEX file


a. Goto OPTIONS FOR TARGET
b. Set Xtal to 12MHz
3. Go-to OUTPUT, check CREATE
HEX FILE, OK
4. BUILD to create HEX file

Figure 11 Options for target

5. Goto Proteus, make circuit, double click on µC 89C51 and upload/burn HEX file in it
6. Simulate. Observe that any change in PORT1 is seen in PORT2 i.e. data is being read from
PORT1 and outputted on PORT2

7
Lab2 Keil Simulator & Debugger Khubaib & Saad

Figure 12 Loading HEX file

Figure 13 Proteus Simulation

8
Lab2 Keil Simulator & Debugger Khubaib & Saad

Conclusion
We learned
 Keil Simulation and Debugging
 Writing an assembly program
 Burning Code on µC
 How to input/output data from ports

References
http://www.circuitstoday.com/getting-started-with-keil-uvision

and notes taken during lab

You might also like