Page 221 - Making PIC Microcontroller Instruments and Controllers
P. 221
2ls cREAfll|OACCUhAIE I{TEBVAIS WttH flitERS! tHE MEInOI|OIES
value onTimero
:liiltiiaii*lgAi Basic program to see the eflect of the prescalar
AzD V VIR BYTE ; creaLe A2D Value to store resul!
DEFTNE AlC EtfS I ; set number of bits in resutt
DEFINE .A.DC CLOCK 3 j sel clock sou.ce (3=rc)
DEFIAIE .A.DC SAITPIJEUS 50 ; set smpling tine in uS
; The value is read with
ADCIN O, A2D V
_ E o i s p a r e o o n n - L D o r l - - p l o - - w i r t
t"cDout sFE, $c0. DEc3 a2D v
; The value is then placed in lhe prescalar wiLh
OPTION-REG= (A2D ! / 32)
When lhese lincs of code arc added to the lrogram the progran becones:
Cl'EllR ; aluays start with clear
DEFINE OSC 4 t defne oscillator speed
DEFINE I,CD DREG PORTD ; define LCD connecLions
DEFINE IJCD_..DBI! 4 ;4 bit path
DEFIIIE IJCD_RSREG PORTE ; select reg
DEFTNE tCD RSBTT 0 ; selecr brr
DEFINE LCD EREG FORTE ; enable reqasler
DEFINE LCD EBI! L t enable bi!
DEFIIIE .A.DC_BITS 8 ; set nurber of bits in resul!
DEETNE ADC CLOCK 3 ) sel clock source {3=rc)
DEFINE ADC SAUPI,EUS 50 i EeL sarpr 19 :me !n L.
LOw PORTE.2 ; nake 1ow for write only
; Seh rhe por! directions, We nust set all of PORTD and all of
; PORTE as ourputs
; even thoush PoRTE has only 3 1ines. rhe other 5 lines wiLl
; be iqnored by the systen.
j D O P I ' i s - e e d e d b e c a - s e . h e p - a z o s p - " k e . i . o r p i r . o f _ - i s p o - l .
IRIsc = %11111011 i ".a nora c.2 to speaker
; conneclion !o output
TRrsD = 800000000 ; seL all PORTD lines to outpuL
TRrSE - %00000000 ; seL all PORTE lines to oulpu!
X VtR I{ORD ; seL up the wariable
A2D V VAR BYTE ; create A2D Value to sLore result
.A.DCON1=%00000111 i set Lre Ara,og o D-gi -- .on ro]
; register
; needed for the 15F877A see notes
PAUSE 500 ; pause for LcD to start up
LCDOTI! SFE, 1 ; clear screen
O!{ IITTERR('PT GOTO I!trI ROIIITNE ; tel1s prograr where !o go on
; interrupt
(Cohtinued)