Ec6504 MPMC Unit 3
Ec6504 MPMC Unit 3
I/O INTERFACING
Reference : Chapter 9
MicroComputer Systems,Cheng Liu,Glenn Gibson
I/O interface
An I/O interface must be able to:
1. Interpret the address and memory-I/O select
signals to determinate whether or not it is
being referenced and, if so, determine which
of its registers is being accessed.
2. Determine whether an input or output is
being conducted and accept output data or
control information from the bus or place
input data or status information on the bus.
I/O interface
3.Send interrupt requests and, if there is no
interrupt priority management in the bus
control logic, receive interrupt
acknowledgments and send an interrupt
type.
4. Receive a reset signal and reinitialize itself
and perhaps, its associated device.
I/O interface
5.Send interrupt requests and, if there is no
interrupt priority management in the bus
control logic, receive interrupt
acknowledgments and send an interrupt type.
6.Receive a reset signal and reinitialize itself
and perhaps, its associated device.
Figure 9-1 Typical block diagram of
an I/O device
Function of an I/O interface
Components
external data bus drivers and receivers
handshaking logic
address decoder
Address decoder – a sample
Parallel
Faster
Data skew
Limited to small distances
External Interface (cont‟d)
Two basic modes of data transmission
External Interface (cont‟d)
Serial transmission
Asynchronous
Each byte is encoded for transmission
Start and stop bits
No need for sender and receiver synchronization
Synchronous
Sender and receiver must synchronize
Done in hardware using phase locked loops (PLLs)
Block of data can be sent
More efficient
Less overhead than asynchronous transmission
Expensive
External Interface (cont‟d)
11-12
Types of serial communication
NO start/stop bits
Each txed character has 5 to 8 bits optionally
followed by parity
All char have same number of bits – n
Same clock control
Under run error – when a character is not available
at the beginning of the interval,txer inserts idle
characters,rxer – sees idle char as errors
Serial Data Transfer
Asynchronous v.s. Synchronous
— Asynchronous transfer does not require clock signal. However, it transfers extra
bits (start bits and stop bits) during data communication
— Synchronous transfer does not transfer extra bits. However, it requires clock
signal
Frame
Asynchronousdata
Data transfer Start
B0 B1 B2 B3 B4 B5 B6 Stop bits
bit Parity
clk
Synchronous
Data transfer
data
B0 B1 B2 B3 B4 B5
Baud (Baud is # of bits transmitted/sec, including start, stop, data and parity).
Long distance serial communication
8251 – Programmable Communication
Interface
Pins and signals - 8251
8251- block diagram
Sections of 8251A
Data Bus buffer
Read/Write Control Logic
Modem Control
Transmitter
Receiver
CS C/D WR RD Operation
0 0 1 0 MPU reads data from data buffer
0 0 0 1 MPU writes data to data buffer
0 1 0 1 MPU writes a word to control register
0 1 1 0 MPU reads a word from status register
1 × × × Chip is not selected for any operation
3. Modem Control
DSR - Data Set Ready : Checks if the Data Set is
ready when communicating with a modem.
DTR - Data Terminal Ready : Indicates that the
device is ready to accept data when the 8251 is
communicating with a modem.
CTS - Clear to Send : If its low, the 8251A is
enabled to transmit the serial data provided the
enable bit in the command byte is set to „1‟.
RTS - Request to Send Data : Low signal indicates
the modem that the receiver is ready to receive a
data byte from the modem.
4. Transmitter section
Accepts parallel data from MPU & converts them into
serial data.
Has two registers:
Buffer register : To hold eight bits
Output register : To convert eight bits into a stream of serial
bits.
Output Register
Transmitter Buffer
Transmit control
Transmitter
The MPU writes a byte in the buffer register.
Whenever the output register is empty; the contents of buffer
register are transferred to output register.
Transmitter section consists of three output & one input signals
TxD - Transmitted Data Output : Output signal to transmit the data to
peripherals
TxC - Transmitter Clock Input : Input signal, controls the rate of
transmission.
TxRDY - Transmitter Ready : Output signal, indicates the buffer register
is empty and the USART is ready to accept the next data byte.
TxE - Transmitter Empty : Output signal to indicate the output register is
empty and the USART is ready to accept the next data byte.
5. Receiver Section
Input Register
RxD
Receive Buffer
RxRDY
Receive control
RxC
When RxD goes low, the control logic assumes it
is a start bit, waits for half bit time, and samples
the line again. If the line is still low, the input
register accepts the following data, and loads it
into buffer register at the rate determined by
the receiver clock.
Receiver
RxRDY - Receiver Ready Output: Output signal,
goes high when the USART has a character in the
buffer register & is ready to transfer it to the MPU.
RxD - Receive Data Input : Bits are received serially
on this line & converted into a parallel byte in the
receiver input register.
RxC - Receiver Clock Input : Clock signal that
controls the rate at which bits are received by the
USART.
Sequencing
Mode register format
Control register format
Mode Instruction (Asynchronous)
Mode Instruction (Synchronous)
Command Register
Status Register
Asynchronous modem connection
Synchronous modem connection
Simple Serial I/O Procedures
Read Write
start start
No No
Is it logic 1? Is it logic 1?
Yes Yes
Read data register* Write data register*
end end
* This clears RxRDY * This clears TxRDY
Example problem
Write A program sequence which uses programmed
I/O to input 80 characters from the 8251A, whose
data buffer register's address is 0050, and put
them in the memory buffer beginning at LINE.
Example - solution
Parallel communication
Simultaneous transfer of bits over separate lines
Adv: high information rate
Disadv:cost of lines
Parallel o/p i/f without control lines
Parallel o/p i/f without control lines
Contents of data buffer Are continually maintained
on data lines connecting the i/f and I/O
Features:
It is a programmable device.
T T L compatible.
A1 A0 Select
0 0 PA
0 1 PB
1 0 PC
Control
1 1
reg.
PINS AND SIGNALS
RESET: to reset the device. clear control registers.
PB0-PB7:Similar to PA
Busy
BIT
X X X SET/RESET
1=SET
Don‟t care 0=RESET
Bit select
0 1 2 3 4 5 6 7
0 1 0 1 0 1 0 1
0 0 1 1 0 0 1B0 1
0 0 0 0 1 1 1B1 1
B2
BIT SET/RESET FLAG
=0 Active
CONTROL WORD
PC0-PC7 is set or reset as per the status of D0.
A BSR word is written for each bit
Example:
PC3 is Set then control register will be 0XXX0111.
PC4 is Reset then control register will be
0XXX01000.
X is a don‟t care.
I/O MODE - CWR
D7 D6 D5 D4 D3 D2 D1 D0
Group B
Group A
Port C Upper
Mode set Port C Lower
1=Input
flag=1=Active 1=Input
0=Output
0=Output
Port B
Port B
1=Input
1=Input
0=Output
0=Output
Mode selection
Mode selection
00=mode 0
0=mode 0
01=mode 1
1=mode 1
1x=mode 2
CWR
Bit D7 is used for specifying OPERATION MODE (Bit
set/reset mode or I/O Mode .
D7=1=I/O mode.
D7=0=Bit set/Reset mode.
8255 MD Control word Contd.
72
MOV DX,0FFFBH
MOV AL,10110000B
OUT DX,AL
MOV DX,0FFFAH
AGAIN: IN AL,DX
TEST AL,00100000B
JZ AGAIN
MOV DX,0FFF8H
IN AL,DX
Step 4
For outputting a byte from AL to the D/A converter,
the instructions are
MOV DX,0FFF9H
OUT DX,AL
MOV CX,N
IDLE: NOP
LOOP IDLE
A flowchart for inputting a block of A/D samples
using programmed timing
UNIT 3
PROGRAMMABLE TIMERS AND EVENT COUNTERS
Functions
1. Interrupt a time-sharing operating system at evenly spaced
intervals so that it can switch programs.
2. Output precisely timed signals with programmed periods
to an I/O device (e.g. an A/D converter).
3. Serve as a programmable baud rate generator.
4. Measure time delays between external events.
5. Count the number of times an event occurs in an external
experiment and provide a means of inputting the count to
the computer.
6. Cause the processor to be interrupted after a programmed
number of external events have occurred.
A typical timer/event counter
PROGRAMMABLE INTERVAL
TIMER - 8254
Features
Three Independent 16-Bit Counters,
Clock input upto 10 MHz,
Status Read-Back Command,
Six Programmable Counter Modes,
Binary or BCD Counting,
Single +5V Supply,
Superset of PIT-8253.
Pin Diagram
Pin Description
Block Diagram of 8254
Internal Blocks of Counter
Count Register (CR) to store count (CRL & CRM),
Counting elements (CE) are used for counting,
Output Latch (OLL & OLM) to latch the count in
CE,
The Control Word Register is not part of the
Counter itself, but its contents determine how the
Counter operates.
The status register, when latched, contains the
current contents of the Control Word Register and
status of the output and null count flag.
Internal Block Diagram
System Interface
Control Word format
8254 Programming
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).
WRITE Operation
F – clock frequency
Frequency applied to clock 1 = F/N
Output – OUT1-Pulse period-MN/F
Output – OUT0-Pulse period-MN/F-Freq-F/L
Apply OUT0 to convert i/p of ADC, F/L samples
/sec will be taken for MN/F sec after 3 counters
are initialized and relay is closed
Interval Timer Application to A/D
Each sample is txed to port A,INTRA is invoked, an
interrupt routine is used to input the sample
Addresses used
0070 to 0073
Initial count L,N – binary
Initial count M- BCD
Initialization of counters for A/D
example
KEYBOARD AND DISPLAY
For low-cost small systems, especially single-board
microcomputers and microprocessor-based
instruments, the front panel (or console) is often
implemented by using simple keyboard and display
units as input and output devices.
Keyboard Design
Unlike a terminal, mechanical contact keyboard, for
which the key switches are organized in a matrix
form, does not include any electronics.
KEYBOARD DESIGN
a 64-key keyboard can be interfaced to a
microcomputer through two parallel I/O ports such
as those provided by an 8255A.
Organization of a mechanical
keyboard
Keyboard Interface
INTERFACING KEYBOARD
5V
0 1 2 3
PA0 ROW 0 10K
4
ROW 1 5 6 7
PA1 10K
8 9 A B
PA2 ROW 2 10K
C D E F
PA3
ROW 3 10K
8255 5V
PB0 COL 0 10K 5V
PB1 COL 1 10K
5V
PB2 COL 2 10K 5V
PB3
COL 3 10K
MODE 0 Application (Keyboard
Interface)
In most applications, the microcomputer scans the
keyboard array. That is, it strobes one row of the
keyboard after the other by sending out a short-
duration pulse, to the 0 logic level, on the row line.
During each row strobe, all column lines are
examined by reading them in parallel.
8086 HAS TO
1. WAIT till all keys are released. Use s.w debounce for each
key check
2. Wait for key closure
3. Confirm key closure
4. Find number of row and column to which key belongs
5. Convert the row and col information to entry number of the
table which contains ASCII code
6. Get code and repeat in infinite loop
Flow chart
START
NO ANYKEY
ENABLE ALL ROWS
PRESSED
YES
READ ALL COL.S
ENABLE A ROW
ALL NO
READ ALL COL.S
KEYS
OPEN
YES
NO
KEY
DELAY FOR DEBOUN INC ROW NUMBER
DETECTED
YES
READ ALL COL.S
CALC. KEY CODE
NO ALL
KEYS STOP
OPEN YES
NO ANYKEY
PRESSED
YES
Control
• These registers store the keyboard and display modes
and and other operating conditions programmed by CPU.
Timing • The registers are written with A0=1 and WR=0. The
Register Timing and control unit controls the basic timings for the
and operation of the circuit.
Timing • Scan counter divide down the operating frequency of
8279 to derive scan keyboard and scan display
Control frequencies.
:
• The scan counter has two modes to scan the
key matrix and refresh the display.
• In the encoded mode, the counter provides
binary count that is to be externally decoded
to provide the scan lines for keyboard and
display
Scan • Four externally decoded scan lines may drive
upto 16 displays.
Counter • In the decode scan mode, the counter
: internally decodes the least significant 2 bits
and provides a decoded 1 out of 4 scan on
SL0-SL3
• Four internally decoded scan lines may drive
upto 4 displays.
• The keyboard and display both are in the
same mode at a time.
Return
Buffers • This section scans for a key closure row wise. If a
and key closer is detected, the keyboard debounce unit
debounces the key entry (i.e. wait for 10 ms).
Keyboard
• After the debounce period, if the key continues to
De- be detected, The code of key is directly
bounce transferred to the sensor RAM along with SHIFT
and and CONTROL key status.
Control:
Display
Address • The display address register holds the address
Register of the word currently being written or read by
the CPU to or from the display RAM.
s and • The contents of the registers are automatically
Display updated by 8279 to accept the next data entry
RAM : by CPU.
• In keyboard or strobed input mode, this block
acts as 8-byte first-in-firstout (FIFO) RAM.
• Each key code of the pressed key is entered
in the order of the entry and in the mean time
read by the CPU, till the RAM become empty.
• The status logic generates an interrupt after
FIFO/Sensor each FIFO read operation till the FIFO is
RAM and empty.
Status Logic: • In scanned sensor matrix mode, this unit acts
as sensor RAM.
• Each row of the sensor RAM is loaded with the
status of the corresponding row of sensors in
the matrix.
• If a sensor changes its state, the IRQ line goes
high to interrupt the CPU.
FUNCTIONAL UNITS
• Scanned
keyboard mode
• Scanned sensor • Display scan
matrix mode • Display entry
• Strobed input •
Operating
mode
modes of 8279
OUTPUT
INPUT ( (display )
keyboard) MODES
MODES
Scanned Keyboard 2 key
Mode : lock
This mode allows a key out
matrix to be interfaced
using either encoded or
decoded scans.
encoded scan 8*8
keyboard,
decoded scan 4*8
N – key
keyboard. roll
The code of key pressed over
with SHIFT and
CONTROL is stored in
FIFO RAM.
2 key
lock out
When a key is pressed, a debounce logic comes into operation. During the
next two scans, other keys are checked for closure and if no other key is
pressed the first pressed key is identified.
The key code is entered with SHIFT and CNTL status, provided the FIFO is
not full, i.e. it has at least one byte free. If not free, data will not be entered
and the error flag is set.
If FIFO has at least one byte free, the above code is entered into it and the
8279 generates an interrupt on IRQ line to the CPU to inform about the
previous key closures.
A key code is entered to FIFO only once for each valid depression,
independent of other keys pressed along with it, or released before it.
a) Keyboard Display Mode Set : The format of the command word to select
different modes of operation of 8279 is given below with its bit definitions.
D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 D D K K K
SENSOR MATRIX
SENSOR MATRIX
B) Programmable clock :
0 0 1 P P P P P
c) Read FIFO / Sensor RAM : The format of this command is
given below.
D7 D6 D5 D4 D3 D2 D1 D0
0 1 0 AI X A A A
E- Error mode
X- don’t care
Cascade Mode :
one master and eight slaves (maximum) to handle
upto 64 priority levels
The master controls the slaves using CAS0-CAS2
which act as chip select inputs (encoded) for slaves
Cascade mode
226
DIRECT MEMORY ACCESS
CONTROLLER
(DMAC – 8237)
Techniques to synchronize data rate of
processor with peripherals
Technique
1 2 3 4 5 6 7 8 9
CLK
HOLD
HLDA
232
8237 pins
CLK: System clock
233 CS΄: Chip select (decoder output)
RESET: Clears registers, sets mask register
READY: 0 for inserting wait states
HLDA: Signals that the μp has relinquished buses
DREQ3 – DREQ0: DMA request input for each channel
DB7-DB0: Data bus pins
IOR΄: Bidirectional pin used during programming and during a DMA write cycle
IOW΄: Bidirectional pin used during programming and during a DMA read cycle
EOP΄: End of process is a bidirectional signal used as input to terminate a DMA process
or as output to signal the end of the DMA transfer
A3-A0: Address pins for selecting internal registers
A7-A4: Outputs that provide part of the DMA transfer address
HRQ: DMA request output
DACK3-DACK0: DMA acknowledge for each channel.
AEN: Address enable signal
ADSTB: Address strobe
MEMR΄: Memory read output used in DMA read cycle
MEMW΄: Memory write output used in DMA write cycle
8237
Minimal System with a DMA Controller
Interrupt On-Chip-Bus
Request
DMA Peripheral
Controller Acknowledge Device
8237 DMA controller
THE 8237 DMA CONTROLLER
The 8237 supplies memory & I/O with control signals and
memory address information during the DMA transfer.
actuallya special-purpose microprocessor
whose job is high-speed data transfer between memory and
I/O
Figure 13–3 shows the pin-out and block diagram of the
8237 programmable DMA controller.
8237 is not a discrete component in modern
microprocessor-based systems.
it appears within many system controller chip sets
8237 is a four-channel device compatible
with 8086/8088, adequate for small systems.
expandable to any number of DMA channel inputs
8237 is capable of DMA transfers at rates up to 1.6M
bytes per second.
each channel is capable of addressing a full
64K-byte section of memory and transfer up to 64K bytes
with a single programming
8237 Pin Definitions
CLK
Clock input is connected to the system clock signal as
long as that signal is 5 MHz or less.
in the 8086/8088 system, the clock must be inverted for
the proper operation of the 8237
8237 Pin Definitions
Chip select enables 8237 for programming.
The CS pin is normally connected to the output of a decoder.
The decoder does not use the 8086/8088 control signal IO/M(M/IO)
because it
contains the new memory and I/O control signals (MEMR, MEMW,
IOR and IOW).
8237 Pin Definitions
RESET
The reset pin clears the command, status, request, and
temporary registers.
It also clears the first/last flip-flop and sets
the mask register.
this input primes the 8237 so it is disabled
until programmed otherwise
8237 Pin Definitions
READY
A logic 0 on the ready input causes the
8237 to enter wait states for slower
memory components.
HLDA
• A hold acknowledge signals 8237 that the
microprocessor has relinquished control of
the address, data, and control buses.
8237 Pin Definitions
DREQ0–DREQ3
DMA request inputs are used to request a transfer
for each of the four DMA channels.
the polarity of these inputs is programmable, so
they are either active-high or active-low inputs
DB0–DB7
• Data bus pins are connected to the
processor data bus connections and used
during the programming of the DMA
controller.
8237 Pin Definitions
IOR
I/O read is a bidirectional pin used during programming
and during a DMA write cycle.
IOW
• I/O write is a bidirectional pin used during
programming and during a DMA read cycle.
8237 Pin Definitions
EOP
End-of-process is a bidirectional signal
used as an input to terminate a DMA
process or as an output to signal the
end of the DMA transfer.
often used to interrupt a DMA transfer at
the end of a DMA cycle
8237 Pin Definitions
A0–A3
These address pins select an internal
register during programming and provide
part of the DMA transfer address during a DMA action.
address pins are outputs that provide part of
the DMA transfer address during a DMA action
8237 Pin Definitions
HRQ
Hold request is an output that connects to
the HOLD input of the microprocessor in
order to request a DMA transfer.
8237 Pin Definitions
DACK0–DACK3
DMA channel acknowledge outputs acknowledge a channel
DMA request.
These outputs are programmable as either active-high or active-
low signals.
DACK outputs are often used to select the
DMA- controlled I/O device during the DMA transfer.
8237 Pin Definitions
AEN
MEMR
• Memory read is an output that causes
memory to read data during a DMA read
cycle.
8237 Pin Definitions
MEMW
Memory write is an output that causes memory to
write data during a DMA write cycle.
8237 block diagram
252
Description
Five main Blocks
1. Data bus buffer
2. Read/Control logic
3. Control logic block
4. Priority resolver
5. DMA channels.
DATA BUS BUFFER:
It contain tristate ,8 bit bi-directional buffer.
MR
The mode register programs the mode of operation
for a channel.
Each channel has its own mode register as selected
by bit positions 1 and 0.
remaining bits of the mode register select operation,
auto-initialization, increment/decrement, and mode for
the channel
8237A-5 mode register. (Courtesy of Intel Corporation.)
8237 Internal Registers
BR
Types:
Sequential DMA
Simultaneous DMA
Three methods (MODES) of DMA operation: (a) byte; (b)
burst; (c) block.
Steps in a DMA operation
Processor initiates the DMA controller
Gives device number, memory buffer pointer, …
Called channel initialization
Once initialized, it is ready for data transfer
When ready, I/O device informs the DMA
controller
DMA controller starts the data transfer process
Obtains bus by going through bus arbitration
Places memory address and appropriate control signals
Completes transfer and releases the bus
Updates memory address and count value
If more to read, loops back to repeat the process
Notify the processor when done
Typically uses an interrupt
Modes of Operation
Rotating priority Mode:
The priority of the channels has a circular sequence.
Fixed Priority Rotating Mode:
The priority is fixed.
TC Stop Mode
LED DISPLAY
LCD DISPLAY
KEYBOARD DISPLAY
ALARM CONTROLLER
7-Segement Display
Vcc
Anode
Cathode
7-Segement Display
Select Segments: Switched Resistors to Vcc
CC
GND
7 SEGMENT DISPLAY
MULTIPLEXED
7 SEGMENT LED DISPLAY
Common
To segment
on all Digits
n=8
Digits
Sequentially
Turn ON one digit at a time
1 turns
segment ON
Tr 1
Tr 2 Most Significa
A: O/P Port:
(MS) Digit
Segment data
For selected digit Multiplex the eight digit displays
(only one is ON at a time)
0 turns digit
B:O/P
O/PPort:
Port:digit ON Vcc
B:
Selectdigit
Select # Displayed
To be displayed
1 digit
. . . . .Digit
. transistor
PLD for 14-bit
GND switch Controlled by
I/O address (A15-A2) + IO/#M decoding Port B bit,
e.g. Tr 1
MS Digit
MEM+7
.
BX .
; Program the 82C55 for Port A and Port B are output ports in mode 0 .
MOV AL, 80H ; 80H Data into AL MEM LS Digit
MOV DX, 703H ; Address of Command Port into DX
OUT DX, AL ; Write 80H into Command Port
; ; to program PPI
; An assembly language procedure that multiplexes the 8-digit display.
; This procedure must be called often enough for the display to appear stable
DISP PROC NEAR USES AX BX DX SI
PUSHF
MOV BX,8 ;load counter BX with # of display digits
MOV AH,7FH ;load initial digit selection pattern to enable MS digit (01111111)
MOV SI,OFFSET MEM - 1 ;Load SI with offset (MEM) - 1
MOV DX,701H ;address Port B (for Port A: decrement DX)
;
;Sequentially display all 8 digits starting with MS digit
.
.REPEAT .
MOV AL,AH .
OUT DX,AL ;send digit selection pattern to Port B
DEC DX ;Address Port A (to send Digit Data)
MOV AL,[BX+SI] ;Load digit data from memory into AL
OUT DX,AL ;send digit data to Port A
CALL DELAY ;wait 1.0 ms leaving displayed digit ON
ROR AH,1 ;adjust selection pattern to point to next digit
INC DX ;Address port B
DEC BX ;decrement counter for data of next digit.
.UNTIL BX == 0
POPF
RET
DISP ENDP Procedure for 1 ms delay, e.g. a loop of
instructions
i.e. digit remains ON for 1 ms before moving
to next
; Delay Loop
XXXX = 1ms/350ns
Display Flashing Rate:
300
The data connections, which are attached to the 82C55
301 port A, are used to input display data and to read
information from the display.
For a 4-bit interface, D4–D7 pins are used where the data
must be formatted with the high nibble first, followed by
the low nibble.
A few newer OLED devices contain a serial interface that
uses a single pin for the data.
302
After initialization, time delays are no longer needed
when sending data or many commands to the display.
The clear display command still needs a time delay as the
busy flag is not used .
Instead of a time delay, the busy flag is tested to see
whether the display has completed an operation.
The BUSY procedure tests the LCD display and only returns
when the display has completed a prior instruction.
303
I/P
Y
O/P
X
0 0 0 0
Column Outputs 1. All 0’s
0 2. Scan columns with To check
For any
one 0 to locate a Press/Release
pressed key
• With no keys pressed, all row inputs are 1‘s
• due to the pull up resistors connected to Vcc
• Column outputs are sequentially scanned as 0‘s
• If key (X,Y) is pressed, it connects the scanning
0 from column X output to row Y input. If no other key
is pressed on the same column, this allows the pressed
key to be identified.
PORT CONNECTIONS
Keyboard Circuit Connections and
Interfacing - Software Keyboard Interfacing
When no keys are pressed, the column lines are held high by
the pull-up resistor connected to +5V.
Pressing a key connects a row to a column. If a low is output
on a row and a key in that row is pressed, then the low will
appear on the column which contains that key and can be
detected on the input port.
• If the row and column of the pressed key is known , you
then know which key was pressed, and you can convert this
information into any code you want to represent that key.
An easy way to detect if any key in the matrix is pressed is
to output 0‟s to all rows and then check the column to see if
a pressed key has connected a low to a column
Two key lock out
first output lows to all the rows and check the
columns over and over until the column are all high.
This is done before the previous key has been
released before looking for the next one. In the
standard keyboard terminology, this is called two-
key lockout
Software keyboard interfacing - algorithm
Once the columns are found to be all high, the program enters
another loop, which waits until a low appears on one of the columns,
indicating that a key has been pressed.
This second loop does the detect task for us. A simple 20- ms delay
procedure then does the debounce task.
• After the debounce time, another check is made to see if the key is
still pressed. I
f the columns are now all high, then no key is pressed and the initial
detection was caused by a noise pulse or a light brushing past a key.
If any of the columns are still low, then the assumption is made that it
was a valid key press.
Flow chart
Still Wait for any remaining
pressed keys
Software Debounce
to be Released
Of Switch Release
into CF
the port B lines are polled continuously till a key closure is sensed.
The routine DEBOUNCE is called for key debouncing. The
key code depends upon the selected row and a low
sensed column.
Interfacing a 4*4 keyboard
Example
The higher order lines of port A and port B are left unused.
The address of port A and port B will respectively 8000H and
8002H while address of CWR will be 8006H.
The flow chart of the complete program is as given.
The control word for this problem will be 82H. Code segment
CS is used for storing the program code.
• Key Debounce : Whenever a mechanical push-button is
pressed or released once, the mechanical components of the
key do not change the position smoothly, rather it generates a
transient response
Flowchart
Example
These transient variations may be interpreted as the multiple
key pressure and responded accordingly by the
microprocessor system.
To avoid this problem, two schemes are suggested: the first
one utilizes a bistable multivibrator at the output of the key to
debounce .
The other scheme suggests that the microprocessor should be
made to wait for the transient period ( usually 10ms ), so that
the transient response settles down and reaches a steady
state.
A logic „0‟ will be read by the microprocessor when the key is
pressed.
Example
In a number of high
precision applications, a
designer may have two
options- the first is to
have more than one 8-bit
port, read (write) the port
one by one and then from
the multibyte data, the
second option allows
forming 16-bit ports using
two 8-bit ports and use
16-bit read or write
operations.
ALARM CONTROLLER
Pre-Settable Alarm System
Program Statement :
Design a pre-settable alarm system using
8253/54 timer.
Use thumbwheel switches to accept 4 digit value in