mikroICD Debugger Example

Here is a step-by-step mikroICD Debugger Example.




First you have to write a program. We will show how mikroICD works using this example :

program  Lcd_Test

' LCD module connections
dim LCD_RS as sbit at LATD0_bit
dim LCD_EN as sbit at LATD1_bit
dim LCD_D4 as sbit at LATB0_bit
dim LCD_D5 as sbit at LATB1_bit
dim LCD_D6 as sbit at LATB2_bit
dim LCD_D7 as sbit at LATB3_bit

dim LCD_RS_Direction as sbit at TRISD0_bit
dim LCD_EN_Direction as sbit at TRISD1_bit
dim LCD_D4_Direction as sbit at TRISB0_bit
dim LCD_D5_Direction as sbit at TRISB1_bit
dim LCD_D6_Direction as sbit at TRISB2_bit
dim LCD_D7_Direction as sbit at TRISB3_bit
' End LCD module connections

dim text as char[16]
       i as byte

main:
  ADPCFG = 0xFFFF
  text = "mikroElektronika"

  Lcd_Init()
  Lcd_Cmd(_LCD_CLEAR)
  Lcd_Cmd(_LCD_CURSOR_OFF)

  for i = 0 to 17
    Lcd_Chr(1, i, text[i-1])
  next i
end.

After successful compilation and MCU programming press F9 to start the mikroICD. After the mikroICD initialization a blue active line should appear.


We will debug the program line by line. Pressing [F8] we are executing code line by line. However, it is not recommended that user does not use Step Into [F7] and Step Over [F8] over Delays routines and routines containing delays. Instead use Run to cursor [F4] and Breakpoints functions.
All changes are read from MCU and loaded into Watch Window. Note that TRISB changed its value from 255 to 0.


Step Into [F7], Step Over [F8] and Step Out [Ctrl+F8] are mikroICD debugger functions that are used in stepping mode. There is also a Real-Time mode supported by the mikroICD. Functions that are used in the Real-Time mode are Run/Pause Debugger [F6] and Run to cursor [F4]. Pressing F4 executes the code until the program reaches the cursor position line.


Run(Pause) Debugger [F6] and Toggle Breakpoints [F5] are mikroICD debugger functions that are used in the Real-Time mode. Pressing F5 marks the line selected by the user for breakpoint. F6 executes code until the breakpoint is reached. After reaching the breakpoint Debugger halts. Here in our example we will use breakpoints for writing "mikroElektronika" on Lcd char by char. Breakpoint is set on Lcd_Chr and the program will stop every time this function is reached. After reaching breakpoint we must press F6 again to continue the program execution.

Breakpoints are divided into two groups: hardware and software breakpoints. The hardware breakpoints are placed in the MCU and provide fastest debugging. Number of hardware breakpoints is limited to 8 (6 instruction, 2 data). If all hardware brekpoints are used, then the next breakpoint will be software breakpoint. These breakpoints are placed inside the mikroICD and simulate hardware breakpoints. Software breakpoints are much slower than hardware breakpoints. These differences between hardware and software breakpoints are not visible in the mikroICD software but their different timings are quite notable.That's why it is important to know that there are two types of breakpoints.

The picture below demonstrates step-by-step execution of the code used in above mentioned examples.

  Common Errors :

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code