Sei sulla pagina 1di 30

Appendix A

Keil Debugger/Simulator

It is a good way to run program on an In-Circuit Emulator (ICE) for software

development of single-chip microcomputer control applications.
Unfortunately, ICE is an expensive one. An alternative solution for software
development is software simulation. A well-designed simulator lets the user
simulate all aspects of target hardware on PC.

For the purpose of technology education and vocational education, we

recommend the excellent debugger/simulators dScope and μVision.
μVision-51 and dScope-51 are the products of Keil Software. The dScope-51
is an 8051 debugger/simulator for Windows and the μVision-51 is an 8051
integrated development environment for Windows.

The provided CD contains an eval version of dScope PK51-EVAL. The user

can visit the site to download the newest eval version of
the simulator.

Software Installation

Step 1: Put the provided CD into CD player, use Start\Run command to Open
the \EK51\Setup.exe file as shown below. Then click OK button.

Step 2: Welcome window shows the installation about the PK51 Eval Version.
Click Continue button.

Step 3: Enter the drive and directory where the PK51 Eval Version will be
placed. The default is C:\C51EVAL. If accepted, click OK to

Step 4: Enter your name and organization, then click Continue button.

Step 5: A Registration Confirmation window shows your information entered.
If correct, click Yes button to continue.

Step 6: The installation process is then in progress.

Step 7: As the installation is complete, there are three items uVision-51,

dScope-51, and Release Notes resident in the C:\WINDOWS\Start
\Programs\Keil PK51-Eval directory. The dScope is an 8051
debugger/simulator for Windows. The uVision is an 8051 integrated
development environment for Windows.

dScope-51 Debugger

Open the dScope-51 mainframe window shown below by executing

Start\Programs\Keil PK51-Eval\dScope-51. The dScope-51 is a software
debugger which simulates the hardware of MCS-51 family and can execute all
machine instructions. Simulation of the integrated peripherals is implemented
by means of loadable drivers. This makes dScope fully capable of simulating
the integrated hardware of the various derivatives of the microcontrollers. A
corresponding driver exists for each microcontroller type supported. The
software test is executed optionally either at the source level, assembler level,
or a combination of both.

The dScope divides the screen into several fully user configurable areas.
Each window can be shown or hidden. A window is selected by clicking the
mouse pointer somewhere within the window.

dScope-51 Components

1. Mainframe window
The Mainframe window is the parent of all other dScope windows. It hosts
the main menu, a toolbar with shortcuts for showing and hiding the
individual child windows, and a statusbar located on the bottom of the
mainframe window for showing a short description text for each menu
entry. The description is also available for the toolbar buttons. To get it,
select some button by moving the mouse pointer over a button. Press the
left mouse button, and keeping the left mouse button pressed, watch the
text in the status bar.

Toolbar buttons:
Open file
CPU driver selection
Show/hide Command window
Show/hide Debug window
Show/hide Register window
Show/hide Serial I/O window
Show/hide Watch window
Show/hide Performance Analyzer window
Show/hide Memory window
Show/hide Symbols window
Show/hide Call-Stack window
Show/hide Code Coverage window
Show/hide Tool Box window
Reset dScope
Show the About dialog

2. Command window
The Command window is used to enter command lines.

Commonly Used Commands

(a) Modify the contents of register:
> Register name=value
> A=45H ; load ACC with immediate value 45H
> R0=50 ; load R0 with immediate value 50

(b) Edit the contents of internal data memory:

> E D:memory address=value
(c) Edit the contents of external data memory:
> E X:memory address=value
> E D:30H=65 ; store value 65 in internal RAM address 30H
> E D:30H=65,70,34 ; store values 65, 70, 34 in internal RAM
; addresses 30H to 32H
> E X:10=12,34,56,8 ; store values 12, 34, 56, 8 in external RAM
; addresses 10 to 12

(d) Display the contents of internal memory: > D D:start address

(e) Display the contents of external memory: > D X:start address
> D D:10H ; display the contents of internal memory
; from address 10H
> D X:0100 ; display the contents of external memory
; from address 0100

(f) Load CPU driver or file: >LOAD filename
> LOAD 8051.DLL ; load 8051 driver DLL
> LOAD TEST1.HEX ; load TEST1.HEX file

3. Debug window
The Debug window is used to display: (1) source program, (2) assembler
instructions, or (3) a combination of both. The display mode can be
changed using the Commands menu entry from the menu line. Text can
be scrolled upwards, downwards or horizontally by using the scrollbars.
The Commands menu contains other commands dealing with trace
recording, source module selection, text search and others. The
remaining menu entries are used to start and stop execution of the user
program. These entries are duplicated in the dialogbar to the right of the
Debug window by using the Commands\Show Dialogbar command.

(1) Load file: A project or HEX file can be loaded to the Debug window
for simulation and debugging by using the [File\Load object file…]
command and selecting the drive and folder.

