the tens and ones digits from the dial value for banks 4 and 3.
There is a conditional constant in the program called ShowState
that is used for testing. Its purpose is to show the current state of the
lock code using the LEDs that form the colon in the SLED4C display.
These LEDs can be individually controlled and are connected to bank
1 bits zero and one. If ShowState is set to one, then LOOKUP gets used
to enable the correct number of LEDs for the current state. Otherwise,
they are all blanked (for normal operational mode).
Now that the register variables are updated, we will turn the display
off. Why? Well, we don’t have to, but what can happen is a bit of “
ghosting” that just doesn’t look very nice. Even with a stock BS2, the blanking
and update happens so fast that we can’t see the blanking period.
After the new values are sent to the bank control registers, we
update the configuration register. Bit 0 will always be set to enable the
display. Bits 1, 2, and 5 are set to one, which means they will either be
in no decode or special decode mode, which depends on bits 6 and 7.
In this case, both are set to zero, so banks 1, 2, and 5 will be in no decode mode (remember that this mode gives us control over segments
A-D only). Banks 3 and 4 are set to hex mode (0 in their configuration
control bits), so we can display the dial digits.
Here’s where that configuration byte quirk affected the program.
Initially, I wanted the display to show “-XX-” (dash-digit-digit-dash),
but when using the SLED4C, the bank 1 digit needs to be set to no decode mode to enable control of the colon LEDs. This forces the use of
no decode mode for banks 2 and 5 as well (so they match), and in that
mode we cannot control segment G (which would make the dash we
wanted). So, we live with the underline.
At this point, the display should show “_00_” — until we turn the
dial. Here’s the code that handles the encode input.
DO WHILE (NumSelect = NotPressed)
encNew = Encoder & %0011
IF (encNew <> encOld) THEN
dial = dial + 1 + (98 * (encA ^ encB)) // 100
encOld = encNew
DO : LOOP WHILE (NumSelect = Pressed)
As you can see, we’re simply monitoring the encoder while the
button is not pressed. If it moves, the dial value gets updated and we
save the new encoder position for the next check. The only tricky bit
here is this:
dial = dial + 1 + 98 * (encA ^ encB)) // 100
You may remember from all of my discussions about the modulus
operator (//) that, if you want to increment a value between 0 and 99
with rollover, you can do this:
value = value + 1 // 100
And, if you want to decrement a value between 99 and 0 with roll-under, you can do it like this:
value = value + 99 // 100
If you look closely at the program, we’ve cleverly incorporated
these two lines of code — how it operates is based on the encoder
test. By XORing the encoder bits, we can determine direction, so that
The One-Stop Source
For All Your
We’re adding hundreds of new robotics
products every month. Plus we’ll continue
to supply favorites like Muscle Wire®,
the OctoBot Survivor™ Robot and more.
A wide variety
for all your
Be sure to visit us at
or call 1.800.374.5764
November 2005 NUTS & VOLTS 87