Friday, July 14, 2006

Pushing my button

It seems I can waggle the pins using the PORT0 variable in much the same way as I can waggle the GPIO under program control. Looking in the manual, the keyword "signal" hooks the function that succeeds it into the simulator so that it runs alongside the simulation. The manual says there's a bunch of stuff I can do with this to simulate signals coming in with specific intervals. The swatch and twatch functions can pause a running signal function for seconds or CPU states respectively.

So the signal function in the Traffic example sets pin P0.14 low, lets the simulation run on for a simulated 50 milliseconds and then takes P0.14 high.
A quick hack of this code and I get a button for my code:

PORT0 = 0x00000001; /* set P0:1 low: Key Input */
/* define a debug function for the push button */
signal void push_button (void) {
PORT0 &= ~0x00000001; /* set P0:1 low */
swatch (0.05); /* wait 50 msec */
PORT0 = 0x00000001; /* set P0:1 high */
}

/* define a toolbar button to call push_button */
define button "Push my button", "push_button ()"



You can try this example by downloading it here

2 Comments:

At 3:08 AM, Anonymous Anonymous said...

Very nice example.
Where did the PORT0 defined, so it can be recognized by the simulator?
I have tried in simulator and got "undefined identifier" for PORT0 register.

 
At 5:00 PM, Blogger Rod said...

Hmm... what MCU are you developing for? I chose the LCP2148 when I created my project. This tells the simulator that there is a Virtual Simulation Register, i.e., an internal constant known to the simulator, called PORT0, which de-references to 0xF2FFFFFF.

You can test this by creating a very simple project for the LPC2148 which looks like this:

int main (void) {}

Build this for simulation and enter the debugger.

At the debugger's command prompt enter

PORT0

this should be reflected as:

0xF2FFFFFF

If you chose a different MCU, PORT0 may either have a different value or may in fact not exist at all!

For a full list of all of the Virtual Simulation Registers defined for a particular MCU type:

DIR VTREG

This is explained in further detail at the online uVision manual here:
http://www.keil.com/support/man/docs/uv3/uv3_db_exp_periphlvar.htm

 

Post a Comment

<< Home