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

PnoJECt  2   2ta


                  The compiler software  for the system  is designed to be able  tojump to a designated  sub-
                  routine when this happens. We specjfy  the target destination  for this with the ON
                  INTERRUPI  GOTO command.

                  tnterrupt  Fleg  An intenupt flag is a bit that is set  in one oI the registers  associated
                  with a timer when the limer overflows and afler all the  pre- and  postscalar effects havc
                  been taken  into account. It indicates  that the prcgam  is ready to be given attention  by
                  the main part of the  processor.  Aftcr  the interrupt has been  taken care oI, the intenxpt
                  bit must be set to 0 (cleared)  by the intenupt service rouline to allow it to be set  to 1
                  again when the  next interrupt takes  place.  The bit is osually  cleared at the end  of the
                  i nteffupt-handling  routine. The interupt  hand]  ing routine must be shot enough to com-
                  plete  before the next  intenlpt adves. Ii this  is not the case, an  interrupt will bc losl.
                  (This  is considered fatal and  is unacceptable.)

                  Inff,'ftupt  Enable  Bit  An inteffupt enable bit is the bit that has to be set  to l,  within
                  one of the registers that controls the timer, before an inteffupt can be generated.  This
                  bitcan us ally be tumed on and  off by lhe  program. Before a specilic interrupt  car take
                  place,  its specific  enable bit must  be sel to L

                  t  rter'|  pt  Latency  Beware thal the interrupts are not handled as soon as they oocur,
                  The PBP compiler  inhibits all interupts  while it executes an  instruction. I1 an  intenxpt
                  occurs while an instruction is being executed,  the inlerlupt will  be addressed atler the
                  jnstruction  is complete.  This cdn lead to a particula-rly  long delay  in the case of a long
                  PAUSE  instruction. PAUSE  instuctions should  be broken up into smaller  pauses in
                  loops to reduce this latency so the largest latency encountered can be tolerated by the
                  task at  hand. Though intenupts  may occur exactly and  as frequendy as  programmed.  they
                  may  not be  handled immediately  by the  proglam. The  programmer  needs  to be aware of
                  this condition  when  programming for time-critical applications.  (Assembly language  pro
                  granming does  not have the  problem  to this extent. It depends  on how the assembler  is
                  designeal, but even so  it tal:es some time to gel  the irteruprhandling  task accomplished  )
                  Ciohal  tnterrupt  Enebre  lGtE)  Bit  The GIE bit in the PIC allows you to shut  off
                  all intenupts when  it is setto 0.Itis located at  INTCON.7. On two  ofthe timers  Timerl
                  and Timer2  this global intenupt enable bit must be enabled before ary interupt  can
                  occur Time  runs all the ti  me and is nol affected by the  global  intemrpt enable bit  See
                  datasheet  page  22.
                    whenever  any  inteffupt flag is set,  the GIEbitis tumed offby the opcrating  system
                  W]rcn the  flag is cleared by  you (with  the software), the GIE  bit will be reset a tomat
                  ically by the operating  system. This means  no other inlerrupt  can occul until  you  take
                  care of the  intemrpt that has occurred.  If you are using  more than one interrupt,  this can
                  cause  problems,  and addressing these  probleDts  is beyond  the scope of this book.
                  Beginners arc advised  to use only one  intenupt in their  programs  till they  get proficient
                  enough wifh the PlCs  to create nore complicated  programs.
                    (For  those who have an  insatiable need to try thesethings  out, the solution  to thc  pre-
                  viously mentioned  problem  has to do wilh replacing  the irterupts very  quickly  with
   211   212   213   214   215   216   217   218   219   220   221