|
|||||||||||
|
Technical Support Support Resources
Product Information |
Technical SupportµVISION DEBUGGER: USING THE PORTX VTREGSInformation in this article applies to:
QUESTIONWhat is the PORT0/PORT1/PORT2/... VTReg and how do I use it? ANSWERThe Keil µVision 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\n",
((P0H & (1 << 3)) ? "HI" : "LO"),
((P0H & (1 << 4)) ? "HI" : "LO"));
}
}
SEE ALSO
FORUM THREADSThe following Discussion Forum threads may provide information related to this topic. Last Reviewed: Tuesday, May 03, 2005 | ||||||||||
|
|||||||||||