Page 116 - Making PIC Microcontroller Instruments and Controllers
P. 116
iO5 IWENS AIID COUNTERS
rrlf;.tqliial!'gr€:a uslng Timero: Program counts the putses lrom a motor'driven
with the 2 PoTs)
eriioier (vou can cnange the speed ol lhe motorand the time forcounts
CI.EAR
DEFINE OSC 4
DEFINE I,CD DREG PORTD
DEFIIIE LCD RSREG PORTE register select
DEFINE LCD_RSBIII O
DEFINE LCD_EREG PORTE enable register
DEFINE ITD_EBII 1
DEFITiE I,CD R!{REG POREE read/wr!le regisrer
DEFINE I,CD RWBIT 2
DEFINE LCD BITS 8
DEI'INE I,CD I,INES 2 rines in display
DEFIIiIE I,CD COII!'ANDUS 2OOO delay in nicro seconds
DEFINE LCD DAIAUS 50 delay in nicro seconds
DEFINE CCP1 REG PORTC deine the hpm settings
DEAINE CCP1 BtlE 2
define the a2D walues
DEFINE ADC BITS 8 seL number of bits in resutl
DEFINE ADC CI.oCK 3 set inleina1 clock source (3=rc)
DEFINE ADC SAIIPLEUS 50 set sanpling tine in us
set the analog to digital controL
aDcoNl=%00000110 needed for the 16F8??A LcD
TEST VAR WORD
A,DVALO 1IAR BYTE create advaL to slore resulc
ADVAI1 1IAR EYTE create adval to store resutL
X l/TR WORD
Y VAR VIORI)
PAUSE 500
t cDour sFE, 1
OPTIOIiI-R!G=%00110 000
mlAo=0
set up the reqister 1/o
,
TRISC = %11110001 D O p f , 0 i . q o n g t o b o
s a - L . 1 e o o o ! l " / e " ' ' l r o
encoder for input
PORIC.3-0 enable the notor
POREC.2=0 set the rotation direcLion
tDcrN 0r A,DvAlo read chamel 0 to aDvALlJ
!.Dcrrir 1, ADVrrl read channeL 1 to l,DVAl,l
A.DCIAI 3, AD\IA!2 read channel 3 to ADVAL2