Megawin 8051 OCD ICE User manual

This document information is the intellectual property of Megawin Technology Co., Ltd. 1
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
Megawin
8051 OCD ICE
User Manual

This document information is the intellectual property of Megawin Technology Co., Ltd. 2
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
Contents
1 Introduction.................................................................................................... 3
Features..........................................................................................................................................3
Description......................................................................................................................................3
2 Hardware Setup............................................................................................. 4
3 Software Setup.............................................................................................. 6
3.1 Install the USB Device Driver for the ICE Adapter...................................................................6
3.2 Install the Megawin 8051 Database in the Keil 8051 IDE Software..........................................6
4 Keil IDE Setup ............................................................................................... 7
4.1 Options- Device.......................................................................................................................8
4.2 Options- Target.......................................................................................................................8
4.3 Options- Output.......................................................................................................................9
4.4 Options- C51...........................................................................................................................9
4.5 Options- Debug.....................................................................................................................10
4.6 Options- Utilities....................................................................................................................11
5 Start Debugging........................................................................................... 12
5.1 Activate the dScope-Debugger Function...............................................................................12
5.2 Introduction to the Debugger Environment ............................................................................13
5.2.1 Reset/Run/Halt/Step/Run-to-Cursor ..............................................................................................14
5.2.2 Source-Level Debugging................................................................................................................14
5.2.3 Breakpoint Setting..........................................................................................................................15
5.2.4 View/Edit the Contents of Peripherals’ SFRs.................................................................................16
5.2.5 View- Disassembly Window...........................................................................................................17
5.2.6 View- Watch Window.....................................................................................................................18
5.2.7 View- Memory Window ..................................................................................................................19
6 Tools, Megawin ICP..................................................................................... 20
6.1 About ICP............................................................................................................................20
6.2 Use ICP...............................................................................................................................20
6.2.1Update Programmer.......................................................................................................................21
6.2.2Update Target ................................................................................................................................26
7 Special Notes............................................................................................... 27
7.1 Register Definition Files.........................................................................................................27
7.2 On-chip XRAM and External Data Memory ...........................................................................27
7.3 Code Optimization and Source-Level Debugging..................................................................28
7.4 “for-Loop” and Source-Level Debugging................................................................................29
7.5 Hardware Option Requirements During Debugging...............................................................29
7.6 Error Message.......................................................................................................................30
7.7 Properly Connect the ICE Adapter to a Host .........................................................................31
Revision History................................................................................................ 32

This document information is the intellectual property of Megawin Technology Co., Ltd. 3
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
1 Introduction
Features
Megawin proprietary OCD (On-Chip-Debug) technology
On-chip & in-system real-time debugging
Two-pin dedicated serial interface for OCD, no target resource occupied
Directly linked to the debugger function of the Keil 8051 IDE Software
USB connection between target and host (PC)
Helpful debug actions: Reset, Run, Stop, Step and Run to Cursor
Programmable breakpoints, up to 4 breakpoints can be inserted simultaneously
Several debug-helpful windows: Register/Disassembly/Watch/Memory Windows
Source-level (Assembly or C-language) debugging capability
Description
The all new “Megawin 8051 OCD ICE”is a powerful development tool for 8051 embedded system. By adopting
the Megawin proprietary OCD (On-Chip-Debug) technology, this ICE provides on-chip and in-system real-time
debugging. The user has no need to prepare any development board during developing, or the socket adapter
used in the traditional ICE probe. All the thing the user needs to do is to reserve a 6-pin connector for the
dedicated OCD interface: VCC, OCD_SDA, OCD_SCL, RST,CLK and GND.
In addition, the most useful feature is that it can directly connect the user’s target system to the Keil 8051 IDE
software for debugging, which directly utilizes the Keil IDE’s dScope-Debugger function. Of course, all the
advantages are based on your using Keil 8051 IDE software.
Note:
“Keil”is the trade mark of “Keil Elektronik GmbH and Keil Software, Inc.”, and “Keil 8051 IDE software”is the
most popular C51 compiler for 8051 embedded system development.

This document information is the intellectual property of Megawin Technology Co., Ltd. 4
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
2 Hardware Setup
For debugging, the user should connect the target system to a PC via the ICE adapter, as shown below. The ICE
adapter is a bus-powered USB device, and therefore there is no need of a power adapter for it.
Hardware Connection Diagram
Note: Refer to Section 6.5 for more information.
OCD ICE Interface Pin Number
Part No.
Package
OCD_SCL
OCD_SDA
RST
CLK
MPC82G516
40-pin DIP
29
30
N/A
N/A
44-pin PLCC
32
33
N/A
N/A
44-pin QFP
26
27
N/A
N/A
MG82FL(E)532/564
44-pin QFP
26
29
4
5
48-pin LQFP
28
32
5
6
MG84FG516
48-pin LQFP
26
27
25
N/A
64-pin LQFP
34
35
33
N/A
MG82FG5A32/5A64
48-pin LQFP
26
27
25
N/A
64-pin LQFP
34
35
33
N/A
MG82FG5Bxx
28-pin SOP
27
28
26
N/A
32-pin LQFP
18
19
17
N/A
MG82FG5Cxx
48-pin LQFP
26
27
25
N/A

