Title: Digital Display
1Chapter 6
2Every-Day Digital Display
- Digital displays are found on many devices, one
being a microwave oven timer. Each of the 3
digits is a 7-segment display controlled by a
microcontroller.
3What's A 7-Segment Display?
- A 7-segment display is a package with 7
bar-shaped LEDs arranged to allow the display of
many useful digits and some letters. - Each segment (labeled A-G) contains an LED which
may be individually controlled. DP is an eighth
LED, the decimal point.
4- Common cathode means that each segment's cathode
is connected to common pins 3 8, allowing the
anode of each to be connected to the
controller.Only one of these two pins will need
to be connected to vss.
Another version is the common anode. To the
right is a common cathode
5- By supplying anodes with Vdd, individual segments
can be energized.
6Activity 1 Building and Testing the 7 Segment
display
- Build the circuit to the left with power off
- Turn power on and verify that segment A is now lit
7- Now modify your circuit so segment B lights up
- Use the circuit diagram to the left for reference
- Repeat this procedure to check all remaining
segments on the display including the decimal
point
8- Displaying the number 3 by setting up the circuit
below - What segments would be lit to display the number
2 and the letter A? Now Try it!
9Activity 2 Controlling the Display
- Of course the BASIC Stamp can control Vdd to the
segments from the I/O pins. Start by
constructing the circuit below
10Programming the 7-Segment Display
- Enter, Run, and Save the code to the left
- Verify that each segment lights briefly
- Make a list that tells you which bs2 pin controls
which segment on the display
11Your Turn
- Comment low pincounter
- What effect should this have?
- Try it!!
Each segment should remain lit after it is
activatedright?
12Activity 3 Displaying Digits
- The HIGH and LOW instructions could be used to
control the display for digits 0-9 by energizing
the required segments, but it would require a
considerable amount of code. - Try displaying the number three again, but this
time make the basic stamp do it.
13All of this for one digit
14Displaying digits with less code
- DIRH OUTH OR DIRL OUTL are internal variable
locations (registers) which can be used to
control a single I/O pin or all I/O pins
simultaneously. This allows a single line of
code to display a unique digit.
15Two variables controlling 8 pins at once
- OUTH
- Refers to the output condition (5V or 0 Vthat is
1 or 0) for the top 8 pins15 8 in that order - SYNTAX
- OUTH 00000000
- This would set all 8 pins to output 0 volts or
respond to inputs of 0 volts - OUTH 11111111
- This tells the pins to output 5 Volts or respond
to 5V inputs
- DIRH
- Refers to the directionthat is input (0) or
output(1) - SYNTAX
- DIRH 11111111
- This would tell all 8 pins to act as outputs, not
inputs - DIR 00000000
- This tells the pins to act as input pins, not
output pins
16To make sense of the outh commands, it is often
convenient to view the circuit upside down
This command would make a 3 appear
OUTH 11010110
17Lets use these registers to create the number
three againTRY IT!!
- Very helpful when deciding how to turn on
specific segments - Set output condition of top 8 pins to 0 volts
- Direct 8 top pins to behave as output pins
- These two commands clear the display
- Light specific segments to create the number 3
18Enter, Run and Save the code on the next slide (
page 177 of your text.)
- Verify that the decimal digits 0 through 9 are
displayed
19(No Transcript)
20How DisplayDigits.bs2 works
- Tells pins 8 15 to output 0 Volts
- The direction of these pins are all output not
input - Activate the segments required to make a 0
appear - Wait for one second
- Create the number 1
21Now modify the program so that the letters
A,b,C,d,E,F are displayed instead of the 0 - 9
- Note Pay attention to the difference in capital
and lower case letters above..
22Using LOOKUP for Lists
- The LOOKUP command allows you to, well, lookup
elements in a list. - LOOKUP index,7,85,19,167,28,value
- Index is a variable to point to a list position
with the 1st being the zero position. - The values in 's are the list elements.
- Value is a variable that will be used to store
the value that was indexed.
23- For example, if the value of index 0
- LOOKUP index, 7,85,19,167,28,value
If the value of index 3 LOOKUP
index,7,85,19,167,28,value
24Enter, Run, and Save the code below
- The LOOKUP command can be used to make displaying
the 7-segment digits much cleaner and simpler.
Note the data that index points to is loaded into
OUTH!!
25Note the following
- The program functions the same as
DisplayDigits.bs2 - The debug terminal shows how the value of index
is used by the lookup command to load the correct
binary value into OUTH list
26Using LOOKDOWN to Find Index
- LOOKDOWN works just opposite of LOOKUP in that
where a value lies in a list returns the index
for that value. - LOOKDOWN value, 7,19,28,85,167, index
- For example, if value 19, 1 would be the value
stored at the ones location. Since 19 is in the
1-spot in the list, 1 will be stored in index.
27Enter, Run and save the code on the next slide
(Page 183)
- Run the program as is with value 167
- Observe the debug terminal to see the index value
- Try setting the value variable equal to other
numbers in the lookdown list. Predict the debug
terminal outcome, and check your answer
28(No Transcript)
29You can also check to see if a value is gt,lt, or
to certain values
- Example
- value 35
- LOOKDOWN value, lt 7,19,28,85,167, index
- CHANGE LOOKDOWN AND VALUE TO THE LINES ABOVE, AND
CHECK THE RESULT - This would report the position of the number that
35 is just less than or equal to. So in this case
the answer would be 3
30Activity 4 Display Dial Position
- In this activity the segments of the display are
lit to indicate the position of a potentiometer
dial.
Build the circuit to the right.
31Lets use this to make the 7-segment display
mirror the position of the potentiometer
- Enter, Run, and Save the code on the next slide
(page 184 of your text). - Twist the potentiometer to see that the program
works - Adjust the code so the display more accurately
shows the position of the potentiometer
32How DialDisplay.bs2 works
- Charge and discharge rc-circuitsave discharge
time as time - Find the approximate position of the discharge
time in the list.save this position as index - Load the segment settings saved at this index
value into OUTH
33Your Turnadding a segment
- Save the current program as dialdisplayyourturn.bs
2 - Modify the program so that it causes all six
segments to light up as the pot is turnedas
opposed to only five