program. For details on encoder use, be sure to download column #8
(October 1995) from Parallax or from the Nuts & Volts website
( www.nutsvolts.com) — that way we can focus on the MC14489.
LOCK IT UP
I’ve been asked a couple of times about creating a digital lock, but
wasn’t really sure what to do it with — until I saw Chris’ use of a rotary
encoder on the solder-pot project. So, what we’re going to do this month
is create a digital version of the old combination lock. Figure 3 shows
the connection for the encoder and a push button (we’ll use it to select
our digit), and Figure 4 shows the connections to the SLED4C display.
In Figure 2, you’ll see two headers that are included with the SLED4C,
which let you decide how you’re going to mount the unit. I soldered in the
right-angle header so I could pop it into a breadboard, but if you’re going
to mount the display in a tight space, you may want to use the straight
header (solder it with the long pins facing the back side of the display).
Before we get into the lock code, let’s talk about the MC14489. As
I previously stated, it’s pretty easy to use but does have a couple of
quirks. The key to succeeding with the MC14489 is understanding those
quirks. Communication to the MC14489 comes in the form of two packets: we either send a one-byte configuration value or six nibbles that
control the digits of the display (the sixth nibble handles display brightness and the decimal point position).
Quirk number one is that we can only send a nibble to each digit.
Initially, this seems like no big deal — until we want to do a custom display that doesn’t involve a standard number or letter that one might see
on a seven-sement LED. Since each digit gets only four bits, when we
enter what is called “no decode” mode, we only have control of segments A-D, and segments E-G get disabled in this mode.
Before I forget, let’s discuss the display modes. Hex decode displays digits, 0-F, based on the value of what’s sent to the bank register.
Special decode displays other letters and characters — things like “P”
or an equal sign. No decode mode is just that — we have control of the
individual outputs that control segments A-D.
Quirk number two is that the display configuration is packed into
one byte, so we don’t have absolute control over every digit for every
possible mode. Table 1 shows the structure of the configuration byte.
Notice how banks 1-3 are grouped together (using bit 6), and banks
4 and 5 are grouped together (using bit 7)? The bottom line is that any
digit can be set to hex decode mode by making its control bit (1-5) zero;
any digit within the same group can be in no decode or special decode,
but within the same group, you cannot mix no decode and special decode modes.
I know that’s a mouthful. Once you understand that you can’t mix
no decode and special decode modes in the same group, it’s easier to
deal with the MC14489. Again, communicating with the chip is quite
◗ TABLE 1: STRUCTURE OF THE
Bit0 - Display control; 0 = off, 1 = on
Bit1 - Bank 1 mode; 0 = Hex decode, 1 = Set by Bit6
Bit2 - Bank 2 mode; 0 = Hex decode, 1 = Set by Bit6
Bit3 - Bank 3 mode; 0 = Hex decode, 1 = Set by Bit6
Bit4 - Bank 4 mode; 0 = Hex decode, 1 = Set by Bit7
Bit5 - Bank 5 mode; 0 = Hex decode, 1 = Set by Bit7
Bit6 - 0 = No decode, 1 = Special decode (for Banks 1-3)
Bit7 - 0 = No decode, 1 = Special decode (for Banks 4-5)
easy, and can be handled with two subroutines.
Enable = 0
SHIFTOUT DataIO, Clock, MSBFIRST, [config]
Enable = 1
Enable = 0
SHIFTOUT DataIO, Clock, MSBFIRST,
Enable = 1
As you can see, the Enable input of the MC14489 is active-low, so
communication with the chip starts by bringing this pin low. Then we’ll
send (via SHIFTOUT) either one byte or six nibbles. The MC14489 will automatically put everything in the right place based on how many bits are
sent. Note that we are using individual nibbles for bank control, so we
have to use \4 in SHIFTOUT to specify four bits for each variable (the default bit count is eight). By using individual nib- ■ FIGURE 2: SLED4C MODULE
bles and this subroutine,
we get the most flexibility for our programs.
Let’s have a look
at the lock code. Structurally, it’s pretty simple.
What we want to do is
to display the current
dial value as the encoder is turned. When
■ FIGURE 3: ENCODER CONNECTION
November 2005 NUTS & VOLTS 85