Page 76 - Making PIC Microcontroller Instruments and Controllers
P. 76

66   COI{TROIII G THE OUTPUT AIIT' READIIIG THE II{PUT



                                                      pins  at the J7 servo  position  control, with
                   !B|!$a$i5;del    use servo on  iumper
                    added tunctions
                    CI;EAR                            ;  clear  menory
                    DEFINE  OSC  4                    ;  osc  speed
                    DEFINE  LCD DREG FORED            ;  define  LCD connections
                    DEFINE  LD-DBIT    4              i
                    DEFINE  ICD_RSREC  PORTE
                    DEFTNE ICD_RSBIT  O               j
                    DEFINE  I|cD  AREG FORIE
                    DEFINE  I,CD_EBIT  T              i
                    DEFINE ADC_BITS  a                ;  set  nunrber  of  bits   in  result
                    DEFINE ADC CLOCR 3                ;  set  clock  source  {3=rc)
                    DEFINE ADC SAt{Pt tUS  50         ;  set  sanpling   line   in  uS
                    TRISA  -  %11111111               ;  set  PORTA to  all   inpu!
                    ERISD =  %00000000                ;  set  all  PORTD lines  ro  ourpuLs
                    A,DCONI  =  %00000111             ;  PORTA  and  PORTE to  digriLaf
                    LOW  PORIE,2                      ;  LCD R/W line  Low  (W)
                    A2D_VAlttE  VAR BY![E             ;  creaLe  A2D_Value  to  store  resr]li
                    A2D VALttEl  VAR BYTE             ;  creaLe  A2D VaLue  to  store  result
                    A2D vAlIrE2  VAR BIEE             :  r  6o-6  A. D,.e  -e  .o
                    POS VAR WORD                      ;  servo  posilions
                    CEIiIIERPOS vAR  WORD             ;  centex  posiLion
                    !4AXPOS VAR WOF                   ;  nax  position
                    MINPOS Vl.R 9|ORD                 ;  nin  position
                    POSSTEP vIR  BYTE                 ;  step  length
                    PAUSE 500                         ;  wait   -5  second
                    SERVOI VAR PORTC.I                ;  alias   sexvo  pin
                    AICIN  0,  A2D VllJttE            ;  read  channeL  0  to  A2D Value
                    OPTIOTiI_REG  =   $?F             ;  enable   pORTB  pu1l  ups
                    t,ol{  SERVO1                     ;  servo  output   low
                    GOSUB CENIER                      ,  center   servo
                    r,cDouE  $FE.  L                  ;  clears   screen  onLy
                    PORTB  E  0                       ;  PORTB lines   1ow  !o  iead  butlons
                    TRISB =  %11111110                j  Fndbl-  fi. s  bJ .  or   ou
                    MAINIOOP:                         ;  nain  progran   loop
                                                      ;  check  dy  buln  pres,d  !o  nove  servo
                      IF  PORTB.4  =  0  THEN GOSUB LEA!      ;  handle  lefL  nove
                      IF  PORIB.s  =  0  THBII GOSUB  CBNFER   ;  hand]e  cenLering
                      MOREB.5      =  0  THEN GOSUB RIGIIII   ;  handle  right   nove
                      ADCIN  0.  AzD_VALUE              ;  read  channel  0  to  A2D Value
                      IDCIN  1,  AzD  VAITUEL           ;  read  channel  1  to  A2D Value  1
                      A.DCIN 3,  A2D  VAlUE2            t  read  channel  2  !o  A2D,Value  2
                      MA,|IOS  =2350  -127  + A2D VAIJUE1  ;  max position   reLationship   defned
                      MINPOS  =750  +127-a2D_varuEl     ;  min  posiLion  relationship   defined
                      CnITERPOS=PO5-127  +  A2D vAI;ttE  ;  coter   posilion   reLationship   denned
                                                        ;  s  arr  sprvo  p!  s6
                        PAUSEUS POS                     ;  puLse  length
                      SER1IOI  =  0                     ;  end  servopulse
                      LCDOUT  gFE,   980,   'POS=".   DEC POS-127  +  A2D_VALUE .   \  \,DEC-
                    A2D VAIJLE,  z  \.DEC   A2D VAIrtEl,/   '.   .DEC  POSSIEP.'   .;
                      P A U S E 5                       :  s - ! . o  L p o a  -  a  -  a o o L l  5 0  L
                             1
                                                                                  (CantinueA
   71   72   73   74   75   76   77   78   79   80   81