(2) Commonly used commands
[Go]: Start execution until some breakpoint gets active.
[StepInto]: Step into next statement.
[StepOver]: Step over next statement.
[StepOut]: Step out of the current function.
[Stop]: Stop execution. Before terminating dScope-51, the program in
execution must be stopped first.
[Assemble…]: Edit assembly instructions in the Debug window by
double-clicking on an instruction line to be edited in the Inline
Assembler window shown below, entering 8051 instruction, and then
clicking the Assemble button.

4. Registers window
The Registers window shown below is used to show the contents of the
various CPU registers, the current program counter (PC) and executed
cycles plus time information. The register layout in the Regs window
depends on the type of the CPU being simulated. The register contents
are updated each time program execution is stopped or if the window is
selected or double clicked.

5. Serial I/O window

The serial outputs of the user program are displayed in the Serial I/O
window as shown below. dScope traps read and write operations to the
specific serial I/O registers of the CPU and directs the output to the Serial
I/O window and serial input to the CPU specific I/O register. The details
on serial I/O depend on the CPU type and is covered by the actually loaded
CPU driver. The serial output may also be directed to a disk file. The
Serial I/O window maintains a history buffer which allows viewing about 8K
of serial output.

6. Watch window
The Watch window shown below is used to show the values of aggregate
types (structures, unions, arrays) or simple scalar values. The items to be
displayed are defined or removed either by commands in the COMMAND
window or with a specific dialog for simple operation of the WATCH window.
The WATCH window is updated after break out of execution but can be
directed to update itself periodically while the user program is executed.

7. Performance Analyzer window

The Performance Analyzer window shown below is used to show the
symbolic name or numeric address of up to 255 defined ranges and for
each range a bar which indicates the execution time percentage consumed
by each range. The display gives a quick overview of the CPU time being
consumed for each range. The bottom of the window shows the
minimum, maximum and medium time along with the invocation count of
the selected range.

8. Memory window
The Memory window shown below is used to display a range of memory in
Hex bytes. The range may be up to 64K in length. This window is
updated after break out of execution but can be directed to update itself
periodically while the user program is executed. The Memory window
contains four fields: memory identifier (D=internal and X=external),
address, Hex value, and ASCII value.

9. Symbols window
The Symbols window shown below is used to show the complete symbolic
debugging information of the loaded user program. This information
includes public symbols, functions with local symbols and line number
information. The output can be limited to symbols with a specific memory
type. The Symbol browser also includes a simple but powerful regular
expression search engine.

The Symbol browser supports the dragging and dropping of symbols to
other dScope windows such as the Command window and to the input
fields of all dialogs which require expressions for input such as define
watch, inline assemble and others.

10. Call-Stack window

The Call-Stack window shown below is used to show the current function
call nesting. The caller of some function is shown on the bottom of the
Call-Stack window if a line from the display is selected. The button
labeled “Refresh” updates the function nesting output since the Call-Stack
window can be left open all the times even when the user program is
executed. Another button labeled “Show invocation” forces the Debug
window to show the code which invoked the selected function.

11. Code Coverage window
The Code Coverage window shown below is used to show the functions
based on the user selectable module together with the number of
instructions of each function and the percentage value the instructions
already executed. Additional features include dynamic update while
executing the user program and synchronizing the Debug window to the
next executed or unexecuted instruction.

12. Toolbox: The toolbox contains a Simulator Reset button.

If CPU driver (for example, 8051.dll) is selected, Peripherals command
appears on the main menu line of dScope-51 mainframe window. The
contents of 8051 on-chip peripherals, such as I/O ports, interrupts,
timer/counters, and serial port, can be displayed and specified in its sub


1. I/O Ports: Each window of parallel ports displays the contents of the latches
and the pins. Bit value can be set or cleared.

2. Interrupt System: Open the Interrupt System window by using the

[Peripherals\Interrupt] command. This window displays the control bits of
interrupt sources. Bit value can be set or cleared.

3. Timer/Counters: Timer/Counter window displays the contents of timer/

counter registers, operating mode, and status.

4. Serial Channel: The Serial Channel window displays the contents of serial
port registers and control bits as well as the baudrate.

Setting Breakpoints

A breakpoint is used to halt a program run at a certain code address. You can
simply set a breakpoint anywhere by double-clicking on an instruction line.
Once the breakpoint is set, a breakpoint number [BR n] presents at the right
end of the instruction line as shown below. The dScope supports up to 40
simultaneously active breakpoints.

Color Setup
Open the Color Setup window using [Setup\Colors and fonts] command. In
this window you can set the background color and text color of the selected
window. To set font, click the [Select Font>>>] button.

Program Debugging Procedure

1. Select CPU driver.

2. Load HEX file or project file created by uVision-51 to dScope-51 for
simulating and debugging.
3. Show the required windows.
4. Run the program and observe the results by setting appropriate
breakpoints and single stepping.


μVision-51 is an integrated development environment that is a combination of

