ARM Technical Support Knowledge Articles

USING THE PORTX VTREGS

Applies to: uVision Debugger

Answer


Information in this article applies to:


QUESTION

What is the PORT0/PORT1/PORT2/... VTReg and how do I use it?

ANSWER

The Keil uVision Simulator provides Virtual Target Registers (VTRegs) to support input to the I/O pins of the simulated device.

The PORTx VTRegs represent the inputs to the pins of the MCU for Port 0, Port1, Port2, and so on.

So, if you have configured an I/O port for input, the following commands (typed in the debugger's Command Window) may be used to set and then clear bits of an I/O port (bit 7 of port 3 in this example).

PORT3 |=  0x80  /* Set P3.7 */
PORT3 &= ~0x80  /* Clear P3.7 */

You may create signal functions that toggle port pins periodically, simulating a pulse train. For example:

signal void P3_toggles (void) {
  while (1) {
    PORT3 ^= 0x80;
    swatch (0.500);  /* wait for 1/2 a second */
  }
}

The following example shows how you can monitor the state of 2 port pins:

#include <reg167.h>
#include <stdio.h>

void main (void)
{
/*---------------------------------------------------------
Setup the serial port
---------------------------------------------------------*/

  P3  |= 0x0400;        /* SET PORT 3.10 OUTPUT LATCH (TXD)              */
  DP3 |= 0x0400;        /* SET PORT 3.10 DIRECTION CONTROL (TXD OUTPUT)  */
  DP3 &= 0xF7FF;        /* RESET PORT 3.11 DIRECTION CONTROL (RXD INPUT) */
  S0TIC = 0x80;         /* SET TRANSMIT INTERRUPT FLAG                   */
  S0RIC = 0x00;         /* DELETE RECEIVE INTERRUPT FLAG                 */
  S0BG  = 0x40;         /* SET BAUDRATE TO 9600 BAUD                     */
  S0CON = 0x8011;       /* SET SERIAL MODE                               */

/*---------------------------------------------------------
Setup Port 0H (bits 3 and 4) for Input
---------------------------------------------------------*/
DP0H &= ~((1 << 3) | (1 << 4));

/*---------------------------------------------------------
Read Port 0H.3 and 0H.4 and output the value
---------------------------------------------------------*/
while (1)
  {
  printf ("P0H.3 = %s  P0H.4 = %s
",
          ((P0H & (1 << 3)) ? "HI" : "LO"),
          ((P0H & (1 << 4)) ? "HI" : "LO"));
  }
}

SEE ALSO

Article last edited on: 2005-05-03 12:42:53

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential