Page 77 - Making PIC Microcontroller Instruments and Controllers
P. 77
a,ign$ilii$.tat use servo on iumper
pins at lhe J7 Servo posirion controt. with
added unctions (Cortirued)
f
GOTO I4AINNOOP ; do it aLl forevex
IJEFT ! ; nowe servo left
IF POS < MAXPOS THEN POS = POS + POSSTEP
RETI'RN
RIGHT: move servo right
IF POg > MTNPOS IHEN POS = POS
RTTURN
CEMTER:
POS = 1540-127 + A2D VAIJI'E
RETURN
END
At this stage, we me starting to getan idea about how one might take a simpleprob_
lem and make it amenable to a more sophisficated solution by adding simple ha(lware
and software fea$res to it. We have gone from a simple but rigid control of the posi_
tionofa servo to a much more flexibleand user-ftiendly approach. Adding feature; like
these to our insfuments and controllers wjll make them more inruitive, useful, and
Readin the In uts
Now that we are beginning to leam how to conFol tbe output. we need to learn how to
read the inputs and manipulate the outputs based on what ihe input is. In orher worals.
e
$errcgoingroleamho$tocre. intefdcll\e.andrhU.mlr)be;oreu.efulprogfarn..
instruments, and controllers.
pusH
!=lD_M FnsI COLU |N, FtRsr ROw BUrroN (swll
A D TUR oI{ ait LED ol{Ly wHtLE rHE BUTToN (swti ts
DOWN
The simplest inputis to readjustone push button anal the simplest output is to tunljust
one LED ON. We will do just rhat bur we will add a tiule complication. The LED is to
be programmed to be ON only while the blrtton is held down. We will use button I atoD
left) on the keyboard and rhe LED connected ro PORTD.0. This emutares the operarion
jn
ofan ordinary momentary conract switch any real world application.
READII{G THE KEYBOARD
On the LAB-XI, all of PORTB is dedicared to the inrerface with rhe kevboard. Lines
B0lo BJ rre connecled lo the ro$i. and Lhe line\ 84 ro B7 are connecred ro rhe columns
of fhe keyboard. When the keyboard is not being used, the lines may be used for other