Keil Logo

µVISION DEBUGGER: Creating Input Signal Patterns

Information in this article applies to:

  • Keil MDK V4 and later
  • C166 Version 4.20 and later
  • C251 Version 3.20 and later
  • C51 Version 6.20 and later
  • µVision Version 2.20 and later


I need to simulate a sequence of values on a input pin. Is there an easy way to read data from an array, so that a sequence of values can be written to a variable on a breakpoint during simulation?


µVision provides a powerful scripting language that allows you to create complex input signals. The scripting language is identical to the C Programming Language with a few exceptions. One of these is that arrays are not directly supported. However, there are several workarounds for this limitation.

One technique for return values from an array is to use a simple debug function that is called periodically:

/* Define a global variable for indexing */
DEFINE unsigned int GetValIdx

/* Return a Value depending on a Index */
FUNC unsigned int GetValue ()  {
  GetValIdx = (GetValIdx + 1) %5;
  switch (GetValIdx)  {
    case 0:  return (0x55);
    case 1:  return (0xCA);
    case 2:  return (0xCB);
    case 3:  return (0xF5);
    case 4:  return (0x05);
    default: return (0x66);

Create a breakpoint invokes this function and assigns a new input value to P2 when your program enters the timer0 function (or any other function in your program). Define this breakpoint as follows:

BS timer0, 1, "P2 = GetValue()"

Of course, you could create a signal function that runs periodically. For example:

signal void setup_P2 (void) {
  while (1) {
    swatch (0.100);  /* Delay 0.1 seconds */
    P2 = GetValue ();  /* change P2 value */

Another technique involves using a specific memory area (S:, T:, U:, or V:) as an input array. Each of these memory spaces may be up to 64KBytes.

To use one of these memory areas, you must MAP it into the address space, define an index for it, and once again create a breakpoint or signal function to read values and assign them to P2 (in this case). For example:

/* Map the user specific memory space */

/* Define a global variable for indexing */
DEFINE unsigned int GetValIdx

/* Define a breakpoint that executions on each entry of timer0 */
BS timer0, 1, "P1 = _RBYTE (S:0 + GetValIdx++)"

The benefit of the specific memory spaces is that you can view and modify the values using the memory window. You may even load and save the contents of specific memory spaces in HEX files using the LOAD and SAVE commands. For example:

/* Store the content of the S: Space */

/* Restore the content of the S: Space */



Last Reviewed: Tuesday, December 15, 2020

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.