MOV DX, 0B000H corresponding to the port address of the selected counter is sent to DX.
MOV AX,5000; The initial value of the 8253 count is sent to AX.
OUT DX,AL; The lower 8 bits are sent to the counter port.
MOV· El, ah; Give the upper eight bits to AL first, and input and output the necessary format of the instruction.
OUT DX,AL; High 8-bit counter input port
HH:MOV DX, 0F002H label, give DX port number.
In AL, dx; Read the address port value
And AL, 01h; Mask the D7~D 1 bit of the port value to keep the D0 bit in AL unchanged, and check whether its value is 0.
If JNZ HH is not 0, jump to HH, otherwise it will be executed in sequence.
LL: in AL, dx; Read the address port value
And AL, 01h; The function is the same as before.
JZ ii; Detect whether the low bit is 0, if it is 0, jump to ll, otherwise, execute it sequentially.
RET return value
delay 5 ms ENDP; Subroutine end command
This 8253 program lacks the command to send control words to the control port, without which it is impossible to send control words to the control port.
5000 is not 5000ms according to your topic, it should be 5 ms As for 5000, it should be calculated according to how many MHZ CLK is.
Do you want to know how to achieve 5ms delay? I don't know much about this. There is no control word. As far as I know, I can't tell how it works. 8253 has six working modes, which are very complicated. I suggest you don't delve into so much. Initializing 8253 is enough unless you decide to do so later. I'm a student, too. I don't have textbooks and some materials we use.
Sweat first!
You should know that whether it is 8253, 8255A or 8259A, you need a control word to initialize it. I think if you learn 8253, you should know what a control word is. The format of the control word is as follows:
Sc 1, sc0 channel select bit. 00,0 1 and 10 respectively indicate that 0,1and 2 channels are selected. RL 1, RL0- read/write operation bit.00 indicates latched data, which can be read by the counter at any time. 0 1 means read-only/write, and 8 low bits and 8 high bits are automatically set to 0; 10 means read-only/write, and 8 high bits and 8 low bits are automatically set to 0; 1 1 means read/write 16-bit data, with 8 lower bits first and 8 higher bits later. M2, M 1, M0- working mode selection bit.
According to the control word, you can specifically judge which working mode to choose. Now, I will talk in general terms.
First, the statistical initial value = timing time ÷CLK period. Do the math.
Say the general principle again:
8253 includes three counting channels with the same function and completely independent operation. Each counting channel consists of 16-bit subtraction counter, 16-bit counting initial value register and 16-bit counting value latch. During initialization, the initial count value loaded into the counting channel is first sent to the initial count register for storage, and then sent to the subtraction counter. After the counter is started, the subtraction counter subtracts 1 from the falling edge of CLK and sends the result to the 16-bit counting latch when it is unlocked. When the count value is reduced to 0, the OUT signal is output, and the first count ends. During the counting process, the contents of the initial counting register remain unchanged. The counting initial register and the counting value latch occupy a port address (that is, the port address of the counting channel), and the CPU reads the current counting value of the counting channel from the counting value latch.
I don't know if you understand latches. The stored command is to lock the count value when reading it to prevent it from changing. Otherwise, if the count value may be changing, the result will be uncertain. When the cpu reads the stored command, the latch will fail and the counter will resume working.
There is no control word, but this is a delay procedure, so you have to make the channel work in timer mode, and at this time, the clock pulse with a certain frequency is input from CLK, which is consistent with the frequency and initial value calculation I mentioned above.
Then the start, disable and allow counts of each channel are related to the GATE control signal GATE, and the output waveform of GATE function OUT varies with the working mode of each channel.
There is no way to determine the working mode without the control word. Maybe there is a way, but my knowledge is limited, so much I can know. I hope it helps you.
PS: You have drained me dry!