Page 199 - Making PIC Microcontroller Instruments and Controllers
P. 199
PBOJECi t r95
Max counl: 9999 in 0.25 secords
39.996 in I second
There are 20 counts per revolution, which givcs:
1.999.0 rcvolutions per secordr, or
(39,996/204"60 rcvolutior\s per m in ut e
Wc can detect (but no! display) a maxinum of 119,940 rpm if we count 20 counts
per rcvolution for 0.25 seconds. If we want to detect and display a higher rpm, we musl
reducc the time interval in thc COUNT instruction or dccrease the eDcoder count
We have already set up PORTD with the lower 4 biN as oumu$ (but if we had not we
would have 1() add the line of code to do thao. After insering an appropriate decision-naking
instruction, we can usc any of these piDs for an output signal to nn apFopriate device.
as covercd in Chapter 5, the signal on any of
lf we amplify the signal appropriately,
the output pins mentioDed carlier can be used to control a heater or punp or whatever
elsc we have in mind.
SEVEN.SEGMENT DISPLAYS
displays come in two types: conlmon anode and common cathode ln
Scvcn-segment
bolh rypes, one side of a1l thc LEDS is wired together lo make a common conneclron
In our expenments, we will use common anode (CA) displays only (see Figure 15 7).
Most so-called seven-segment l-ED displays rctually have eight or nine LEDS in them.
The eighth and ninth LEDS are the decimal points on one ol two sides of the number
displayed. We willnotusethe decimal poinls forthis project, so wewill need only seven
lines, but we will wire in the eighth line ofthe po to activate one decinal poinl ofeach
display for possible futurc use.
arc used.
First. we need to unders[and a litl]e bit about how seven segmentdisplays
In a seven segment LED display, all the segments have one common leg, lhe onc that
will goto the anode. The data is impressed on the other ends ()1lhe LEDs,and when the
common legis connected to the power, whalevcr dala is impressed on the segments gets
turned on. The segments are turned on one al atime in mostcases, bulthey can also all
bc turned on sinullaneously. Often, there willbe more than one anode pin on adisplay,
bul allofthem will be connccted together inside the display. These extn pins are pro-
vided 1() makc it easier to lay ou1 the wirjng on a printed circuit board.
All the display scgnrents for each of ihe displays are connected in parallel to the data
lines to ore PIC port, and each ofthe con lon lines is assigned to a scparate line from
the PIC on anothef porl. Each ofthe seven-segment modules is eneryizrd one at a time
in rapid succession so that it sccms to the human eye that they are all on at the same
ljmc. Deciding how ]ong cach segment must be lit and how often the disphy must
bc rcfieshed can be done on a trial'and-effor basis 1i11 you come up with lhc best dis-
The segnents arc all the same sizet so they
play possible under the circumstances.
requirc the same cunent, butthe decimalpoint is smallerandnccds less cuffent. It 1nay
be necessary to power it for a shorter limc or provide a larger rcsistor for it to malch
the brightress olall thc other segnents.