Professional Documents
Culture Documents
Interfacing With Timer
Interfacing With Timer
2
• Selection of CWR A1 A0 Selection
and Counters:
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control Register
•Control Word D7 D6 D5 D4 D3 D2 D1 D0
Format SC1 SC0 RW1 RW0 M2 M1 M0 BCD
4
Modes
Initially OUT is low. Once a count is loaded, the
MODE 0:
counter is decremented every cycle and when the
INTERRUPT
count reaches zero, out goes high which can be
ON TC
used as interrupt
MODE1: OUT is initially high. When the GATE is triggered,
HW-RETRI the out goes low and at the end of the count, the
GG-ERABLE out goes high again, thus generating a one-shot
ONE-SHOT pulse
This mode is used to generate a pulse equal to the
MODE 2: clock period at a given interval. When a count is
RATE loaded, the out stays high until the count reaches 1,
GENERATO and then the out low for one clock period. The
R count is reloaded automatically and the pulse is
generated continuously
5
MODE 3: When a count is loaded, OUT is high. The count is
SQUARE-WAVE decremented by two at every clock cycle, and
GENERATOR when it reached zero, the OUT goes low and the
count is reloaded again. This is repeated
continuously, thus a cont. square wave is
generated
MODE 4: OUT is initially high; it goes low for one clock
SOFTWARE-TRIGG period at the end of the count. The count must be
ERED STROBE reloaded for subsequent outputs.
7
Programming of 8254
As a Counter: Write a subroutine to Initialize counter 2 in mode 0 with a count
50,000d. Read the count on fly. When the count reaches 0 it should return to main
program.
• Control Word: 10110000 = B0H
• Subroutine:
MVI A, B0H; CW to initialize counter 2
OUT 83H; write in CR
MVI A, LOBYTE; LO Byte of 50,000
OUT 82H; Load Counter 2 with LO Byte
MVI A, HIBYTE; HO Byte of 50,000
OUT 82H; Load Counter 2 with HO Byte
READ: MVI A, 80H; CW to Latch a count
OUT 83H; Write in CR
IN 82H; Read LO Byte
MOV D,A; Save LO Byte in D
IN 82H; Read HO Byte
ORA D; OR LO and HO Bytes to set Z flag
JNZ READ
RET
8
Write instructios to generate a pulse every 50us
from counter0.
1. Mode : Mode-2
2. CW: D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 1 0 1 0 0
Counter0 Load 8-bit Mode-2 Binary
count count
9
4. Program
PULSE: MVI A, 14H; control word
OUT 83H; write in control register
MVI A, 64H; LO Byte of the count
OUT 80H; load Counter0 with LO Byte
HALT
10
Square-Wave Generator
Write instructions to generate a 1kHz
square-wave from Counter1.
1. CW: D7 D6 D5 D4 D3 D2 D1 D0
0 1 1 1 0 1 1 0
Select counter1 Load 16-bit Mode-3 Binary
count count
11
Program:
SQWAVE: MVI A, 76H; control word
OUT 83H; write in control register
MVI A, D0H; LO byte of the count
OUT 81H; load counter 1 with LO byte
MVI A, 07H; HO byte of the count
OUT 81H; load counter1 with LO byte
HALT
12