Introduction:
Peripheral devices provide interface between the CPU and slow electromechanical devices Previously, all these devices were taken care of by the CPU using interrupt mechanism or polling techniques, which results in reduced overall efficiency and low processing speed To minimize the slow speed I/O communication overhead, a set of dedicated programmable peripheral devices have been introduced Thus once initiated by the CPU, these devices take care of all the interface activities , and thus makes the CPU free from the interface activities and execute its main task more efficiently.
Advanced Microprocessor
I/O Interface
Advanced Microprocessor
Fig. above shows the block diagram of 8253/54. It includes three counters, a data bus buffer, Read/Write control logic, and a control register. Each counter has two input signals CLOCK and GATE and one output signal OUT.
CLK: The clock input is the timing source for each of the internal counters. It is often connected to the PCLK signal from the bus controller. GATE: The gate input controls the operation of the counter in some modes. OUT: A counter output where the wave-form generated by the timer is available.
Data Bus Buffer : This tri-state, bi-directional, 8-bit buffer is used to interface the 8253/54 to the system data bus. The Data bus buffer has three basic functions.
1. Programming the modes of 8253/54. 2. Loading the count registers. 3. Reading the count values. Advanced Microprocessor
Advanced Microprocessor
Programmable interval Timer 8253 Each counter is individually programmed by writing a control word, followed by the initial count. The control word allows the programmer to select the counter, mode of operation, binary or BCD count and type of operation (read/write).
Advanced Microprocessor
11
Programmable interval Timer 8253 Programming the 8254 Each counter may be programmed with a count of 1 to FFFFH. Each counter has a program control word used to select the way the counter operates. If two bytes are programmed, then the first byte (LSB) stops the count, and the second byte (MSB) starts the counter with the new count.
There are 6 modes of operation for each counter: Mode0, Mode1, Mode2, MOde3, Mode4, Mode5
Advanced Microprocessor
12
Programmable interval Timer 8253 Programming the 8254 Modes of operation Mode 0: interrupt on terminal count. The output becomes a logic 0 when the control word is written and remains there until N plus the number of programmed counts.
The G input triggers the counter to output a 0 pulse for count clocks.Counter reloaded if G is pulsed again.
Advanced Microprocessor
13
Programmable interval Timer 8253 Programming the 8254 Modes of operation Mode 2: rate generator or divide by N counter N is loaded as the count value, then after N pulses, the output becomes low only for one clock cycle. The cycle is repeated until reprogrammed or G pin set to 0.
Mode 3: Generates a continuous square-wave with G set to 1. If count is even, 50% duty cycle otherwise OUT is high 1 cycle longer.
Advanced Microprocessor
14
Programmable interval Timer 8253 Programming the 8254 Modes of operation Mode 4: Software triggered one-shot (G must be 1).
Advanced Microprocessor
16
Read Operations There are three possible methods for reading the counters:
a simple read operation the Counter Latch Command the Read-Back Command Simple read operation : The Counter which is selected with the A1, A0 inputs, the CLK input of the selected Counter must be inhibited by using either the GATE input or external logic. Otherwise, the count may be in the process of changing when it is read, giving an undefined result.
Advanced Microprocessor
17
Programmable interval Timer 8253I/O Interface Counter Latch Command: SC0, SC1 bits select one of the three Counters two other bits, D5 and D4, distinguish this command from a Control Word If a Counter is latched and then, some time later, latched again before the count is read, the second Counter Latch Command is ignored. The count read will be the count at the time the first Counter Latch Command was issued.
Advanced Microprocessor
18
Programming
CONTROL WORD FORMAT SC1 SC0 0 0 RL1 1 RL0 1 M2 0 M1 1 M0 0 BCD 0
= 34H(Mode 2)
SC1 0
SC0 0
RL1 1
RL0 1
M2 0
M1 1
M0 1
BCD 0
= 36H(Mode 3)
Control word
SELECT COUNTER BIT DEFINITION
SC0 SC1 OPE RATION
0 0 1 1
0 1 0 1
RL1
RL0
0 0 1 1
0 1 0 1
MODE
M2 M1 M0 SELECTED MODE MODE 0 MODE 1 MODE 2 MODE 3 MODE 4 MODE 5 0 0 X X 1 1 0 0 1 1 0 0 0 1 0 1 0 1
BCD 0 1
Rate Generator
MOV AL,34H OUT 16,AL MOV AL,04H OUT 10,AL MOV AL,00H OUT 10,AL HLT
Move the command word to A register Output it to control register Move 04 to A register Output the value to counter 0 Move 00 to A register Output the value to content 0 Halt the program execution
SQUARE WAVE
MOV AL,36H OUT 16,AL MOV AL,04H OUT 10,AL MOV AL,00H OUT 10,AL HLT
Move the command word to A register
Output it to control register Move 04 to A register Output the value to counter 0 Move 00 to A register Output the value to content 0 Halt the program execution