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

flfEnt   227


                                    Metronome usinsTimerl  (Continuect)
                   liafiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiia!1i11!i9l:
                     ;  set  the  port  directions.   ire  nust  set  all  of  PoRTD and  all  of
                     ;  PORTE as  outputs
                     ;  even  lhorlgh  PORTE  has  only  3  1ines.   The  other   5  lines   will
                     ;  be  ignored  by  the  systen.


                    TRISC  =  %11111001             ;  set  PORTC.2, the  speaker
                                                    ;  connection
                                                    ;  to  an  output   line
                    tRtSD  -  %00000000             ;  set  all  PORTD  lines  to  output
                    TRrsE  =  %00000000             ;  set  att   poRTE  lines  Lo  oubput
                    PORIE.2=o                       ;  set  LCD to  write  node
                    x  vAR  woRD                    ;  set  up  the  variable
                                                                                        '
                    A ! c o N 1 = % 0 0 0 0 0 1 1 1        \ ^  M " _ o q - r o - D  q : r a t  - o n r o
                                                    :  . - g r  , . e _
                                                    ,  needed  for  the  15F877A see  noles
                    PAUSE  500                      ;  pause  for  LCD !o  sta.t   up
                    LDOUT  $FE/  L                  ;  clear   sc.een
                    ON IMIERRUPT GOTO  INt  ROUEIIqE  j   --   )  p-ogrqn   /hor-   .o  So  ol
                                                        ,  interxupt
                    llcoN=%01110001                                '-   .e  L rp  en-D_e
                    PIE1.0=1                        ;  clears  the  interrupr   flag  so  it  can

                    INTCOIi.6=1
                    OPTION-REG=%000001LL            ;  sels  the  prescalar   ro  256
                    x=0                             ;  seLs  the  iniliat   value  for  X
                                                                _ o o D
                    M A I N !                       :  r h o  a d i l  o /  .  e  p  o g _ d n
                                          .'Metrono@"
                      LCDOI'I  $FE,  $80.              ;  dispray   frrst  line
                      LCDOu!  SlE,  $C0,  DEC5 x   ;  vrite   X  to  1lne  2
                      IF  X=15  TBEN               ;  check  value  of  X
                        x-0
                        TOGGI,E PORTC.2            ;   o9q16   h6  -pe-  <e  so
                                                   ;  i !
                      EIIDIF
                    GOIO  MAIN                     ;  repeaL   Loop

                                                                     r o n  o  r a  . o T p  4 .
                    INr-ROIXIINE  !                ;  interxupt   service   rouiine
                      X=*+X                        ;  increment   the  counter
                      PlR1.0=0                                   _nr e!!  .pL  nag
                    RESUME                         ;  qro  back   to  where  you  were
                    E N A a L E                    i  r 6 o d  s -  l c t  ' ) 1  L o  . n -  o m p : i e .

                    END                            ,  afl   prograns   nust   end  with   End
   225   226   227   228   229   230   231   232   233   234   235