Operating system Development Series -13.H. Delay operation

Source: Internet
Author: User

The counter works like this: it has an input frequency that is 1193180HZ on the PC. At each clock cycle (CLK cycles), the counter value is reduced by 1, and when it is reduced to 0 o'clock, an output is triggered. Since the counter is 16-bit, the maximum value is 65535, so the default clock interrupt occurs at a frequency of 1193180/65536 approximately equal to 18.2HZ.

We can programmatically control 8253. Because if you change the counter count, the time interval for the interrupt is changed accordingly.

For example, if you want the system to produce an interrupt every 10ms, that is, the output frequency is 100HZ, then you need to assign a value of 1193180/100 to about 11931.

。。。

Write mode

。。。

By modification, we have changed the interval of two clock interrupts to 10ms. The original 18.2 interrupts a second, about 55ms occurs once, now 100 times a second, 10ms occurs once.

Now we can write a new delay function, because the interrupt 10ms occurs once, so ticks is also 10ms added once, the delay function can be written like this, clock.c:

public void Milli_delay (int milli_sec) {        int t = get_ticks ();        while (((Get_ticks ()-t) * 1000/hz) < milli_sec) {}}

The function starts with the current ticks value, and then starts looping, looking at how many ticks have passed (assuming ΔT) at each loop. Because the interval between ticks is (1000/hz) MS, Δt ticks is equivalent to (δt*1000/hz) MS, and the loop exits when the number of milliseconds is greater than the required number of milliseconds.

Next, modify process A's process body:

void TestA () {int i = 0;while (1) {disp_str ("A");d Isp_int (Get_ticks ());d isp_str ("."); Milli_delay (1000);}}

Also let the process body of process B and C be similar to this.

Run as follows:

" Source "

Operating system Development Series -13.H. Delay operation

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.