Keil MDK signal function

Source: Internet
Author: User

The Keil signal function is used to simulate and Test serial Io, simulate Io, port communication, and other repeated external events.

The signal function starts with the keyword signal. In a function, twatch must be called for latency. Otherwise, Keil will be in an endless loop. The parameter of the twatch function indicates the CPU execution cycle to be delayed. For example, twatch (1000000) indicates that a signal function delays 1000000 CPU cycles.

Signal Functions are subject to the following constraints:

  • The Return Value Type of the function must beVoid.
  • A function can have a maximum of eight parameters.
  • Signal Functions can call other redefinition functions and user functions.
  • Signal Functions cannot call each other.
  • Signal functions can be called by user functions.
  • The signal function must be called.TwatchAt least once. If the signal function is never calledTwatch,The target program cannot be executed in time. And because it cannot be usedCTRL + cInterrupt signal function. In this case, µvision3 will enter an endless loop.

1. Create a function

There is a built-in function editor in Keil, which can be opened through debug -- function editor. When opening the function editor, you must enter a file name or open a file specified by options for target -- debug initialization file.

2. Edit the example.

In the following example, enter a square wave shown in figure on the platinum 8 pin of the lpc2114.

// Add two 1 K waves in the low half cycle of the Hz square wave. // signal void test (void) {While (1) {port0 | = 0x100; // latency 8 sets high twatch (11059200*4/400); // latency 2.5 ms (200Hz) port0 & = ~ 0x100; // twatch (11059200*4/400) with a low latency of 2.5 ms (200Hz); // port0 | = 0x100; // listen 8 sets high twatch (11059200*4/400); // delay 2.5 ms (200Hz) port0 & = ~ 0x100; // twatch (11059200*4/400) with a low latency of 2.5 ms (200Hz); // port0 | = 0x100; // listen 8 sets high twatch (11059200*4/400); // delay 2.5 ms (200Hz) port0 & = ~ 0x100; // reset 8 low twatch (11059200*4/2000); // delay ms (800Hz) port0 | = 0x100; // listen 8 sets high twatch (11059200*4/2000); // delay 2.5 ms (400Hz) port0 & = ~ 0x100; // twatch (11059200*4/2000) with a low latency of 2.5 ms (800Hz); // port0 | = 0x100; // listen 8 sets high twatch (11059200*4/2000); // delay 2.5 ms (400Hz) port0 & = ~ 0x100; // p0.8 low twatch (11059200*4/2000); // latency 2.5 ms (800Hz )}}

3. Compile

On the signal function editing page, click the compile button, and a prompt will be displayed if the compilation is successful or not.

4. Call the signal function

After compilation, enter the following command in the control window (command window) during software simulation:

Test ()

Note: test is the name of the signal function.

5. view the idle signal function

Use the signal State Command

6. Delete the signal function (take test () as an example)

Signal kill test or kill func Test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.