Keil pure software simulation function

Source: Internet
Author: User
Tags open ini file

 

This article draws from http://blog.ednchina.com/likee/25421/category.aspx

 

We usually say that Keil's pure software simulation function is extremely powerful. to which extent is it powerful? In short, it can simulate almost all internal resources and peripheral I/O Ports.

 

 

As shown in, almost all Io ports, serial ports, I2C, SPI, and ad can be simulated. Haha, Is it strong enough? The following describes the simulation and adconverter of the downstream I/O Ports.

You can download the following software package for synchronization in combination with my example:

 

 

 

After downloading the SDK, You can compile the SDK directly. After compilation, there are no errors or warnings. Then you can click the red D button in debug, click peripherals, and select gpio, select port0 in the sub-menu (because in the program, I wrote the fl lamp on the corresponding port0 pin ). Click "run at full speed". Oh, did you find that the io0set's 16th-23rd bits are marked in sequence? This is because they are high in turn. If we connect LEDs (the anode is connected to the throttling resistor and then to the IO port, and the cathode is grounded) on the actual development board, in this way, our LED will flash and flash, like running water ~~~~~~~~

What about ad ing? We have an adconverter. First, we need to simulate a simulated voltage. After you click debug, do not run at full speed. Select function Editor (Open INI file) in the Debug menu. A prompt will be displayed to open a script file and add the following file:

The content of the script file is:

//

// Generate sine wave signal on ad channel 0

//

Signal void ain0 (void ){

Float volts; // peak-to-peak voltage

Float frequency; // output frequency in Hz

Float offset; // voltage offset

Float duration; // duration in seconds

Float val;

Long I, end;

 

Volts = 1.5;

Offset = 1.6;

Frequency = 1800;

Duration= 0.1;

 

Printf ("Sine Wave Signal on ad channel 0." N ");

 

End = (duration* 100000 );

While (1 ){

Val = _ Sin (frequency * (float) States)/clock) * 2*3.1415926 );

Ain0 = (Val * volts) + offset;

Swatch (0.00001); // in 10 USEC steps

}

}

Save, compile, and press below to run at full speed, and then open the logic analysis window. Do you see the sine wave at this time? You can't see it!

Why? Because we haven't added it to the simulated IO port yet! So how to add it? In the following window:

 

 

 

 

 

Let's take a look at the content of the above script. The function adds a sine wave signal to a pin called ain0, in the command window, enter the "dir Vreg" command to view the simulation resources of the simulated CPU. Then, we will add this function to the simulated port and enter the name of the script function: "ain0 ()". Does this result show a sine wave? See! How happy it is to see a sine wave jumping and jumping!

Overall:

 

 

Related Article

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.