Page 86 - Making PIC Microcontroller Instruments and Controllers
P. 86
76 CO IROLL|I{G lllE OUtPUt A D nEADll{G THE lllPUT
lhe
$nilm$ffiF.Ki# Potenliometer readings (Displaying value oi the potenliometer
in all formats) {Contnued)
'the.onrl
? G poctun I ould look like,he lorlou in8:
DEFINE LCD_DRIG PORID ; deine LcD regislers and bils
DEFINE LCD-DB!t 4
DEFTNE LCD_RSRTG POREE
DEFINE LCD_RSBIT O
DEFINE IJCD_EREG PORTE
DEFINE I,CD_EBIT 1
A2D 1/Aj-UE 1IAR BY'JE r cieate A2D Value !o store resutt
' SEt PORTA SE! PORTD
IRISA . %11111111 r wet PoRTA lo aLl input
TRISD = %00000000 ; wet PORTD to all output
A.DcoNo . %11000001 ; conngare and tuln on a/D Modute
ADcoNl = %00000010 , set PoRTA malos and LEFT justify
PAUSE 500 ; wait 0.5 second for LcD startup
[ooP:
AI)CONo.2 = t t start conversion
NqF-DOIIE:
IA ADCONo.2 = 1 THEN NCri! DONE ; wait for 1ow on bit 2 of aDcoNo,
-or \ -rsi on finisl es
A2D \rALI'E = A.DRESI| ; move hiqh byte of lesult lo A2D Value
t.cDOUt gFE, 1 ; cLear screen
t|cDOUt[ .DEC VA'!UE- \, DEC A2D_vIlttE, z \ ; Display 3 values
'gEX=", \rzBIN=zr
LDOUT $FE, 9C0, HEx2 A2D-VALIIE,' BIN8
AzD VrrUE, z
PORTDlIrD_vArrttE ; dispLays vatue in baigraph
PAUSE 100 ; wair 0.1 second
GOIIO I,oOP ; do it forever
END ; end Progra
In Program 5.16, we used the named rcgiste themselves to set up the conversions-
In the prognm in the next section, we will use the power of the compiler and its
related commands to read the three pots much more conveniently by using lhe
ADCIN command.
Read All Three Potentiometers and
Display Their Values on the LCD
Five of the six pins on PORIA can be used as analog inputs. In our case, phs 0, 1, and
3 are connected to the tkee potentiometers. (Pin A4 cannot be used.)