Saving Data in Keil
Saving Data in Keil
Example: I wish to save the contents of the following array of 16 8-bit data values.
Method 1:
Display the values in the command window while logging them to a file. In the command window, create a log file
and “dump” the contents of the array or memory block:
Method 2:
Write the values in any desired format to a file via a user-defined function in the debugger. The function can be
invoked from the µVision command line or from a button in the toolbox. Define a function in the µVision Function
Editor (see Figure 1), which is opened from the Debug menu (Debug > Function Editor). Enter the function, compile it,
and save it in an “initialization file” (eg. displayvalues.ini). The function in Figure 1 will create a log file, print the contents of
array keys[] to the file, using the format in the printf statement, and then close the log file.
Figure 1. User-defined function to print the contents of array keys[] to log file MyValues.log.
The function is loaded into the debugger in one of two ways.
1. Specify the file in the field Options for Target — Debug — Initialization File. The file is loaded and processed each time
a debugging session is initiated.
2. Use the INCLUDE command during a debugging session to read and process the file.
>INCLUDE displayvalues.ini
Debug functions defined in this file are made available for use during the debugging process.
While the simulator is stopped, the function can be invoked in the µVision command line:
displayvalues() // function invocation
or you can define a button in the toolbox to start the function:
define button "Log Array", "displayvalues()"
For more efficient post-processing of the data in the saved file, the formatting in the printf statement can be changed, along
with the file extension, to essentially make what you export a .csv (comma-separated values) file, which can be directly
imported into Excel or MATLAB
Method 3:
Enter the “save” command in the command window to save addresses and data to an “Intel hex” file, from which the data can
be extracted.
Save keys.hex &keys[0], &keys[15] -- write data between the two addresses