09.05.2015 Views

Microcomputer Circuits and Processes

Microcomputer Circuits and Processes

Microcomputer Circuits and Processes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

to the digit select. A very short program has to be written to scan across<br />

all of the digits in the display, making sure each gets its correct number.<br />

But that is cheaper than the previous suggestion.<br />

APPLICATION NOTE - KEYBOARD SCANNING AND INTERFACE<br />

A keyboard may be a typewriter-type board just like the one on a<br />

personal computer, it could be a music synthesizer's 4- or 5-octave<br />

keyboard, or it could be a small 16-key pad. To take this last example, it<br />

will have 16 switches <strong>and</strong> need the computer to determine the keys<br />

pressed. Each key is given a number, here 0 to 15, <strong>and</strong> when a key is<br />

pressed, say 3, the computer has to save the number 3 in one of its<br />

registers or in memory.<br />

The arrangement is shown in figure 4.15. The computer sends a 4-bit<br />

number (0 to 15) via an output buffer to a decoder, just like the ones<br />

discussed in Chapter 2.<br />

4-bit numbers<br />

from output<br />

port<br />

key s't WI Ches<br />

- 0 - -<br />

- 1 - -~<br />

•.<br />

2 - ~<br />

DECODER<br />

3 '-'<br />

·<br />

·• 1-- •••<br />

15 ~ ~<br />

common line<br />

to CPU<br />

-;.<br />

signals any key<br />

is pressed<br />

Figure 4.15<br />

A decoder chip is used to scan a keyboard made of 16 key switches.<br />

Remember, a decoder receives a 4-bit number, <strong>and</strong> then makes one<br />

of its 16 output lines go high. If the processor has output 0011 (3 10 ),<br />

then the decoder makes its output 3 high, which is connected to key<br />

switch 3. Notice that all the key switch outputs are connected together.<br />

If key 3 is pressed then the high gets through to this common line. If 4 is<br />

pressed the high does not get through. A high on the common line<br />

means number 3. The common line is connected directly to the<br />

microprocessor, so that the microprocessor knows that a key has been<br />

pressed, <strong>and</strong> stops. Now the microprocessor has been programmed to<br />

output not just 3, but all numbers 0 to 15 in order, over <strong>and</strong> over. So if<br />

key 3 is pressed continually then the common line will remain low until<br />

the processor has got round to outputting 0011. Then it will go high,<br />

<strong>and</strong> the microprocessor will be stopped. Its last output, 0011, will be in<br />

some register which can be got at <strong>and</strong> so used in another part of the<br />

program to implement whatever pressing key 3 is meant to do.<br />

53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!