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

52   CO  TNOLIING TI'IE OUTPUTAND READITG THE INPUI



                     ,t:1 .ji6!iil:5;2:l   Blinking eighl  LEDS one aller lhe other on a bargraph
                      CLEAR
                      DEFIAIE  OSC  4
                      LED-ID   VA.R  BYTE         calL  ouL  the  two  variables
                      A  VTR  BYTE
                      TRISD  =%00000000           ser  PoRTD to  a1L  ourpurs

                      IIAINLOOP:                  this  loop  is  executed  forever
                                                  initialize   Lhe  counter  to  1
                          F o R t E D t D = 1 T O I  do  it  for  the  I  LEDS
                            PORTD=A               puts  nunDer  a.  PURrU
                            PAUSE  1OO            pause  so  you  can  see  the  display
                                                  nuLtipLy   by  2  noves  liL   I-ED  left   1


                          NEXT  IJED  ID          go  up  and  increnent   counter
                      GO!!O  MAIIIITOOP           do  it  aLl  forever
                      END                         always  end  with  END




                     Dim and  Brishten One  LED



                     In Program 5.3,  we demonstrate |hc ability  to dim an LED  (at  PORTD.O) by larying
                     the duty cycle ofthe ON  signal to the LED.


                                     Turns on an LED and  dims the one next  to it  (Doing  il this wav  leis
                     tlB!!0iai!.riltqiSil
                                 the brightness ofthe two  LEDS)
                      you  compare
                                                                 ' .        - L E a D
                      CLEAR                                         r i  5  d      > " o f 6 0 5 .
                      DEFINE  OSC  4
                      ERISD  =  %11111100            set  only  PoRTD  pin  0  and  1  to  outpuLs
                      X  VAR  BYTE                   d e c L a r e x a s a v a r i a b l e
                                                     turned  PORTD.I ON & conpare  io  PoRTD.o

                      I.OOP:
                        FOR  x  =  1  TO  255  SIEP  2  set  up  foop  foi  x
                          PIIM  PORTD. O,  X,  3     vary  Lhe  duty  cycLe
                          PAUSE  200 /X              pauses  longer  for  the  dimer   values
                        NEXT  X                      en.f of  Loop  for  x
                      GOIO  LOOP                     reLurn  and  do  i!  again
                      END                            all   progxans  Fith   an  END statenent
                       With  the  preceding programs, we learned that we can control  theON OFF staie  anci
                     the brightness  on an LED. Controlling  the brighhess will become  relevan! when  we
                     are conrolljng seven  segmenl displays because  the LEDS in them  dre tuned ON one
                     at a time and thc duty  cycle has to be managed  pfoperly  10  get  an  acceptable display
   57   58   59   60   61   62   63   64   65   66   67