Write an assembly language program for the 8253/8254 (programmable interval timer) to operate in mode 3 and mode 2.
Use counter 0 for which control word register address is 2DH and counter 0 address is 2BH. Input clock is 1 MHz and output frequency is 1 kHz.
10 marks · directive: Write
The core of a good answer
The count is 1 MHz/1 kHz = 1000 = 03E8H; the control word for counter 0, LSB then MSB, binary count is 36H for mode 3 (square wave) and 34H for mode 2 (rate generator), written to 2DH, followed by E8H and 03H written to 2BH.
An outline written by upsc.help, not an official UPSC answer; every fact checked by a separate review. How we work
What the question asks
The candidate must compute the count, build the 8253 control word bit by bit for each mode, and write 8085 OUT instructions in the correct order (control word first, then low byte and high byte of the count).
Answer outline
Introduction
8253 control word format: D7 D6 = SC1 SC0 (counter select), D5 D4 = RW1 RW0, D3 to D1 = M2 M1 M0 (mode), D0 = BCD. Count N = fclk/fout = 10⁶/10³ = 1000 = 03E8H (binary).
Step 1: Control words
- Mode 3: 00 (counter 0) 11 (LSB then MSB) 011 (mode 3) 0 (binary) = 0011 0110 = 36H
- Mode 2: 00 11 010 0 = 0011 0100 = 34H
Step 2: Program for mode 3 (1 kHz square wave)
- MVI A, 36H ; control word, counter 0, mode 3
- OUT 2DH ; write to control register
- MVI A, E8H ; low byte of 1000
- OUT 2BH ; load counter 0 LSB
- MVI A, 03H ; high byte of 1000
- OUT 2BH ; load counter 0 MSB
- HLT
Step 3: Program for mode 2 (1 kHz rate generator)
- MVI A, 34H ; control word, counter 0, mode 2
- OUT 2DH
- MVI A, E8H
- OUT 2BH
- MVI A, 03H
- OUT 2BH
- HLT
Step 4: Output waveforms
- Mode 3: OUT is high for 500 clocks and low for 500 clocks, a 1 kHz square wave (period 1 ms)
- Mode 2: OUT stays high for 999 clocks and goes low for one clock period (1 µs) every 1000 clocks, a 1 kHz pulse train
- GATE 0 must be held high: in modes 2 and 3 a low GATE forces OUT high and resets the counter
Conclusion
Count 03E8H with control word 36H (mode 3) or 34H (mode 2) gives a 1 kHz output from counter 0 with a 1 MHz clock.
Examples and data to cite
- BCD alternative: control words 37H (mode 3) and 35H (mode 2) with count 1000 loaded as LSB 00H and MSB 10H.
- The 8254 is a superset of the 8253 with higher clock speed ratings and a read-back command.
Facts to remember
- 8253 has three independent 16-bit down counters and six modes (0 to 5).
- Mode 2 is the rate generator; mode 3 is the square wave generator.
- Output frequency = input clock frequency/N.
- With RW = 11 the low byte must be written before the high byte.