User`s manual

20 digi.com Quick Tutorial
The elapsed time message is printed by the costatement starting at the line marked (2). Costatements need
to be executed regularly, often at least every 25 ms. To accomplish this, the costatements are enclosed in a
while loop. The while loop starts at (1) and ends at (6). The statement at (3) waits for a time delay, in
this case 1000 ms (one second). The costatement executes each pass through the while loop. When a
waitfor condition is encountered the first time, the current value of MS_TIMER is saved and then on
each subsequent pass the saved value is compared to the current value. If a waitfor condition is not
encountered, then a jump is made to the end of the costatement (4), and on the next pass of the loop, when
the execution thread reaches the beginning of the costatement, execution passes directly to the waitfor
statement. Once 1000 ms has passed, the statement after the waitfor is executed. A costatement can
wait for a long period of time, but not use a lot of execution time. Each costatement is a little program with
its own statement pointer that advances in response to conditions. On each pass through the while loop
as few as one statement in the costatement executes, starting at the current position of the costatement’s
statement pointer. Consult Chapter 5 for more details.
The second costatement in the program checks to see if an alpha-numeric key has been pressed and, if one
has, prints out that key. The abort statement is illustrated at (5). If the abort statement is executed, the
internal statement pointer is set back to the first statement in the costatement, and a jump is made to the
closing brace of the costatement.
Observe the value of secs while the program is running.To illustrate the use of snooping, use the watch
window to observe secs while the program is running. Add the variable secs to the list of watch expres-
sions, then press <Ctrl+U> repeatedly to observe as secs increases.
3.4 Run DEMO4.C
The sample program DEMO4.C uses execution tracing. This is one of the advanced debugging features
introduced in Dynamic C 9. Tracing records program state information based on options you choose in the
Debugger tab of the Project Options dialog. The information captured from the target by Dynamic C’s
tracing feature is displayed in the Trace window, available from the Window menu. To make the target
send trace information, you must turn on tracing either from the
INSPECT menu or from within your pro-
gram using one of the macros described here.
To use this sample program, first go to the
Debugger tab of the Project Options dialog,
select Enable Tracing, and choose Full for
the Trace Level. Click OK to save and close
the dialog, then compile and run DEMO4.C.
When the program finishes, the Trace win-
dow will open and you can examine its
entries. The Trace window can be opened
anytime after the program is compiled, but execution speed is slightly affected if the window is open while
the program is running.