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

sErrtr{G out  oun bEstclt ||{tEltt   rae



                  I  The E line, which needs to be toggled to transfer data to the LCD
                  I  The RS line, which selects the rcgister
                  r  The (R/W), which sets the read/write status ofthe  operations

                    Using eight  lines for data allows us to generate  allthe codes and all the characters
                  that the chip has in its memory, but more impoftandy, it allows the data [ansfer to be
                  performed in one step. We can also use a 4-bit protocol and transfer half a byte at a
                  time. Using four lines for our control scheme means the LCD can be controlled from
                  just one  port (seven  lines will be used, leaving us one line to spare). The datasheets
                  tell us that whether we use four lines or eight, they all must be  part  of one  port,  and if
                  we are using fourlines, they must be the cortiguous fourhigh,  or the contiguous four
                  low,  bits of a  po  -meaning  we cannot  use  just  any  random lines for the  data  buss.
                  The data transfer for the 4-bit prctocol must use fhe I  high bits on the LCD,  and \\te
                  must send the datatom  tlre PIC to the tlisplal  with the high tu a nibble  frst  and the
                  low data  ibble last. This little  gem  is not speUed out in the instructions, btlt it's wha't
                  must be done,
                    The datasheet also tells us that t}Ie display initializes itself on power-up.  We can
                  reinitialize it under ourcontrol, butil is done automatically on starlup and we cannot
                                             "not
                  inhibit that. All we have to do is   do anything" for about halfa second for the self-
                  initialization to complete. The  busy  llag is set high during startup and  initialization,
                  but  is indeterminate immediately  after initialization starts and for 16.4  milliseconds
                  after the supply voltage reaches 4.5  volfs,  so we cannot determine how long we have
                  to wait afler powering  up to start doing what we want. We will  set a o.s-second
                  wairpause in our progmm  at startup. If that is not lorg enough, we will come back
                  and increase the waiting time. Wait tine is a must. Ifyou do not wait, t}Ie system will
                  not start up properly.
                    Automatic initialization sets the foliowing conditions for the display:
                  I  Display cleared
                  r  Set for 8 bit interface
                  r  Set for 1 line ofdisplay
                  I  Set  for 5 x 7 dot matrix  display
                  I  Display is tumed off
                  I  Cursor  is tumed olT
                  I  Blink is tumed off
                  I  Increment between chamcters is set to I (culsor  moves over one space automatically)
                  a  Shift is off

                    The  preceding  may not be exactly what we want for o r purposes,  so we will go
                  tbrough an initialization  sequence as specified  by the instrnctions. We do not have to
                  go  through all the steps, rar we rrill, sowe have a completerecord ofwhatneeds to be
                  done for future projects.
                    The instructions  tell us that the  follo\'r'ing  six instructions must be sent to the display
                  during an  initialization  sequence. The lirst three insfuctions are identical but require
                  diifercnt waits after each is sent to the display.
   152   153   154   155   156   157   158   159   160   161   162