Use Keil2 software to simulate the time of delay statement

Publisher:自由漫步Latest update time:2022-05-24 Source: eefocusKeywords:keil2 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

First click option for target 'target1' under project

insert image description here

Change the crystal frequency to 11.0592MHz, which is consistent with the crystal frequency on the TX-1C test board

insert image description here

Then click the start/stop debug session button under debug to debug

insert image description here

The delay code is as follows


#include //Int integer variables are allocated two bytes, ranging from (-32768 to 32767, i.e. -2^15 to 2^15-1)

unsigned int i,j; //Unsigned integer variables are allocated two bytes, ranging from (0 to 65535, i.e. 2^16-1)

sbit led8=P1^7; //Declare the highest bit of port P1 as led8

void main()

{

while(1)

{

led8=0; //Set the highest position of P1 port to 0

for(i=100;i>0;i--)

for(j=500;j>0;j--);//It takes time for the MCU to execute the code, and the double-layer for loop plays a role in delaying

led8=1;

for(i=100;i>0;i--)

for(j=500;j>0;j--);

}

}


Click port1 in peripherals

insert image description here

You can see the 8-bit status of P1 port, and all I/O ports are 1

insert image description here

Look at the watch1 label in the lower right corner, press F2, enter the two variables i and j, and it will be displayed as 0x00. i and j are not assigned values ​​at the beginning, and the compiler defaults to 0. They are assigned values ​​after entering the for loop.

insert image description here

You can see that the sec value in the left register window is 422.09 microseconds, which is the time taken by the program from the start to the yellow arrow.

insert image description here

If you run it in a single step, you can see that the check mark in the highest position is gone, indicating that the statement led8=0 has been executed. The eighth diode is lit for 423.18 microseconds, minus 422.09 microseconds, which is 1.09 microseconds, or one machine cycle.

insert image description here

Click the reset button to set two breakpoints. When the full speed runs to the breakpoint, it stops. The statement after the breakpoint is the next statement to be executed.

insert image description here

Click Run at Full Speed, and you can see that the time becomes 88535.16 microseconds. Subtract the previous 423.18, and the double-layer for loop is about 88111.92 microseconds, that is, the eighth LED flashes every 88 milliseconds.

insert image description here

Summarize

1. Clock cycle: The reciprocal of the clock frequency is the reciprocal of the external crystal oscillator. The clock cycle of a 12MHz crystal oscillator is 1/12 microseconds. Machine cycle: A machine cycle consists of 12 clock cycles.

2. In the "New Concept 51 Single Chip Microcomputer Tutorial", the author debugged that when the variable type is unsigned int, the inner for loop is constant at 110. The outer for loop is about the same as the number of milliseconds, such as for(i=1000;i>0;i–)for(j=110;j>0;j–);, which means a delay of 1 second. This is just an approximate time. If you want higher accuracy, use a timer.

Keywords:keil2 Reference address:Use Keil2 software to simulate the time of delay statement

Previous article:51 single chip microcomputer realizes the operation of running water lamp
Next article:Microcontroller learning notes - interrupt principle and application

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号