This document information is the intellectual property of Megawin Technology Co., Ltd. 5
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
64-pin LQFP
34
35
33
N/A
MG82FG5Dxx
16-pin SOP
15
16
14
N/A
20-pin SSOP
19
20
18
N/A
**N/A : No need to connect

This document information is the intellectual property of Megawin Technology Co., Ltd. 6
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
3 Software Setup
This section tell the user how to do software setup before using the OCD ICE.
3.1 Install the USB Device Driver for the ICE Adapter
The user just needs to plug the ICE adapter into any USB port in a PC. There is no need to install any device
driver for the ICE adapter.
3.2 Install the Megawin 8051 Database in the Keil 8051 IDE Software
Activate the “Setup.exe”in the folder [Database Installer] to open the Database Installer Application Program to
install the Megawin Database into the Keil 8051 IDE software. Of course, you should have installed the Keil 8051
IDE software, either μVision2 or μVision3, in your PC previously.
After opening the Database Installer, please follow the steps shown in the following GUI figure.
Step1) Click the Browse button to specify where the Keil software has been installed.
(Normally, when you install the Keil 8051 IDE software, the default install-path is "C:\KEIL".)
Step2) Click the Install button to start installing the Megawin Database into the Keil software.
GUI of the Database Installer

This document information is the intellectual property of Megawin Technology Co., Ltd. 7
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
4 Keil IDE Setup
Before using the dScope-Debugger function of the Keil IDE, the user should do some proper settings in the Keil
IDE. First, open the μVision project you would like to debug. Then, move cursor to “Target-..”and click the
mouse’s right button to invoke the “Options for Target”, as shown below.

This document information is the intellectual property of Megawin Technology Co., Ltd. 8
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
4.1 Options- Device
Select the “Megawin Device Database”and the target part number.
4.2 Options- Target
Enable the “Use on-chip ROM”and the “Use on-chip XRAM”.

This document information is the intellectual property of Megawin Technology Co., Ltd. 9
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
4.3 Options- Output
Enable the “Debug Information”. It is necessary for creating an absolute OMF file for source-level debugging.
4.4 Options- C51
Disable the code optimization by selecting “Level 0: Constant folding”. Refer to Section 6.3 for more information
about this setting. Note: This setting is optional.

This document information is the intellectual property of Megawin Technology Co., Ltd. 10
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
4.5 Options- Debug
Select the “Megawin On-Chip-Debug Driver”.
And, enable the “Load Application at Startup”and all the Cache Options.

This document information is the intellectual property of Megawin Technology Co., Ltd. 11
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
4.6 Options- Utilities
Always disable the “Update Target before Debugging”. It is because we have enabled the “Load Application at
Startup”shown in Section 4.5. And, leave the ”Use Target Driver for Flash Programming”don’t-cared.
Note: μVision2 doesn’t have this selection item.

This document information is the intellectual property of Megawin Technology Co., Ltd. 12
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
5 Start Debugging
After the tasks described in Sections 2, 3 and 4 have been done, you can start debugging your μVision project.
5.1 Activate the dScope-Debugger Function
After building the project (suppose no error), you can enter the Keil IDE’s debugger mode by clicking the dScope
button, as shown below. Now, the project code will be automatically downloaded into the target’s Flash. It will
take some time.

This document information is the intellectual property of Megawin Technology Co., Ltd. 13
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
5.2 Introduction to the Debugger Environment
There are four basic windows regarding the debugging operation in the debugger environment. They are Register
Window, Disassembly Window, Watch Window and Memory Window, as described below.
Register Window
This window shows the contents of the current register bank (R0~R7), the system registers (A, B, SP, DTPR and
the Program Counter) and the Program Status Word (PSW). The register with blue background means its content
is just changed due to the instruction just executed.
Disassembly Window
This window is the default window opened just when the debugger mode is entered. It shows the source-level
code followed by its corresponding assembly code.
Watch Window
This window automatically shows the local variables when Locals is clicked. The local variables are the variables
declared within a function including the main() function. To view the global variables, click Watch #1 or Watch #2
and type <F2> key to edit and enter the variable name. The variable with blue background means its content is
just changed due to the instruction just executed.
Memory Window
This window shows the contents of the memory located at the data/idata/xdata/code memory space. The
available commands are: d:0x00~d:0xFF, i:0x00~i:0xFF, x:0x0000~x:0xFFFF and c:0x0000~c:0xFFFF. The user
can view any of the four memory by entering the corresponding command.

