Page 120 - Making PIC Microcontroller Instruments and Controllers
P. 120
IIO TII'EES AND COUI{TEFS
-
:iiFiliiliieii a,? Timerl as counter (Timerl counls slgnals lrcm a molor encode4
(Continued)
X VAR }IORD ; spare tariable for experinenlation
Y VAR WORD ; spare variable for experinentarlon
PAUSE 500 , pause for LcD to slrart up
T,CDOIIT gFE, 1 ; cLear Display and cursor hone
; set uP ihe register I/O
ERIsc = %11110001 ; PoRTc- 0 is qloing to be the InpuL
ccPlcoN = %ooooo101 ; caplure ewerv rising edge
rlcotir = %OOooOO1l ; no prescale/osc offlsvnc on
; external source/TMRl on
; sLart the notor, usinq a notor encoder
PORTC.3-0 ; enabLe Lhe n'olor
PORTC - 2-1 ; set the rotation direction
; Next fe go inLo the bodv of Lhe prograi. fhe toop stails watn
; Lhree potenlioneters though tne are using onlv rhe frrst one Lo
; set the Pover
; and thus the speed of the notor.
a.DclN 0, a.DvAl,o read chamel 0 to aDvAL!
A.DCIN 1, ADI/AI,I
ADCIN 3, A.DVA'"2
; If Lhe duty cycLe of the notor is tess Lhan 20 out of 255 lhe
; notor wiLl noL cone on
; so we make an allowance for ihat and displav ihe condition on
IF ADVAI,O>zo IEIIEN
HP9!M 2. AD\rBlo, 32000
*Pl'l
