PHY 406 - Microprocessor Interfacing
Techniques
Module 3 - Digital Input and Output
Objective
In module 1 we looked some very simple analog input and output. In this module we do some
similar things for digital input and output. Our "model" is to control a small keypad and display
unit.
Preparation
You will need the following VIs
Functions>>Data Acquisition>>Digital I/O>>Read From Digital Port.vi
Functions>>Data Acquisition>>Digital I/O>>Write To Digital Port.vi
Make sure (by asking if necessary) that you understand the circuit diagram for the keypad and
display interface keypad.pdf
This module will also tax your knowledge of LabVIEW programming. Two very useful concepts
that you should be sure you understand are the use of "sub-VIs" to encapsulate code so that you
don't have to program it again or have it cluttering up your screen, and the concept of "constant
arrays" which allow you to deal with "if the number I get is A, then the result I want is B" when
there is no simple mathematical relationship (or there is, but it's a pain to compute) between A
and B
Equipment
You will need the keypad and LED display interface which is kept in the cupboard. All the
interfaces should be identical so there should be no need to record the number of the interface
unless the thing doesn't work!
There has been one problem with a computer failing to run the interface because of a fuse failure
in the interface. If it doesn't seem to be working at all - no lights, no numbers - try running the
test program to see if it is the interface or your program
The interface consists of a single digit LED display which has seven segments (hence it is often
called a "seven-segment" display) and a decimal point each of which can be individually
controlled from single bits of the PB port which is an output port. There is a also a 4x4 keypad
which is scanned by four bits of the PB port and produces results in the lower four bits of the PA
input port. The upper 4 bits of that port are always 0.
Your mission, Jim, should you decide to accept it, is to make this interface work in a logical
manner.
Digital I/O
- The demonstration VI e:\l_view\examples\keyboard.vi gives you the port numbers to use
with the interface. Why is the shift register used? The output function of the VI activates the
lines PB0-7 with a bit pattern which is supplied from the control Output Pattern. Notice the
use of a binary display to make things easier. Make a simple VI to display a number from
0-20 on the LED display when you enter it from the computer keyboard (not the keypad
beside the LED display). You will have to get inventive to display numbers >9 with a single
digit, but you may invent you own patterns for those.
- Input is more of a problem. You will need to "scan" the keypad by raising each of the lines
PB4-7 high in turn and then "sampling" the input on PA0-3. (e.g. you can raise PB5 by
sending the bit pattern 00100000). The bit inputs will be 0 unless the corresponding key of the
matrix is depressed, in which case you will get a "1" in the corresponding location. Write a
VI to display the number of the key pressed on the computer screen. You should ensure that
an invalid keypress (such as two keys pressed at once) is detected and some sort of alarm
condition activated until things clear up.
- Make your two Vis into sub-VIs (see the tutorial) and use them in a VI to take the number
from the keypad and put it in the LED display. This will be a problem because the display
lines are used for both purposes. Things are therefore not perfect. Use your ingenuity - and
some modified timing - to produce the best visual result in the display.
Advanced
This section is for the intelligent/bored or otherwise fascinated. There are no marks for this
section - only the satisfaction of solving a problem or two.
- One of the problems that keyboards suffer is "bounce". It isn't visible on your system because
the sampling with the VI (which you will remember is of the order of mS) is too slow. How
would you defend against "bounce" where a key repeated connects and disconnects before
settling to the new state?
Notes
This problem of things being used for two purposes which interfere with each other is common.
Although it would be desirable for you to always have "one thing one job" it isn't always
economically feasible. Sometimes you have to compromise and make the best of it.