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

couxflt{G w|lH Al EScAPEMEII 241



                    Pro$am  17.2   Program to count marbles with an escapement
                    CI,EAI                        i  d l w o y .  d  w  r  ' - - o '  . q r - o b  a
                    DSAr!iIE  OSC  4              ;  always   deine   osc   speed
                    :  A_  q-wer-   \e  w   l  oe           fol   rl  -  L  D  oo-  o   on  E!
                    DEFTNE  I.CD  DREG  PORTD       define  LCD connecrrons
                    DEFINE  I.CD  DBIE  4
                    DEFTNE  I.CD  RSREG  PORITE     select  reqisLer
                    DEFINE  I,CD  RSBIT  O
                    DEFINE  !.CD  ERIG  PORTE       enabLe regisLer
                    DEFINE  LCD  EBI!!  1
                    I,OW PORTE.2                    10{  mean we viLl  write  only
                    DEFINE  I,CD  COMMANDUS  2OOO   delay  in  nicro  seconds
                    DEI'INE  ']CD  DATAUS  50       detay  in  micro  seconds
                    DEFINE  ADC  BITS  8            se!  number of  bits  in  result
                    DEFINE  ADC  CLOCK  3           set  internal   clock  source  (3=rc)
                    DEFIIIE   ADC  SAIIPISUS   50   se!  sanpllng  rine  in  us

                    ;  N e ^  r e  e t  c  t f e  p o -  r o  -  - q u i l - d  d  ' -  . o n
                    ;  and  se!  their   bits   hierh  and  1o0

                    TRISB=%11110000                 set  PORTB direcLion
                    PoRtB=%o0001110
                    TRIsc=%00000000                 set  PORTC direcrion
                    PoRIc  =%00000000
                    ERIsD=%00000000                 se!  PORTD  direclion
                    PoRrD  =%00000000
                    PoRaE  =%00000000               se!  PORTE direction
                                                    bo  nake  lhe  systen  digiLaL
                                                  s  for  the  liner
                                                  for  bhe  pullups  and  the  prescalar

                    AlcoNl  =%00000111              set  a,  E  registers   to  digital
                    INTcoN=%l0100000                set  intefupt   conLroL  reg  bits
                    oPuoN  REc=%o0000101            set  oplion  reg  bits
                                                                L o .
                                                             o .      o  s 6 . o . d
                    ;  To  allow  the  LCD Lo  cone  up  to  speed  and  cLear  Lhe  screen

                    PAUSE  5OO
                    r,cDonr  sFE, 901

                    Assien variablcs for rhe servos. and counters and set their vaLues

                    POTO VAR  BY'E                  create  adval  !o  store  resulL
                    POT1  VAR  BYTE                 create  adval  to  store  resulL
                    POf2  VAR  BYTE                 cieale  adval  to  store  result
                    AI,FHA  VAR  BY4E               coun!er  variable
   238   239   240   241   242   243   244   245   246   247   248