
What is a Microcontroller (Paralax, v2.2, student guide, 2004)
.pdf
|
|
|
Chapter #5: Measuring Rotation · Page 163 |
|
|
|
|
prevTime |
= time |
' Store previous time reading |
|
HIGH 7 |
|
|
' Read pot using RCTIME |
PAUSE 10 |
|
|
|
RCTIME |
7, 1, time |
|
|
time = |
time + 330 |
' Scale pot, match servo range |
|
|
|
||
IF ( time > prevTime + 2) THEN |
' increased, pot turned CCW |
||
HIGH |
13 |
|
' Bi-color LED red |
LOW 12 |
|
|
|
ELSEIF |
( |
time < prevTime - 2) THEN |
' value decreased, pot turned CW |
LOW 13 |
|
' Bi-color LED green |
|
HIGH |
12 |
|
|
ELSE |
|
|
' Servo holding position |
LOW 13 |
|
' LED off |
|
LOW 12 |
|
|
|
ENDIF |
|
|
|
PULSOUT 14, time
LOOP
P2. The key is to add IF…THEN blocks; an example is shown below.
'What's a Microcontroller - Ch5Prj02_ControlServoWithPot.bs2
'Read potentiometer in RC-time circuit using RCTIME command.
'The time variable ranges from 126 to 713, and an offset of 330 is
'needed.
'Modify so the servo only rotates from 650 to 850.
'{$STAMP BS2}
'{$PBASIC 2.5}
DEBUG "Program Running!"
time VAR |
Word |
|
|
DO |
|
|
|
HIGH 7 |
|
|
' Read pot with RCTIME |
PAUSE 10 |
|
|
|
RCTIME |
7, 1, time |
|
|
time = |
time + 330 |
' Scale time to servo range |
|
IF (time |
< 650) THEN |
' Constrain range from 650 to 850 |
|
time |
= |
650 |
|
ENDIF |
|
|
|
IF (time |
> 850) THEN |
|
|
time |
= |
850 |
|
ENDIF |
|
|
|
PULSOUT 14, time
LOOP
Page 164 · What’s a Microcontroller?
Further Investigation
Several different electronic components, concepts and techniques were incorporated in this chapter. Some of the more notable examples are:
•Using a potentiometer as an input device
•Measuring the resistance/capacitance of a device using RCTIME
•Performing math on an input value and recycling it into an output
•Controlling a motor based on a measured value
“Advanced Robotics: with the Toddler”, Student Workbook, Version 1.2, Parallax Inc., 2003
“Robotics with the Boe-Bot”, Student Workbook, Version 2.0, Parallax Inc., 2003 “SumoBot”, Student Workbook, Version 1.1, Parallax Inc., 2002
Every Stamps in Class robotics text uses RCTIME to measure resistive sensors to detect a variety of conditions. Each condition leads to math and decisions, and the end result is robot movement.
“Basic Analog and Digital”, Student Guide, Version 2.0, Parallax Inc., 2003
Basic Analog and Digital uses the potentiometer to create a variable voltage, called a voltage divider, which is analyzed by an analog to digital converter. A potentiometer is also used as an input device to set the frequency of a 555 timer. This text takes a closer look at the math involved in RC voltage decay.
“Applied Sensors”, Student Guide, Version 1.3, Parallax Inc., 2003
RCTIME is used extensively in this book to collect data from a variety of sensors.
“Industrial Control”, Student Guide, Version 2.0, Parallax Inc., 2002
This book introduces techniques used extensively in industry for controlling machines based on sensor input. The techniques fall under the general category of control systems.

Chapter #6: Digital Display · Page 165
Chapter #6: Digital Display
THE EVERY-DAY DIGITAL DISPLAY
Figure 6-1 shows a display on the front of an oven door. When the oven is not in use, it displays the time. When the oven is in use, it displays the oven’s timer, cooking settings, and it flashes on and off at the same time an alarm sounds to let you know the food is done. A microcontroller inside the oven door monitors the pushbuttons and updates the display. It also monitors sensors inside the oven and switches devices that turn the heating elements on and off.
Figure 6-1
Digital Clock 7-Segment
Display on Oven Door
Each of the three digits in Figure 6-1 is called a 7-segment display. In this chapter, you will program the BASIC Stamp to display numbers and letters on a 7-segment display.
WHAT’S A 7-SEGMENT DISPLAY?
A 7-segment display is rectangular block of 7 lines of equal length that can be lit selectively to display digits and some letters. A very common form is the 7-segment LED display, a package with a rectangular block of 7 LEDs. Figure 6-2 shows a part drawing of the 7-segment LED display you will use in this chapter’s activities. It has one additional LED, a dot that can be used as a decimal point. Each of the segments (A through G) and the dot contains a separate LED, which can be controlled individually. Most of the pins have a number along with a label that corresponds with one of the LED segments. Pin 5 is labeled DP, which stands for decimal point. Pins 3 and 8 are labeled “common cathode”, and they will be explained when the schematic for this part is introduced.

