Thursday 21 March 2013

Debugging the circuit.


Debugging the circuit.

Starting a Debug Session
The first task here is to set a breakpoint in the program code from within the Keil IDE. A suitable point would
be the entrance to the LCD initialisation routine so select calc.c from the left hand pane and place the mouse
cursor on the line with the code:
initialise(); // Initialize the LCD
From the Debug menu select the Insert/Remove Breakpoint command – you should now see a red rectangle
at the start of the line which represents the breakpoint.
Note: If you want to specify a shortcut key for this or any other commonly used functions you do so via the
Options command on the View menu.
Now select the Start/Stop Debug Session option from the Debug menu. This will initialise the debug session
and should have two noticeable effects.
1.The main Keil window will change and display an assembly language listing. A small yellow arrow on the
left hand side will indicate the current instruction as dictated by the breakpoint. The left hand pane of the
Keil window will change to display the register bank and system registers.
2.Simulation will start in ISIS and then pause prior to execution of the instruction specified by the
breakpoint. The status bar at the bottom of the application window will display the amount of time that
the simulation has run and the PC value when the breakpoint is reached.
Note: If you are running both applications on the same computer you can toggle between them using
ALT+TAB.
Additional Debug Information
The Peripherals menu in the Keil IDE allows you to view the status and values of the Interrupt System,
Timers, IO Ports, A/D Converter and the Serial Peripheral Interface. Additionally, you can look at the
memory contents and use the Watch Window via the View menu.
ISIS provides a series of popup windows accessible from the Debug menu which allow you to view memory
contents register values as well as use the configurable Watch Window. The values displayed in these
should of course be identical to those in the Keil environment at any stage of the simulation and as such you
can use either or both according to your personal preferences.
Another useful feature of ISIS is that you can visually display the logic states of the pins throughout the
simulation. This option is accessible through the Set Animation Options command on the Template menu
and provides an excellent snapshot of the state of the circuit.
Note: Both ISIS and Keil use highlighting to indicate that the value of an item in the watch window (or a
register in the left pane of the Keil IDE) has changed since the last paused state.
Debugging Commands
The following commonly used debugging commands are available within the Keil environment.
Go
When paused this command will release the simulation back into free running mode.
Step
When paused this command will advance the simulation by one instruction.
Step Over
When paused this command will step over the current instruction and pause at the following instruction.
Step Out of Current Function
When paused this command will exit the current routine pausing at the instruction subsequent to the return.

Run to Cursor Line
When paused this command will release the simulation into free running mode until the line of code where
the mouse cursor is currently positioned is reached.
Stop Running
When running this command will pause the simulation at the instruction currently being executed.
It is important to realise that these commands operate at the level of the 8051 assembly language and not at
the level of the C source file. A Step Over command, for example, will not advance the simulation over the
current line in the C file but rather step over the current instruction as shown in the disassembly window.

No comments:

Post a Comment