8254 General Interface Experiment (Assembly and Interface Technology Course)


Preface

A compulsory course for undergraduates at Beijing Jiaotong University - 8254 Assembly and Interface Technology Routine Experiment.


1. Experimental purpose

1. Master the connection method between 8254 and microcomputer interface, and understand the basic working principle and programming method of 8254.
2. Understand the characteristics of various working modes of 8254 timer/counter; intuitively understand the similarities and differences of several working modes of 8254 by observing experimental waveforms.

2. Experimental content

experiment one

Set 8254 counter 0 to working mode 0, and set the initial value of the counter to N (N<0FH). Connect the single pulse on the experimental platform to CLK0, manually input the single pulse one by one, and use L0 and an oscilloscope to observe the level changes of OUT0 (after inputting N+1 pulses, OUT0 becomes high level and L0 lights up)

Ideas:
1. First we need to initialize the 8254, enter the mode command 00010000 to the command port 283H to select counter 0, write only the low byte, working mode 0, binary count 2, and then send the initial counting value 3 to counter 0
( This number is up to you to decide)
Experimental phenomenon:
Light bulb: The light bulb L0 is in an extinguished state at the beginning. When we manually give 4 (N+1) pulses, the light bulb turns bright and continues to stay bright.
Oscilloscope: The oscilloscope is at a low level at the beginning, but when we manually give 4 (N+1) pulses, the oscilloscope becomes a high level and no longer changes.
Result analysis:
Mode 0 only puts the value in the initial value register into the decrement counter when the first pulse is manually given, and starts to decrement by one when the second pulse arrives, so the light bulb and oscilloscope appear at N +1 pulse before it turns bright and becomes high level. And in mode 0, the out signal is always at high level after the count is completed, so the light bulb and oscilloscope remain in a constant light and high level state.
code show as below:

code segment
start :
mov dx, 283h; 命令口地址
mov al, 00010000b; 计数器0;只写低字节;2方式;二进制
out dx, al; 初始化

mov dx, 280h; 选择计数器0
mov ax, 03h; 计数器初值是3
out dx, al

code ends
end start

Experiment 2

Write a program to display the waveforms in working modes 2 and 3 respectively. The output frequency of mode 2 is required to be 1000Hz, and the output frequency of mode 3 is required to be 2000Hz. This experiment uses the timer/counter 0 of the 8254. GATE0 is connected to +5V or ground through K1, CLK0 is connected to the 1MHZ clock pulse, and OUT0 is connected to an oscilloscope to observe the output waveform (see Figure 1-2 for connections).
Figure 1-2

Method two:

  • Idea:
    Because the input pulse frequency is 1MHZ, in order to make the oscilloscope output frequency be 1000HZ, we can calculate the initial count value as 1MHZ / 1000HZ = 1000, so we first initialize, select counter 0, input the high byte first and then the low word Section, mode 2, counts in binary; then input the initial counting value of 1000 to the counter.
  • Experimental phenomenon:
    The waveform and value of 1000HZ can be observed on the oscilloscope
  • code show as below
code segment
start :
mov dx, 283h; 命令口地址
mov al, 00110100b; 计数器0;先低字节再高字节;2方式;二进制
out dx, al

mov dx, 280h; 选择计数器0
mov ax, 3e8h; 计数器初值1000
out dx, al; 先写低字节
mov al, ah;
out dx, al; 再写高字节
code ends
end start

Way 3:

  • Idea: Similar to method 2, except that the initial counting value is 1MHZ / 2000HZ=500
  • code show as below:
code segment
start :
mov dx, 283h; 命令口地址
mov al, 00110110b; 计数器0;先低字节再高字节;3方式;二进制
out dx, al; 初始化

mov dx, 280h; 选择计数器0
mov ax, 1f4h; 计数器初值500
out dx, al; 先写低字节
mov al, ah
out dx, al; 再写高字节
code ends
end start

Experiment 3

Using the cascade mode of timer 0 and timer 1, the light-emitting diodes are periodically turned on and off for 0.5 seconds each. (See Figure 1-3 for connections)
Figure 1-3

Idea:
We know that both methods 2 and 3 are the initial values ​​of the automatic reloading count, and the output waveform of method 3 is approximately high level: low level = 1:1, so here we choose counter 0 to use mode 2 and counter 1 to use Method 3, and use the OUT signal of counter 0 as the input clock of counter 1. Because the clock signal connected to counter 0 is 1MHZ, in order to periodically turn on and off the LED for 0.5 seconds each, we need to generate a square wave with a period of 1s and a frequency of 1/1s = 1HZ. In order to generate the 1HZ square wave, the product of the initial counting values ​​of counter 1 and counter 0 should be equal to 1MHZ / 1HZ = 1000000. Here we set the initial counting values ​​of counter 0 and counter 1 to 1000, and then conduct the experiment. Get the expected results.

  • code show as below:
code segment
assume cs : code
start :
mov dx, 283h; 命令口地址
mov al, 00110100b; 计数器0,先写低字节再写高字节,方式22进制
out dx, al

mov dx, 280h;  计数器0
mov al, 1000;   计数初值1000
out dx, al
mov al, ah
out dx, al;


mov dx, 283h; 命令口地址
mov al, 01110110b; 计数器1,先写低字节再写高字节,方式32进制
out dx, al

mov dx, 281h; 计数器1
mov al, 1000;   计数初值1000
out dx, al
mov al, ah
out dx, al;

code ends
end start

4. Experimental programming tips

Write 4 experimental programs (respectively 0, 2, 3, cascade mode) and execute them respectively. When observing the output waveforms of various modes, it is necessary to analyze the reasons for the test results.

5. Experimental steps

1. Connect the experimental circuit correctly according to the schematic diagram (thick black wire needs to be connected).
2. Correctly understand the experimental principles.
3. Write the experimental program, debug it on the computer, and observe the experimental results.

6. Thinking questions

What kind of waveform is the observed 0 mode? Why does this phenomenon occur?

The waveform is: first the low level lasts for a period of time and then changes to the high level.
Reason: When the initial counting value is written, the counter starts counting, the out signal becomes low level, and remains low until the content of the subtraction counter reaches 0, then stops working, and the out signal becomes high level, and remains low. high level.

Guess you like

Origin blog.csdn.net/weixin_63614711/article/details/131303138