Page 166 · What’s a Microcontroller?
|
Common |
|
|
|
Cathode |
|
|
10 9 |
8 7 |
6 |
|
G |
F |
A |
B |
|
|
A |
|
|
F |
B |
|
|
|
G |
|
E |
C |
|
|
|
|
D |
|
E |
D |
C |
DP |
1 2 |
3 4 |
5 |
|
|
Common |
|
|
|
Cathode |
|
Figure 6-2
7-Segment LED Display Part Drawing and Pin Map
Pin Map: Figure 6-2 is an example of a pin map. A pin map contains useful information that helps you connect a part to other circuits. Pin maps usually show a number for each pin, a name for each pin, and a reference. Take a look at Figure 6-2. Each pin is numbered, and the name for each pin is the segment letter next to the pin. The reference for this part is its overall appearance. You know by looking at the top of the display that pin 1 is closest to the lower-left corner of the display. Other parts have more subtle references, such as the flat spot on a regular LED’s case.
Figure 6-3 shows a schematic of the LEDs inside the 7-segment LED display. Each LED anode is connected to an individual pin. All the cathodes are connected together by wire inside the part. Because all the cathodes share a common connection, the 7-segment LED display can be called a “common cathode” display. By connecting either pin 3 or pin 8 of the part to Vss, you will connect all the LED cathodes to Vss.

Chapter #6: Digital Display · Page 167
1 |
4 |
6 |
7 |
9 |
E |
C |
B |
A |
F |
10 |
5 |
|
G |
DP |
|
|
|
Figure 6-3 |
|
LED’s |
7-Segment |
|
Schematic |
|
|
|
3 |
8 |
ACTIVITY #1: BUILDING AND TESTING THE 7-SEGMENT LED DISPLAY
In this activity, you will manually build circuits to test each segment in the display.
7-Segment LED Display Test Parts
(1) 7-segment LED display
(5) Resistors – 1 kΩ (brown-black-red)
(5) Jumper wires
7-Segment LED Display Test Circuits
√With power disconnected from your Board of Education or HomeWork Board, build the circuit shown in Figure 6-4 and Figure 6-5.
√Reconnect power and verify that the A segment emits light.
What’s the x with the nc above it in the schematic? The nc stands for not connected or no-connect. It indicates that a particular pin on the 7-segment LED display is not connected to anything. The x at the end of the pin also means not connected. Schematics sometimes use just the x or just the nc.

Page 168 · What’s a Microcontroller? |
|
|
|
|
|||
|
|
|
|
Vdd |
|
|
|
|
|
|
|
1 kΩ |
|
|
|
nc |
nc |
nc |
nc |
|
nc |
nc |
nc |
X |
X |
X |
X |
|
X |
X |
X |
1 |
|
4 |
6 |
7 |
9 |
10 |
5 |
E |
|
C |
B |
A |
F |
G |
DP |
|
|
|
|
|
|
|
LED’s |
Figure 6-4
Test Circuit Schematic for the ‘A’ Segment LED Display.
3 |
8 |
||||||
|
|
|
|
|
|
X |
|
|
|
|
|
|
|
||
|
|
|
|
|
|
nc |
|
Vss |
|||||||
|
P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P1 P1 P1 P1 P1 P1 X 0 1 2 3 4 5 2 |
X3 |
|
Vdd |
|
Vni |
|
Vss |
Figure 6-5
Test Circuit Wiring Diagram for the ‘A’ Segment LED Display
√Disconnect power, and modify the circuit by connecting the resistor to the B
LED input as shown in Figure 6-6 and Figure 6-7.

