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