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

LCD DISPIAY


                                            andbllnking
                                                                      in the LCD display
                   ipiiiiiiiiiry{i{:l   Disprayins     "HELLOWORLD"
                    (Continue,tl
                    DEFINE   I,CD  RVIBIT  2
                    DEFINE  NCD-BITS   A
                    DEFINE   I,CD  I,INES   2
                    DEFINE  I.CD  COMMANDI'S 2 0 0 0 ; delay  in  rnicio  seconds
                    DEFINE   I,CD_DATAUS  50      delay  in  nicro  seconds

                      Set  Lhe port  directions.   we are  setting   (nust  set)  all  of  PORTD
                      a o d  q t l  o I  P O R T I  " s  o ' - p ! i .  F v 6 r  ' h o ! o t  D o o -  L d s  o . l r  . \  e p
                      l i n e s .  T h -  l o !  l  b b l -  i i  D o o  D  / d l  o e  s e t  d s  - p - - s  : .  ^ e  L  c
                      a  4  high  bit   path  Lo  feed  the  LCD.)

                    PAUSE 500               araow  ror  LLU srarEup
                    ERISD =  %00000000                      rlnes  !o  ouEpur
                    TRISE  =  %00000000     ser  all  PORTE lines  !o  output
                                                         o o - - o - D r q i a  c o - L - o  - e g  s L o r
                                                                    r
                    A.DCONI=%00000111       needed  for  the  16F877A  -   see  above  and
                                            below     this   nakes  all   of  poris   A  and  E
                                            disitaL.
                                            the  main  loop  of  the  program
                      I,CDOUT  SFE,  1      clear  screen,  go  !o  position   1
                      PAUSE 250             pause  0.2s  seconds
                      LCDOUIF  \HELI,oZ
                      LCDOUT  tFE,  SCo   ;  go  to  second  1lne,  frrst  position
                      I,CDOUT  \![ORLDZ
                      PAUSE 250           ;  Pause  0.25  seconds
                    Gctro  LooP
                    EIID                  ;  all   progxans  must  end  in  END

                     Before we can write to the LCD. we have to define how the LCD is connected to the
                   MCU. Also, since the 16F877A has sone analog capahilities, it w,ill stah  p atul rcset
                   in analog rnode, and has to be changed to digital mode  (for PORTE  onb in ow  imme
                   diate case) before we can use its digital properttes.
                     The compiler manual tells us we have  to specify the location of thl3 LCD and spec
                   ify the confit  lines connected to it so the compiler can address the device  properly.  Doing
                   so lets us place  the  LCD wherever it's converfent for us when we design our own
                   devices  (and  the compiler will  still be able find it). These variables  are  to be specified
                   in DEFINE statements before any of the rest  of the program  is written. (In thjs book,
                   we will always  place  the LCD at the same address locations  used by the LAB Xl  so
                   we can test all our programs  for our insffuments  on the LAB  Xl  when we need to,)
                     Program 5.4 demonstrates the most  elementary control over oulpul to the LCD dis
                   play.  Variations of these lines of code,  and the addition of a few command codes, will
                   be used to write to the LCD in all our  programs.
                     Not all the  preceding  DEFINE statements are needed on the LAB-XI,  but when  you
                   build your own devices,  you will  need to include them all to make sure nothing has been
                   omitted. You never know what state anMCU might start up in, so coverall  yourbases.
   60   61   62   63   64   65   66   67   68   69   70