Page 88 - Making PIC Microcontroller Instruments and Controllers
P. 88
'F COXTNOLLIXG ?TE OUTPUT AI{D BEAbING IHE IIIPUT
Adding the Kind of Flexibility That
Defines Computer Interfaces and
Demonstrates the Ability to Make
Sophisticated Real-Time Adjustments
Program 5. 1 8 is riruilar to P n gram 5.16 that r)as derdloPed €drlie. but shows another
apFoach.
Use the three polentiometers to conlrol one R-/C selvo.
Control the relative location of the center position with POTo
Control limit position of the end positions with POT1.
Confol the rate of movement with POT2.
(Three potenliomelers
ffiffimalx*fK seruo/Potentiometers conirolling one
servoiconnecl the servo to JumperJT lofthls program)
CI,EAR
DEFINE OSC 4
DEFIIIE I,CD DREG PORTD deine LCD connections
DEFINE I,CD DBIT 4
DEFINE IJCD RSRAG PORTE
DEFINE I,CD_RSATT O
DEFINE LCD_EREG PORTE
DEFINE t,CD EBIT 1
LOW POREE.2 LCD R/w line low (r,i)
DEFINE ADC_BIES 8 set number of bits in resulL
DEFINE ADC_CI,OCK 3 set clock source (3=rc)
DEFINE ADC,SA!IPI,Et'S 50 set sanplinq line in us
TRIgt = %11111111 seL PORTA to a1t input
TRISD = %00000000 se! all PORTD Lines to outputs
.ADcONl = %00000111 PoRTA and PoRTE to digital
A2D VII-I'E VTJI BYTE create A2D-Va1ue to store resulL
AzD VII.UEI \rAR BYAE creare A2D vatuel to store result
A2D_VA',UE2 VlR BYTE cieate A2D Value2 to store result
POS VAR I'IORD se.vo posl.1ons
CENTERPOS VAR VICRD
IIAXPOS VAR }IORD
IIINPOS VAR IIORD
POSSTEP VAR BYEE
PAUSE 500