This document information is the intellectual property of Megawin Technology Co., Ltd. 14
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
5.2.1 Reset/Run/Halt/Step/Run-to-Cursor
Reset, Run, Halt (Stop), Step and Run-to-Cursor are the basic debug actions. The user can easily invoke any of
these actions by clicking the short-cut buttons in the debugger GUI, as shown below.
5.2.2 Source-Level Debugging
To do the source-level debugging, open the source file by clicking Files to open the Project Workspace and
select the source files you want. Click Regs again to return to Register Window, as shown below.

This document information is the intellectual property of Megawin Technology Co., Ltd. 15
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
5.2.3 Breakpoint Setting
There are total four breakpoints available for debugging. Up to four breakpoints can be inserted simultaneously.
Insert/Remove a Breakpoint
Move the cursor to the front of the line and click the right key, then click “Insert/Remove Breakpoint”for toggling
between Insert and Remove, as shown below.
Enable/Disable a Breakpoint
Move the cursor to the front of the line and click the right key, then click “Enable/Disable Breakpoint”for
toggling between Enable and Disable. Of course, this line should have been inserted a breakpoint previously.

This document information is the intellectual property of Megawin Technology Co., Ltd. 16
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
5.2.4 View/Edit the Contents of Peripherals’SFRs
There are many peripheral SFRs that don’t belong to the registers shown in the Register Window. To view or edit
these registers, select the Peripherals item on the main menu. A pulled-down sub-menu will be displayed, and
the user can select a peripheral to view or edit its corresponding SFRs, as shown below.

This document information is the intellectual property of Megawin Technology Co., Ltd. 17
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
5.2.5 View- Disassembly Window
Disassembly Window displays source-level code followed by its corresponding assembly. To open this window,
select the View item on the main menu. A pulled-down sub-menu will be displayed, and then select
Disassembly Window, as shown below.
Maximize the Disassembly Window for detailed description:

This document information is the intellectual property of Megawin Technology Co., Ltd. 18
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
5.2.6 View- Watch Window
The Watch Window helps the user to check either local variables or global variables, as shown below.
To check the global variables, click Watch #1 or #2, then type <F2> key to enter the variable name.

This document information is the intellectual property of Megawin Technology Co., Ltd. 19
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
5.2.7 View- Memory Window
To open this window, select the View item on the main menu. A pulled-down sub-menu will be displayed, and
then select Memory Window, as shown below. The available commands are:
(1) d:0x00~d:0xFF, for ‘data’type
(2) i:0x00~i:0xFF, for ‘idata’type
(3) x:0x0000~x:0xFFFF, for ‘xdata’type
(4) c:0x0000~c:0xFFFF., for ‘code’type
The user can view any of the four memory by entering the corresponding command. Refer to Section 6.2 for how
to display ‘xdata’type variables.

This document information is the intellectual property of Megawin Technology Co., Ltd. 20
Megawin Technology Co., Ltd. 2014 All right reserved.
MEGAWIN
MAKE YOU WIN
8051 OCD ICE
User Manual, v3.00
6 Tools, Megawin ICP
6.1 About ICP
ICP is the acronym of In-Circuit Programming. Users can update the application code under the software control
without removing the mounted MCU chip from the actual end product. In addition, because the programming data
to be programmed to the target can be saved in the ICE adapter’s non-volatile storage, this stand-alone
programmer is able to work without host(PC) intervention. This feature is especially useful in the field without a
PC.
6.2 Use ICP
Here are the two ways of opening ICP application:
1. Execute “ICPProgrammer.exe” under “\C51\INC\Megawin\”of Keil’s Install folder.
2. Click “Tools\Megawin ICP” from Keil’s Menu bar.
Attention: To program ICP application correctly by means 2, users have to open Project and Build first.
Table of contents
Other Megawin Computer Hardware manuals
Popular Computer Hardware manuals by other brands

i-See
i-See IGEP COM AQUILA AM335x Hardware reference manual

Ebmpapst
Ebmpapst 8412 NGMI operating manual

SIGMA TEK
SIGMA TEK S-DIAS AI 084 instruction manual

WHISPER KOOL
WHISPER KOOL QUANTUM TWIN H.E. Series owner's manual

SMART-AVI
SMART-AVI SM-EHD quick start guide

Promise
Promise FastTrak SX4100 user manual