|
|
|
Vdd |
|
|
|
|
|
1 kΩ |
|
|
nc |
nc |
nc |
|
nc |
nc |
X |
X |
X |
|
X |
X |
1 |
|
4 |
6 |
7 |
9 |
E |
|
C |
B |
A |
F |
Chapter #6: Digital Display · Page 169
nc |
nc |
X |
X |
10 |
5 |
G |
DP |
|
LED’s |
Figure 6-6
Test Circuit Schematic for the ‘B’ Segment LED Display.
3 |
8 |
||||||
|
|
|
|
|
|
X |
|
|
|
|
|
|
|
||
|
|
|
|
|
|
nc |
|
Vss |
|||||||
|
P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P1 P1 P1 P1 P1 P1 X 0 1 2 3 4 5 2 |
X3 |
|
Vdd |
|
Vni |
|
Vss |
Figure 6-7
Test Circuit Wiring Diagram for the ‘B’ Segment LED Display
√Reconnect power and verify that the B segment emits light.
√Using the pin map from Figure 6-2 as a guide, repeat these steps for segments C through G.
Your Turn – The Letter A and the Number Two
Figure 6-8 and Figure 6-9 show the digit ‘3’ hardwired into the 7-segment LED display.

Page 170 · What’s a Microcontroller?
Vdd |
Vdd |
Vdd |
Vdd |
Vdd |
||||
|
|
|
|
|
|
|
|
|
nc |
|
|
|
|
|
|
|
|
|
nc |
||
X |
|
|
|
|
|
|
|
|
|
X |
||
1 |
|
4 |
6 |
7 |
9 |
|||||||
E |
|
|
|
C |
B |
A |
|
F |
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 kΩ (all)
|
nc |
|
X |
10 |
5 |
G |
DP |
|
LED’s |
Figure 6-8
Hardwired Digit ‘3’
The digit “3” is shown on the 7- segment LED display using the circuit shown in this schematic.
3 |
8 |
|
|
|
X |
|
|
Vss |
nc |
|
|
|
|
|
|
P0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P1 P1 P1 P1 P1 P1 X 0 1 2 3 4 5 2 |
X3 |
|
|
|
|
Vdd |
|
|
|
Vi |
Figure 6-9 |
|
|
n |
Wiring Diagram for |
|
|
|
|
|
|
|
Figure 6-8 |
|
|
Vss |
|
√Build and test the circuit shown in Figure 6-8 and Figure 6-9, and verify that it displays the number three.
√Draw a schematic that will display the number two on the 7-segment LED.
√Build and test the circuit to make sure it works. Trouble-shoot if necessary.
√Repeat for the letter ‘A’.

Chapter #6: Digital Display · Page 171
ACTIVITY #2: CONTROLLING THE 7-SEGMENT LED DISPLAY
In this activity, you will connect the 7-segment LED display to the BASIC Stamp, and then run a simple program to test and make sure each LED is properly connected.
7-Segment LED Display Parts
(1) 7-segment LED display
(8) Resistors – 1 kΩ (brown-black-red)
(5) Jumper wires
Connecting the 7-Segment LED Display to the BASIC Stamp
Figure 6-10 shows the schematic and Figure 6-11 shows the wiring diagram for this BASIC Stamp controlled 7-segment LED display example.
√Build the circuit shown in Figure 6-10 and Figure 6-11.
Schematic and pin map: If you are trying to build the circuit from the schematic in Figure 6- 10 without relying on Figure 6-11, make sure to consult the 7-segment LED display’s pin map (Figure 6-2, page 166).

Page 172 · What’s a Microcontroller? |
|
|
|
|
|
|
|
1 kΩ |
|
|
|
|
|
|
|
(All) |
|
|
|
|
|
|
|
P15 |
|
|
|
|
|
|
|
P14 |
|
|
|
|
|
|
|
P13 |
|
|
|
|
|
|
|
P12 |
|
|
|
|
|
|
|
P11 |
|
|
|
|
|
|
Figure 6-10 |
P10 |
|
|
|
|
|
|
BASIC Stamp |
P9 |
|
|
|
|
|
|
Controlled 7- |
|
|
|
|
|
|
Segment LED |
|
P8 |
|
|
|
|
|
|
|
|
|
G |
F |
|
|
Display |
|
E |
C |
DP |
A |
B |
Schematic |
||
LED’s |
|
|
|
|
|
|
|
|
|
|
common |
|
|
|
|
|
|
Vss |
|
|
|
|
Be careful with the resistors connected to P13 and P14. Look carefully at the resistors connected to P13 and P14 in Figure 6-11. There is gap between these two resistors. The gap is shown because pin 8 on the 7-segment LED display is left unconnected. A resistor connects I/O pin P13 to 7-segment LED display pin 9. Another resistor connects P14 to 7- segment LED display pin 7.