a project manager, integrated make facility, dialogbox tool configuration, and
text editor. Basically μVision-51 consists of assembler (A51.EXE), code
banking linker (BL51.EXE), object-to-hex converter (OH51.EXE), etc.
Associated with the dScope-51 debugger/simulator, 8051 programs can be
developed by following the flow shown below.

Extensions of files created by uVision-51 are:

Source file: .A51

Object file: .OBJ
Listing file: .LST
Executable file: no extension
Intel HEX file: .HEX

Text Editor

Source Assembly

A51 Assembler

Object Listing
(.OBJ) (.LST)

BL51 Linker

Machine Code

OH51 Converter

Intel HEX dScope-51



Run μVision-51 by executing Start\Programs\Keil PK51-Eval\uVision-51 and
open the μVision/51 evaluation window. The mainframe window hosts the
main menu, a toolbar with shortcuts for menu entries, and a statusbar located
on the bottom of the mainframe window for showing a short description text for
each menu entry.

Toolbar Buttons:
New file
Update A Project
Build All
Tile Horizontally Command
Tile Vertically Command
Debug (dScope-51)

To create a new source file, use [File\New] command to open the editor
window as shown below.

Now you can write a source program in the working area. Then save the
source file onto the disk using the [File\Save As] command and select .A51
extension for assembly source and .C for 8051 C source.

Create A New Project

Use the [Project\New Project…] command to open the Create New Project
dialog box as shown below. Select drive and folder, enter the filename and
click OK.

Project dialog box is shown below. The project source files and options are

Select a source file to be added to the current project and then click Add
button. The Add File to Project dialog box is shown below.

Select drive, folder, source file, and click Add button to add the files selected to
the current project. Click Close button and return to Project dialog box.
Click Save button to save the current project.

Some options of A51 Assembler, BL51 Linker, dScope-51 Debugger, and

Make must be first selected before executing the μVision-51.

(1) Create a DSCOPE.INI file

Execute a word processing program and edit a file containing the
command line:
and save as DSCOPE.INI to the current directory. Switch to the
directory where 8051 source and project files exist. At DOS prompt,
enter the command lines:

Then press Ctrl+Z keys. This file is used for loading 8051 driver.

(2) A51 Assembler Options

Using [Options\A51 Assembler…] command open A51 Assembler
Options dialog box. The A51 Assembler Options dialog box lets you
select options the assembler uses when it creates listing files and
object files from your source files. Three groups of options are
available in this dialog box: Listing options, Object options, and
Miscellaneous options. The Listing thumb tab shows the options that
control how the assembler generates the listing file.

The Object thumb tab shows the options that control how the
assembler generates the object file.

The Misc thumb tab shows miscellaneous assembler options.

(3) BL51 Code Banking Linker options

Use [Options\BL51 Code Banking Linker…] command to open BL51
Code Banking Linker dialog box. The BL51 Code Banking Linker
dialog box lets you select options the linker uses when it creates your
executable target file. Six groups of options are available in this
dialog box: Listing options, Linking options, Size/Location options,
Additional options, Segments options, and Files options.

The Listing thumb tab shows controls the linker uses when creating a
map or listing file.

The Linking thumb tab shows controls the linker uses when creating an
absolute object module or a banked object module.

The Size/Location thumb tab shows controls that specify the size or
location of different memory areas.

(4) Make Options
Use [Options\Make…] command to open the Make Options dialog box.
The Make Options dialog box lets you select options for the make
process. Four groups of options are available in this dialog box: After
Compile options, After Make options, Misc options, and Extensions

The After Compile thumb tab shows what μVision-51 does after all files
in the project are assembled and compiled.

The After Make thumb tab shows what μVision-51 does after all files in
the project are processed and the linker, library manager, and object

converters have been run.

The Extensions thumb tab shows the file extensions used by your
source and library files.

(5) dScope Debugger options

Use [Options\dScope Debugger…] command to open dScope
Debugger Options dialog box. Specify DSCOPE.INI for the dScope
debugger as shown below.

Compiling and Linking
Once a project is created, the project can be complied and linked with the
[Compiler File], [Make-Update Project], and [Make-Build Project] commands in
Project menu.

(1) Compile File command is used to assemble project source and create
(2) Make-Update Project command is used to assemble project source
and link object and create executable and HEX files.
(3) Make-Build Project command is used to assemble project source and
link object and create executable and HEX files.

The Project Status window shows a HEX file created successfully.

If syntax errors occur, ERR window will be shown and the error instruction line
is colored.

To debug the project, enter dScope-51 by using [Run\dScope Debugger…]
command. Open Command window and enter [LOAD filename] command
line. The source program will be shown in Debug window.

Procedure of Project creation and simulation

1. Edit and save a source file.

2. Create a project and add source file to the project.
3. Create executable and HEX files using [Project\Make-Update Project] or
[Project\Make-Build Project] command.
4. Enter dScope-51 for simulating and debugging.
5. Re-edit source file and repeat steps 3 and 4 if necessary.