using mikroicd 6 - lib.chipdip.rulib.chipdip.ru/189/doc000189201.pdf · using mikroicd 6 program...
Post on 14-May-2018
231 Views
Preview:
TRANSCRIPT
mikroICD overview 4
Hardware 4
Software 5
Using mikroICD 6
Program writing 6
Setting up the project for ICD debugging 7
Program compilation 8
Writing program to MCU 9
Starting mikroICD Debugger 10
mikroICD Debugger Options 11
Practical example of using mikroICD 12
mikroICD Debugger Options 16
Real-Time Debugging 16
Breakpoints 16
Watch Window 18
Disassembly view 19
EEPROM Window 20
View Code Window 21
View RAM Window 22
TABLE OF CONTENTS
mik
roIC
D
mikroICD overviewmikroICD is designed for debugging purposes. It enables you to monitor on your PC
the state of all registers within the built in microcontroller while it operates in real envi-
ronment. To use this feature successfully, it is necessary to own the appropriate hard-
ware and software for communication and programming.
HardwaremikroICD is a part of PICflash programmer and as such it is built in all development
systems designed by MikroElektronika (EasyPIC5 EasyPIC4, BigPIC4, PICPLC8Aetc.). In addition to that, mikroICD is a part of a stand-alone PICflash programmer as
well. It has a double purpose. It is used for PIC microcontroller programming as well as
to check program execution in real environment (debugging). In both cases, chip which
is programmed can be built in the target device (soldered).
4
PICflash programmer built
in EasyPIC5 development
system.
Target device connected to stand-alone
PICflash programmer.
mik
roIC
D
The microcontroller is connected to the programmer via RB6, RB7 and MCLR pins.
In case the programmer is used only for programming, immediately after downloading
the hex code, built-in hardware automatically breaks connection with these pins which
can be further used as per program.
In case it is necessary to test and debug a program in real environment it is actually
necessary to monitor the state of all registers within the microcontroller. Debugger
also offers more sophisticated functions such as running a program step by step (sin-
gle stepping), stopping (pausing the program execution to examine the current regis-
ters state) by means of breakpoint etc. In that case, since the mikroICD communi-
cates with the PC all the time, the RB6 and RB7 pins cannot be used for the target
device operating.
Software
In order to enable you a successful use of mikroICD, MikroElektronika has developed
additional software which must be installed on PC:
PICflash v7.02 (or later) is a program designed to operate along with PICflash pro-
grammer hardware. You can download it for free from our web site www.mikroe.com.
It is used to select the microcontroller to program and set up its modes.
Drivers for the PICflash programmer operation. This software enables communica-
tion between PC and PICflash programmer’s hardware.
Compilers: mikroC v6.0 (or later), mikroBasic v5.0 (or later) and mikroPascalv6.0 (or later). Such programs are used for compiling high-level program languages
into executable file (HEX code). All these compilers are designed by MikroElektroni-
ka and support ICD debugger. Their demo versions can be downloaded for free from
our web site too.
5
mik
roIC
D
Using mikroICD
mikroICD is supplied with most of compilers designed by MikroElektronika. This man-
ual illustrates the way it operates in mikroBasic. The same applies on compilers
mikroC and mikroPascal.
Program writing
First of all, you should create a new project and write a program within it.
6
MikroICD Main Window
mik
roIC
D
Setting up the project for ICD debugging
In order to set up your project for using mikroICD and Software simulator, you have
to select the appropriate options in the Project Setup window.
7
Select Release build type in case you do not
want to use mikroICD after programming.
Select mikroICD Debug build type in case you
want to use mikroICD after programming.
If you want to use software simulator after programming,
select the Software Simulator option.
If you want to use mikroICD debugger after pro-
gramming, select the second option.
mik
roIC
D
Program compilation
Prior to download into MCU, the program should be compiled into machine code. This
process is called program compilation. In order to start it, press the appropriate short-
cut buttons or select one of the following options from the Project drop-down menu:
Build [Ctrl+F9] If the project consists of one file
Build All [Shift+F9] If the project consists of several files.
Build+Program. [Ctrl+F11] If you want PICflash programmer to be automatically
activated after compiling. In this case, the compiled
program will be automatically loaded into the MCU
program memory.
8
Build options
mik
roIC
D
Writing program to MCU
After successful compilation, it is time to write the program to PIC microcontroller. It
can be done in two ways- by pressing [F11] or selecting Tools > PicFlash Program-mer from the drop-down menu.
PICflash program window will appear and the compiled program will be automatical-
ly written to MCU. After that, the window will be automatically closed.
9
PICflash Programmer activation
PICflash Main Program
Window
mik
roIC
D
Starting mikroICD Debugger
After successful PIC programming you have to start mikroICD by selecting the StartDebugger option from the Run drop-down menu.
Since this moment, mikroICD enables you to directly monitor the state of all registers
within the microcontroller. In addition, starting the mikroICD makes more control
options available to you. Some of the most frequently used are: Step Into, Step Over,Run to Cursor and Step Out.
10
Start Debugger option
Watch window enables monitoring MCU
registers and program variables.
Yellow line indi-
cates that micro-
controller is run-
ning.
mik
roIC
D
mikroICD Debugger Options
mikroICD has several integrated options listed in the table below:
11
Name Description Function key
Debug Starts Debugger. [F9]
Run/Pause debugger
Runs or pauses program execution and debugging. [F6]
Toggle Breakpoints
During debugging, program is executed until a breakpoint is reached. At that point, the Toggle Breakpoints option sets new breakpoints or removes those already set at the current cursor position. To view all the breakpoints, select Run >View Breakpoints from the drop-down menu. Double click on an item from the list locates the breakpoint.
[F5]
Run to cursor Program is executed until the cursor position is reached.
[F4]
Step Into
Executes the current C/Pascal/Basic (single- or multi-cycle) program line, then halts. If the program line is a routine call, steps into the routine and halts at the first instruction within it.
[F7]
Step Over
Executes the current C/Pascal/Basic (single- or multi-cycle) program line, then halts. If the program line is a routine call, enters the routine and halts at the first instruction following the call.
[F8]
Flush RAMFlushes current PIC microcontroller RAM. All RAM memory values will be changed according to values in the Watch window.
-
Stop Debugger
Stops Debugger. [Ctrl+F2]
Step Out Executes all remaining program lines within the subroutine. It halts immediately upon exit from the subroutine.
[Ctrl+F8]
Disassembly View
Instead of program written in high-level program language (Basic in this very case), the assembly version of the same program will appear. Each program line written in Basic is divided in assembly instructions executed by the microcontroller.
[Alt+D]
PR
AC
TIC
AL
EX
AM
PLE
Practical example of using mikroICD
Here is a step-by-step illustration of the operation of mikroICD:
Step 1: Example program writing
First of all, you have to write a program. In this example, it is a simple program which
demonstrates the operation of LCD display.
program Lcd_demo
dim text as string[20]dim i as byte
main:text = "mikroElektronika"ANSEL = 0 ' Configure AN pins as digitalANSELH = 0 ' on PIC16F887Lcd_Config(PORTB,3,2,1,0,PORTB,4,6,5) ' Lcd Init EasyPIC5Lcd_Cmd(LCD_CLEAR) ' LCD command “clear display”Lcd_Cmd(LCD_CURSOR_OFF) ' Send command “cursor off”for i = 1 to 16Lcd_Chr(1,i,text[i-1]) ' Print txt to LCD, 2nd row, 1st columnnext i
end.
Step 2: Setting up the example project for ICD debugging
After program compilation, you can proceed with its execution in two ways:
If you want MCU to execute the program at full speed by not
affecting the operation, select the Release option in Project
Setup Window.
If you want MCU to execute the program by using debugger,
select the mikroICD Debug option in the same window.
12
Program example
PR
AC
TIC
AL
EX
AM
PLE
Step 3: Example Program Compilation
In order to compile the example program into machine code, select the Build option
from the Project drop-down menu.
Step 4: Writing example program to MCU
The compiled example program
(HEX code) is automatically written
to the microcontroller by selecting
the mE Programmer option from the
Tools drop-down menu.
13
PR
AC
TIC
AL
EX
AM
PLE
Step 5: Running mikroICD
The example program is now written to the microcontroller. Its execution in real envi-
ronment can be monitored by using
mikroICD debugger. To start it, select the
Start Debugger option from the Run drop-
down menu or click [F9] button.
Step 6: Line-by-line program execution
The example program will be executed line by line by pressing the button [F8]. It
means that every time you press the button [F8], MCU on the target device will exe-
cute one program line and halts afterwards.
14
During operation, the program
line being currently executed is
colored blue by default.
PR
AC
TIC
AL
EX
AM
PLE
The state of all registers within the PIC microcontroller can be read from Watch Win-dow.
As can be seen on the picture above, the program has reached the 15th line after
LCD initialization. That line is used for writing characters on LCD:
Lcd_Chr(1,i,text[i-1]).
If you press [F8] (Step Over) again, the program will execute
specified function and “m” will be written on LCD.
If you press the same button again, program will remain in
the same loop for writing characters and the letter “i” will be
written just after the letter “m”. Now, there is “mi” on your
LCD.
If you continue pressing [F8] (Step Over), the third let-
ter will be written on LCD. By proceeding with it, you
will reach the end of the loop, as well as the end of
this simple program. The result will be the word
“mikroElektronika” written on your LCD.
15
Monitored registers
mik
roIC
D D
EB
UG
GE
R O
PT
ION
S
mikroICD Debugger Options
Real-Time Debugging
By using commands Step Into [F7] and Step Over [F8], program will be executed line
by line. It results in slow program execution and as such is convenient for shorter pro-
grams. Unlike them, the commands Run/Pause Debugger [F6] and Run To Cursor[F4] are much faster since they execute program in real time. The speed of execution
is determined by the microcontroller own clock.
By pressing [F6] or selecting the
Run/Pause Debugger option,
mikroICD is temporarily halted and
the microcontroller executes the
loaded program at full speed. After
another press on the same button
mikroICD is reactivated and the pro-
gram execution stops at reached loca-
tion.
By pressing [F4], the microcontroller
will proceed with program execution
at high speed until it reaches the line
selected by cursor.
Breakpoints
When using mikroICD, each program line can be marked with a breakpoint. It is an
intentional stopping or pausing place in a program, put in place for debugging pur-
poses. Therefore, the program is interrupted by encountering a breakpoint. There are
two kinds of breakpoints-hardware and software breakpoints. The only visible differ-
ence between them is in the speed of program execution until the specified program
line. Hardware breakpoints are placed inside the microcontroller chip and provide
considerably faster program execution. Number of hardware breakpoints is limited-
16-bit PIC microcontrollers have only one, whereas those 18-bit PIC microcontrollers
have up to 3 such breakpoints. If all hardware breakpoints are used, each next break-
point will be software one. The total number of software breakpoints is unlimited.
16
mik
roIC
D D
EB
UG
GE
R O
PT
ION
S
Breakpoints are placed in the program by clicking the space to the left of the program
line or by pressing [F5] which marks the line selected for breakpoints by the user. By
selecting the Run command [F6], the microcontroller executes program from the cur-
rent location (colored blue) until it reaches a breakpoint (colored red). After a break-
point is reached, debugger halts.
17
Program line being
currently executed
Breakpoint in
the program
mik
roIC
D D
EB
UG
GE
R O
PT
ION
S
Watch WindowDebugger Watch window allows you to monitor values of variables in the program as
well as the contents of SFRs while the program is running. As soon as the program
is written to the micocontroller, this window automatically appears on the screen. If
you remove it and want to show it again, select the Debug Windows > Watch Win-dow option from the View drop-down menu.
Watch Window displays data in three columns: register or variable names, their val-
ues and memory addresses.
Double click on some variable opens the Edit Valuewindow in which you can assign a new value to it. On
such change, it is possible to select data format (deci-
mal, hexadecimal, binary, floating or character).
18
Add selected value
to the list
Debugger - START
Debugger RUN/PAUSE Debugger STOP Step into [F7] Step over [F8]
Run to cursor [F4]
Step out [Ctrl+F8]
Remove selected
value from the list
Change format of
selected variable
Selected
variable
Add all variables to
the list
Remove all variables
from the list
Watch Window view option
Edit Value Window
mik
roIC
D D
EB
UG
GE
R O
PT
ION
S
Disassembly view
During compiling, each program line written in high-level program language is
replaced by one or more assembly instructions. To display program in assembly
language, select the Disassembly View option from the Debugger drop-down menu.
In this case, simulation and debugging are performed in the same way as if the pro-
gram is written in high-level language.
19
Program written in high level language...
...the same program written in assembly language
mik
roIC
D D
EB
UG
GE
R O
PT
ION
S
EEPROM Window
mikroICD EEPROM Window is available from the drop-down menu View > DebugWindows > EEPROM. It shows current values written into PIC internal EEPROM
memory.
There are two action buttons in this window used to access EEPROM- ReadEEPROM and Write EEPROM..
Read EEPROM reads memory locations from the chip and shows them in
EEPROM window.
Write EEPROM writes data from EEPROM window into PIC internal EEPROM
memory.
20
EEPROM Window
mik
roIC
D D
EB
UG
GE
R O
PT
ION
S
View Code Window
The contents of the PIC microcontroller program memory (HEX code) can be
viewed from the mikroICD View Code Window available from the drop-down menu
View > Debug Window > Code. There is one action button in the upper left corner
of this window referred to as Read Code. By clicking it, mikroICD will read the code
from PIC and display it in View Code Window.
21
Code Window
mik
roIC
D D
EB
UG
GE
R O
PT
ION
S
View RAM Window
mikroICD allows you to view the contents of the microcontroller’s RAM memory in
RAM window available by clicking the Debug Window > RAM option from the Viewdrop-down window. Unlike the Watch Window, all memory locations are displayed in
the table. The content of each RAM location is displayed in hexadecimal format and
may be changed any time during operation. Changed values are directly written to
the microcontroller by clicking “Enter”.
22
RAM Window
top related